forked from angular-fullstack/generator-angular-fullstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
258 lines (226 loc) · 6.46 KB
/
Gruntfile.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
'use strict';
var markdown = require('marked');
var semver = require('semver');
var _s = require('underscore.string');
var shell = require('shelljs');
var process = require('child_process');
var Q = require('q');
var helpers = require('yeoman-generator').test;
var fs = require('fs-extra');
var path = require('path');
module.exports = function (grunt) {
require('load-grunt-tasks')(grunt);
grunt.initConfig({
config: {
demo: 'demo'
},
pkg: grunt.file.readJSON('package.json'),
changelog: {
options: {
dest: 'CHANGELOG.md',
versionFile: 'package.json'
}
},
release: {
options: {
commitMessage: '<%= version %>',
tagName: 'v<%= version %>',
bump: false, // we have our own bump
file: 'package.json'
}
},
stage: {
options: {
files: ['CHANGELOG.md']
}
},
buildcontrol: {
options: {
dir: 'demo',
commit: true,
push: true,
connectCommits: false,
message: 'Built using Angular Fullstack Bluemix v<%= pkg.version %> from commit %sourceCommit%'
},
release: {
options: {
remote: 'origin',
branch: 'master'
}
}
},
jshint: {
options: {
curly: false,
node: true
},
all: ['Gruntfile.js', '*/index.js']
},
mochaTest: {
test: {
src: [
'test/*.js'
],
options: {
reporter: 'spec',
timeout: 120000
}
}
},
clean: {
demo: {
files: [{
dot: true,
src: [
'<%= config.demo %>/*',
'!<%= config.demo %>/readme.md',
'!<%= config.demo %>/node_modules',
'!<%= config.demo %>/.git',
'!<%= config.demo %>/dist'
]
}]
}
}
});
grunt.registerTask('bump', 'bump manifest version', function (type) {
var options = this.options({
file: grunt.config('pkgFile') || 'package.json'
});
function setup(file, type) {
var pkg = grunt.file.readJSON(file);
var newVersion = pkg.version = semver.inc(pkg.version, type || 'patch');
return {
file: file,
pkg: pkg,
newVersion: newVersion
};
}
var config = setup(options.file, type);
grunt.file.write(config.file, JSON.stringify(config.pkg, null, ' ') + '\n');
grunt.log.ok('Version bumped to ' + config.newVersion);
});
grunt.registerTask('stage', 'git add files before running the release task', function () {
var files = this.options().files;
grunt.util.spawn({
cmd: process.platform === 'win32' ? 'git.cmd' : 'git',
args: ['add'].concat(files)
}, grunt.task.current.async());
});
grunt.registerTask('generateDemo', 'generate demo', function () {
var done = this.async();
shell.mkdir(grunt.config('config').demo);
shell.cd(grunt.config('config').demo);
Q()
.then(generateDemo)
.then(function() {
shell.cd('../');
})
.catch(function(msg){
grunt.fail.warn(msg || 'failed to generate demo')
})
.finally(done);
function generateDemo() {
var deferred = Q.defer();
var options = {
script: 'js',
markup: 'html',
stylesheet: 'sass',
router: 'uirouter',
bootstrap: true,
uibootstrap: true,
mongoose: true,
auth: true,
oauth: ['googleAuth', 'twitterAuth'],
socketio: true
};
var deps = [
'../app',
[
helpers.createDummyGenerator(),
'ng-component:app'
]
];
var gen = helpers.createGenerator('angular-fullstack-bluemix:app', deps);
helpers.mockPrompt(gen, options);
gen.run({}, function () {
deferred.resolve();
});
return deferred.promise;
}
});
grunt.registerTask('releaseDemoBuild', 'builds and releases demo', function () {
var done = this.async();
shell.cd(grunt.config('config').demo);
Q()
.then(gruntBuild)
.then(gruntRelease)
.then(function() {
shell.cd('../');
})
.catch(function(msg){
grunt.fail.warn(msg || 'failed to release demo')
})
.finally(done);
function run(cmd) {
var deferred = Q.defer();
var generator = shell.exec(cmd, {async:true});
generator.stdout.on('data', function (data) {
grunt.verbose.writeln(data);
});
generator.on('exit', function (code) {
deferred.resolve();
});
return deferred.promise;
}
function gruntBuild() {
return run('grunt');
}
function gruntRelease() {
return run('grunt buildcontrol:heroku');
}
});
grunt.registerTask('updateFixtures', 'updates package and bower fixtures', function() {
var done = this.async();
var packageJson = fs.readFileSync(path.resolve('app/templates/_package.json'), 'utf8');
var bowerJson = fs.readFileSync(path.resolve('app/templates/_bower.json'), 'utf8');
// replace package name
packageJson = packageJson.replace(/"name": "<%(.*)%>"/g, '"name": "tempApp"');
packageJson = packageJson.replace(/<%(.*)%>/g, '');
// remove all ejs conditionals
bowerJson = bowerJson.replace(/"name": "<%(.*)%>"/g, '"name": "tempApp"');
bowerJson = bowerJson.replace(/<%(.*)%>/g, '');
// save files
fs.writeFile(path.resolve(__dirname + '/test/fixtures/package.json'), packageJson, function() {
fs.writeFile(path.resolve(__dirname + '/test/fixtures/bower.json'), bowerJson, function() {
done();
});
});
});
grunt.registerTask('installFixtures', 'install package and bower fixtures', function() {
var done = this.async();
shell.cd('test/fixtures');
grunt.log.ok('installing npm dependencies for generated app');
process.exec('npm install --quiet', {cwd: '../fixtures'}, function (error, stdout, stderr) {
grunt.log.ok('installing bower dependencies for generated app');
process.exec('bower install', {cwd: '../fixtures'}, function (error, stdout, stderr) {
shell.cd('../../');
done();
})
});
});
grunt.registerTask('test', [
'updateFixtures',
'installFixtures',
'mochaTest'
]);
grunt.registerTask('demo', [
'clean:demo',
'generateDemo'
]);
grunt.registerTask('releaseDemo', [
'demo',
'releaseDemoBuild',
'buildcontrol:release'
]);
//grunt.registerTask('default', ['bump', 'changelog', 'stage', 'release']);
};