Skip to content

Commit

Permalink
Merge pull request #34 from assemble/develop
Browse files Browse the repository at this point in the history
v0.4.7
  • Loading branch information
hariadi committed Jan 20, 2014
2 parents 2f9f76a + 3c480a7 commit 487a86d
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 44 deletions.
6 changes: 0 additions & 6 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# Set default behaviour, in case users don't have core.autocrlf set.
* text=lf
* text eol=lf
*.* eol=lf

*.jpg binary
*.gif binary
*.png binary
*.jpeg binary
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ node_modules/
temp/
*.sublime-project
*.sublime-workspace
.jshintrc
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
language: node_js
node_js:
- '0.10'
- '0.8'
51 changes: 49 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

## Usage

### Assemble app scaffolds.
Creates an Assemble boilerplate projects.

```bash
mkdir project && cd $_
Expand All @@ -18,6 +18,10 @@ yo assemble

#### Options

* `-i` alias `--init`

Force to prompt question and re-initialize `.yo-rc.json`.

* `-s` alias `--skip-install`

Skips the automatic execution of `bower` and `npm` after scaffolding has finished.
Expand All @@ -26,8 +30,51 @@ yo assemble

Skips app welcome message.

## Alternative

## Include in boilerplate
* time-grunt
* grunt-contrib-clean
* grunt-contrib-connect
* grunt-contrib-watch


## Boilerplate
The following directory structure generated after run `yo assemble`:

.
├── .editorconfig
├── .gitignore
├── .yo-rc.json
├── AUTHORS
├── CHANGELOG
├── Gruntfile.js
├── LICENSE-MIT
├── package.json
├── README.md
├── dist
│ ├── assets
│ │ ├── assemble.css
│ │ ├── github.css
│ │ └── highlight.js
├── src
│ ├── content
│ │ └── markdown.md
│ ├── data
│ │ └── site.yml
│ └── templates
│ ├── layouts
│ │ └── default.md
│ ├── pages
│ │ ├── index.hbs
│ │ └── blog.hbs
│ └── partials
│ └── navbar-fixed-top.hbs
└── node_modules

## Related

* [Assemble Helper generator](https://github.com/assemble/generator-helper)
* [Assemble Plugin generator](https://github.com/assemble/generator-plugin)
* [grunt-init-assemble](https://github.com/assemble/grunt-init-assemble)


Expand Down
5 changes: 3 additions & 2 deletions app/USAGE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Example:
yo assemble --init --skip-install --skip-welcome-message
yo assemble -i -s -w (alias)
yo assemble
yo assemble [--init] [--skip-install] [--skip-welcome-message]
yo assemble [-i] [-s] [-w]
66 changes: 48 additions & 18 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ var AssembleGenerator = module.exports = function AssembleGenerator(args, option

yeoman.generators.Base.apply(this, arguments);

this.description = 'Creates a default Assemble boilerplate';
this.pkg = JSON.parse(this.readFileAsString(path.join(__dirname, '../package.json')));
this.description = this.pkg.description;

// Not required but need to show when user command `yo assemble -h`
this.option('init', {
Expand All @@ -28,14 +29,15 @@ var AssembleGenerator = module.exports = function AssembleGenerator(args, option
this.on('end', function () {
this.installDependencies({
skipInstall: options['skip-install'] || options['s'],
skipMessage: options['skip-welcome-message'] || options['w']
skipMessage: options['skip-welcome-message'] || options['w'],
callback: function () {
this.spawnCommand('grunt', ['build']);
}.bind(this) // only run grunt build after succesful npm/bower install
});
});

this.files = this.expandFiles('**/*', { cwd: this.sourceRoot(), dot: true });

this.pkg = JSON.parse(this.readFileAsString(path.join(__dirname, '../package.json')));

this.dotFiles = [
'gitignore',
'gitattributes',
Expand All @@ -45,8 +47,18 @@ var AssembleGenerator = module.exports = function AssembleGenerator(args, option

this.pkgFiles = ['_package.json'];

this.defaultPlugins = {
"assemble-contrib-anchors": true,
"assemble-contrib-permalinks": true,
"assemble-contrib-sitemap": true,
"assemble-contrib-toc": true,
"assemble-markdown-data": false,
"assemble-related-pages": false
};

this.config.defaults({
projectName : "",
projectDesc : "The best project ever.",
githubUser : "assemble",
installPlugin : true,
author: {
Expand All @@ -64,7 +76,6 @@ util.inherits(AssembleGenerator, yeoman.generators.Base);
* Command prompt questions
* Extend defaults and options based on user answers
*/

AssembleGenerator.prototype.askFor = function askFor() {
var done = this.async();

Expand Down Expand Up @@ -108,18 +119,39 @@ AssembleGenerator.prototype.askFor = function askFor() {
default : this.config.get("installPlugin")
});

// for first time/re-init, make new list of defaultPlugins
if(!this.config.get("installPlugin") || force) {
var plugins = this.config.get("plugins");
// if we have previous plugin choice
if (this._.isArray(plugins)) {
var defaultPlugins = {};
// convert it to object and assign checked
plugins.forEach(function(plugin) {
defaultPlugins[plugin] = true;
});
// concat with defautPlugins
for (var key in defaultPlugins) {
this.defaultPlugins[key] = defaultPlugins[key];
}
}
}

var choices = [];
var pluginObj = this.defaultPlugins;

// make choice more dynamic and checked from previous choice
// TODO: fetch from npm with "assembleplugin" keyword
for (var plugin in pluginObj) {
if(pluginObj.hasOwnProperty(plugin)){
choices.push({ name: plugin, checked: pluginObj[plugin] });
}
}

questions.push({
name : "plugin",
name : "plugins",
type : "checkbox",
message : "Which plugins would you like to include?",
choices : [
{ name: "assemble-contrib-anchors", checked: true },
{ name: "assemble-contrib-permalinks", checked: true },
{ name: "assemble-contrib-sitemap", checked: true },
{ name: "assemble-contrib-toc", checked: true },
{ name: "assemble-markdown-data" },
{ name: "assemble-related-pages" },
],
choices : choices,
when: function( answers ) {
return answers.installPlugin;
}
Expand All @@ -130,8 +162,8 @@ AssembleGenerator.prototype.askFor = function askFor() {
this.projectName = answers.projectName || this.config.get("projectName");
this.projectDesc = answers.projectDesc || this.config.get("projectDesc");
this.authorLogin = answers.githubUser || this.config.get("githubUser");
this.plugin = answers.plugin;
this.authorName = this.config.get("author").name;
this.plugins = answers.plugins || this.config.get("plugins");
this.authorName = this.config.get("author").name;
this.authorEmail = this.config.get("author").email;

//save config to .yo-rc.json
Expand All @@ -145,7 +177,6 @@ AssembleGenerator.prototype.askFor = function askFor() {
* TODO: Separate file generated with their own function. See test-creation.js
* Copy boilerplate main code
*/

AssembleGenerator.prototype.app = function app() {
var files = this.files;

Expand All @@ -168,7 +199,6 @@ AssembleGenerator.prototype.app = function app() {
/**
* Stringify an object and normalize whitespace with project preferences.
*/

AssembleGenerator.prototype.normalizeJSON = function() {
var pkgFile = path.join(this.destinationRoot(process.cwd()), 'package.json');
var pkgObj = this.read(pkgFile);
Expand Down
6 changes: 3 additions & 3 deletions app/templates/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ module.exports = function(grunt) {
assets: '<%%= config.dist %>/assets',
layout: '<%%= config.src %>/templates/layouts/default.hbs',
data: '<%%= config.src %>/data/*.{json,yml}',
partials: '<%%= config.src %>/templates/partials/*.hbs'<% if(plugin && plugin.length > 0){ %>,
plugins: [<% if(typeof plugin === 'object'){ _.each(plugin, function(name, i) { %>'<%= name %>'<% if(i < (plugin.length - 1)) { %>,<% } }); } else { %>'<%= name %>'<%} %>],<%}
_.each(plugin, function(name, i) { if(name == 'permalinks') { %>
partials: '<%%= config.src %>/templates/partials/*.hbs'<% if(plugins && plugins.length > 0){ %>,
plugins: [<% if(typeof plugins === 'object'){ _.each(plugins, function(name, i) { %>'<%= name %>'<% if(i < (plugins.length - 1)) { %>,<% } }); } else { %>'<%= name %>'<%} %>],<%}
_.each(plugins, function(name, i) { if(name == 'permalinks') { %>
permalinks: {
preset: 'pretty'
},<% }
Expand Down
8 changes: 4 additions & 4 deletions app/templates/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
"grunt-contrib-connect": "~0.6.0",
"grunt-contrib-watch": "~0.5.3",
"load-grunt-tasks": "~0.2.1",
"time-grunt": "~0.2.7"<% if(plugin && plugin.length > 0){ %>,
<% if(typeof plugin === 'object'){ _.each(plugin, function(name, i) { %>
"<%= name %>": "*"<% if(i < (plugin.length - 1)) { %>,<% } %>
"time-grunt": "~0.2.7"<% if(plugins && plugins.length > 0){ %>,
<% if(typeof plugins === 'object'){ _.each(plugins, function(name, i) { %>
"<%= name %>": "*"<% if(i < (plugins.length - 1)) { %>,<% } %>
<% }); } else { %>
"<%= plugin %>": "*"
"<%= plugins %>": "*"
<%} } %>
},
"licenses": [
Expand Down
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "generator-assemble",
"version": "0.4.6",
"description": "The scaffolding for Assemble",
"version": "0.4.7",
"description": "Creates an Assemble boilerplate projects.",
"keywords": [
"yeoman-generator",
"assemble",
Expand All @@ -11,8 +11,7 @@
"bugs": "https://github.com/assemble/generator-assemble/issues",
"author": {
"name": "Hariadi Hinta",
"email": "[email protected]",
"url": "http://hariadi.org"
"email": "[email protected]"
},
"main": "app/index.js",
"repository": {
Expand All @@ -29,10 +28,10 @@
"mocha": "*"
},
"peerDependencies": {
"yo": ">=1.0.4"
"yo": ">=1.0.0"
},
"engines": {
"node": ">=0.8.0",
"node": ">=0.10.0",
"npm": ">=1.2.10"
},
"licenses": [
Expand Down
2 changes: 1 addition & 1 deletion test/test-creation.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('Assemble generator', function () {
helpers.mockPrompt(this.app, {
projectName: 'assemble',
githubUser: 'assemble',
plugin: ['permalinks', 'sitemap']
plugins: ['permalinks', 'sitemap']
});

this.app.run({}, function () {
Expand Down

0 comments on commit 487a86d

Please sign in to comment.