forked from assemble/generator-assemble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
191 lines (158 loc) · 5.61 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
'use strict';
var path = require('path');
var yeoman = require('yeoman-generator');
/**
* Module exports Assemble Generator constructor
* Extend Yeoman base generator
*/
var AssembleGenerator = yeoman.generators.Base.extend({
initializing: function () {
this.pkg = require('../package.json');
this.description = this.pkg.description;
this.option('init', {
alias: 'i',
desc: 'Force to prompt question and re-initialize of .yo-rc.json',
type: String,
defaults: false,
required: false
});
this.init = this.options['init'] || this.options['i'] || false;
this.defaultPlugins = {
"assemble-middleware-anchors": false,
"assemble-middleware-permalinks": true,
"assemble-middleware-sitemap": true,
"assemble-middleware-toc": false,
};
this.config.defaults({
projectName : "",
projectDesc : "The best project ever.",
authorLogin : "assemble",
installPlugin : true,
author: {
name : this.user.git.name() || process.env.user || process.env.username,
login : "assemble",
email : this.user.git.email()
}
});
}, // initializing
prompting: function () {
var done = this.async();
var force = false;
if (!this.config.existed || this.init) {
force = true;
}
if (!this.options['skip-welcome-message']) {
console.log(this.yeoman);
}
var questions = [];
(!this.config.get("projectName") || force) && questions.push({
type : "input",
name : "projectName",
message : "Your project name",
default : this.appname || this.config.get("projectName")
});
(!this.config.get("projectDesc") || force) && questions.push({
type : "input",
name : "projectDesc",
message : "Your project description",
default : this.config.get("projectDesc")
});
(!this.config.get("author").login || !this.config.get("authorLogin") || force) && questions.push({
type : "input",
name : "authorLogin",
message : "Would you mind telling me your username on Github?",
default : this.config.get("author").login || this.config.get("authorLogin")
});
questions.push({
type : "confirm",
name : "installPlugin",
message : "Do you want to install Assemble plugins?",
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 : "plugins",
type : "checkbox",
message : "Which plugins would you like to include?",
choices : choices,
when: function( answers ) {
return answers.installPlugin;
}
});
this.prompt(questions, function (answers) {
this.projectName = answers.projectName || this.config.get("projectName");
this.projectDesc = answers.projectDesc || this.config.get("projectDesc");
this.authorLogin = answers.authorLogin || this.config.get("authorLogin");
this.plugins = answers.plugins;
this.authorName = this.config.get("author").name;
this.authorEmail = this.config.get("author").email;
//save config to .yo-rc.json
this.config.set(answers);
done();
}.bind(this));
}, // prompting
writing: {
projectfiles: function () {
this.template('AUTHORS');
this.template('CHANGELOG');
this.template('LICENSE-MIT');
this.template('Gruntfile.js');
this.template('_package.json', 'package.json');
this.template('editorconfig', '.editorconfig');
this.template('README.md');
},
gitfiles: function () {
this.copy('gitignore', '.gitignore');
this.copy('gitattributes', '.gitattributes');
},
bower: function () {
this.template('_bower.json', 'bower.json');
},
src: function () {
this.mkdir('src/data');
this.mkdir('src/content');
this.mkdir('src/templates/pages');
this.mkdir('src/templates/assets');
this.mkdir('src/templates/layouts');
this.mkdir('src/templates/partials');
this.copy('site.yml', 'src/data/site.yml');
this.copy('theme.css', 'src/assets/theme.css');
this.copy('markdown.md', 'src/content/markdown.md');
this.copy('blog.hbs', 'src/templates/pages/blog.hbs');
this.copy('index.hbs', 'src/templates/pages/index.hbs');
this.copy('layout.hbs', 'src/templates/layouts/default.hbs');
this.copy('inc-navbar-fixed-top.hbs', 'src/templates/partials/navbar-fixed-top.hbs');
}
}, // writing
install: function() {
this.installDependencies({
skipInstall: this.options['skip-install'] || this.options['s'],
skipMessage: this.options['skip-welcome-message'] || this.options['w']
});
}, // install
});
module.exports = AssembleGenerator;