/
index.js
142 lines (103 loc) · 4.63 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
var util = require('util'),
fs = require('fs'),
path = require('path'),
yeoman = require('../../../../');
module.exports = AppGenerator;
function AppGenerator(args, options, config) {
yeoman.generators.NamedBase.apply(this, arguments);
this.destinationRoot(this.name);
// setup the test-framework property, Gruntfile template will need this
this.test_framework = options['test-framework'] || 'mocha';
// cleanup the name property from trailing /, typical usage of directories.
// update the args object, it's used to initialize js-framework hooks
if(this.name) this.args[0] = this.args[0].replace(/\/$/, '');
// resolved to js by default (could be switched to coffee for instance)
this.hookFor('javascript-engine');
// resolved to sass by default (could be switched to less for instance)
this.hookFor('stylesheet-engine');
// init a framework specific controller. resolved to ? by default
this.hookFor('js-framework', { as: 'controller' });
// init a framework specific model. resolved to ? by default
this.hookFor('js-framework', { as: 'model' });
// init a framework specific view. resolved to ? by default
this.hookFor('js-framework', { as: 'view' });
// resolved to jasmine by default (could be switched to mocha for instance)
this.hookFor('test-framework');
}
util.inherits(AppGenerator, yeoman.generators.NamedBase);
AppGenerator.prototype.readme = function readme() {
this.copy('readme.md', 'readme.md');
};
AppGenerator.prototype.gruntfile = function gruntfile() {
this.template('Gruntfile.js');
};
AppGenerator.prototype.packageJSON = function packageJSON() {
this.template('package.json');
};
AppGenerator.prototype.gitignore = function gitignore() {
this.copy('gitignore', '.gitignore');
};
AppGenerator.prototype.fetchH5bp = function fetchH5bp() {
var cb = this.async();
var self = this;
// Fecth allows the download of single files, into the destination directory
this.fetch('https://raw.github.com/h5bp/html5-boilerplate/master/index.html', 'index.html', function(err) {
if(err) return cb(err);
cb();
// Resolve path to index.html
var indexOut = path.resolve('index.html');
// Read in as string for further update
var indexData = self.readFileAsString(indexOut);
indexData = indexData.replace('css/main.css', 'app/css/main.css');
indexData = indexData.replace('js/vendor/modernizr-2.5.3.min.js', 'app/js/vendor/modernizr-2.5.3.min.js');
// Strip sections of H5BP we're going to overwrite
indexData = self.removeScript(indexData, 'js/plugins.js');
indexData = self.removeScript(indexData, 'js/main.js');
// Wire Twitter Bootstrap plugins (usemin: app/js/plugins.js)
indexData = self.appendScripts(indexData,
'app/js/plugins.js',
["app/js/vendor/bootstrap/bootstrap-alert.js",
"app/js/vendor/bootstrap/bootstrap-dropdown.js",
"app/js/vendor/bootstrap/bootstrap-tooltip.js",
"app/js/vendor/bootstrap/bootstrap-modal.js",
"app/js/vendor/bootstrap/bootstrap-transition.js",
"app/js/vendor/bootstrap/bootstrap-button.js",
"app/js/vendor/bootstrap/bootstrap-popover.js",
"app/js/vendor/bootstrap/bootstrap-typeahead.js",
"app/js/vendor/bootstrap/bootstrap-carousel.js",
"app/js/vendor/bootstrap/bootstrap-scrollspy.js",
"app/js/vendor/bootstrap/bootstrap-collapse.js",
"app/js/vendor/bootstrap/bootstrap-tab.js"]);
// Alternative: indexData = _this.appendScriptsDir(indexData, 'js/plugins.js', path.resolve('app/js/vendor/bootstrap'));
// Write out final file
self.writeFileFromString(indexData, indexOut);
});
};
AppGenerator.prototype.fetchPackage = function fetchPackage() {
this.log.writeln('Fetching h5bp/html5-boilerplate pkg');
var cb = this.async();
this.remote('h5bp', 'html5-boilerplate', 'master', function(err, remote) {
if(err) return cb(err);
// Remote allows the download of full repository, copying of single of
// multiple files with glob patterns. `remote` is your API to access this
// fetched (or cached) package, to copy or process through _.template
// remote.copy('index.html', 'index.html');
// remote.template('index.html', 'will/be/templated/at/index.html');
remote.directory('.', 'app');
cb();
});
};
AppGenerator.prototype.app = function app() {
this.mkdir('app');
this.mkdir('app/js');
this.mkdir('app/css');
this.mkdir('app/templates');
};
AppGenerator.prototype.lib = function lib() {
this.mkdir('lib');
// init a generator ? a readme explaining the purpose of the lib/ folder?
};
AppGenerator.prototype.test = function test() {
this.mkdir('test');
this.mkdir('spec');
};