-
Notifications
You must be signed in to change notification settings - Fork 708
/
index.js
115 lines (99 loc) · 3.14 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
'use strict';
const Generator = require('yeoman-generator');
const commandExists = require('command-exists').sync;
const yosay = require('yosay');
const mkdirp = require('mkdirp');
const config = require('./config');
module.exports = class extends Generator {
constructor(args, opts) {
super(args, opts);
for (let optionName in config.options) {
this.option(optionName, config.options[optionName]);
}
}
initializing() {
this.pkg = require('../package.json');
if (this.options['skip-test-framework']) {
return;
}
this.composeWith(
require.resolve(
`generator-${this.options['test-framework']}/generators/app`
),
{
'skip-install': this.options['skip-install']
}
);
}
prompting() {
if (!this.options['skip-welcome-message']) {
this.log(
yosay(
"'Allo 'allo! Out of the box I include HTML5 Boilerplate, jQuery, and a gulpfile to build your app."
)
);
}
return this.prompt(config.prompts).then(answers => {
const features = answers.features;
const hasFeature = feat => features && features.includes(feat);
// manually deal with the response, get back and store the results.
// we change a bit this way of doing to automatically do this in the self.prompt() method.
this.includeSass = hasFeature('includeSass');
this.includeBootstrap = hasFeature('includeBootstrap');
this.includeModernizr = hasFeature('includeModernizr');
this.includeAnalytics = hasFeature('includeAnalytics');
this.includeJQuery = answers.includeJQuery;
});
}
writing() {
const templateData = {
appname: this.appname,
date: new Date().toISOString().split('T')[0],
name: this.pkg.name,
version: this.pkg.version,
includeSass: this.includeSass,
includeBootstrap: this.includeBootstrap,
testFramework: this.options['test-framework'],
includeJQuery: this.includeJQuery,
includeModernizr: this.includeModernizr,
includeAnalytics: this.includeAnalytics
};
const copy = (input, output) => {
this.fs.copy(this.templatePath(input), this.destinationPath(output));
};
const copyTpl = (input, output, data) => {
this.fs.copyTpl(
this.templatePath(input),
this.destinationPath(output),
data
);
};
// Render Files
config.filesToRender.forEach(file => {
copyTpl(file.input, file.output, templateData);
});
// Copy Files
config.filesToCopy.forEach(file => {
copy(file.input, file.output);
});
// Create extra directories
config.dirsToCreate.forEach(item => {
mkdirp(item);
});
if (this.includeModernizr) {
copy('modernizr.json', 'modernizr.json');
}
let cssFile = `main.${this.includeSass ? 'scss' : 'css'}`;
copyTpl(cssFile, `app/styles/${cssFile}`, templateData);
}
install() {
const hasYarn = commandExists('yarn');
this.installDependencies({
npm: !hasYarn,
yarn: hasYarn,
bower: false,
skipMessage: this.options['skip-install-message'],
skipInstall: this.options['skip-install']
});
}
};