-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Gruntfile.js
190 lines (167 loc) · 4.6 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
var shell = require('shelljs');
var child_process = require('child_process');
var Q = require('q');
var helpers = require('yeoman-test');
var fs = require('fs');
var path = require('path');
module.exports = function (grunt) {
var gruntUtils = require('./task-utils/grunt')(grunt);
var gitCmd = gruntUtils.gitCmd;
var gitCmdAsync = gruntUtils.gitCmdAsync;
grunt.initConfig({
config: {
demo: 'demo'
},
pkg: grunt.file.readJSON('package.json'),
release: {
options: {
commitMessage: '<%= version %>',
tagName: '<%= version %>',
file: 'package.json',
beforeBump: ['updateSubmodules'],
afterBump: ['updateFixtures:deps', 'commitNgFullstackDeps'],
beforeRelease: ['stage'],
push: false,
pushTags: false,
npm: false
}
},
stage: {
options: {
files: ['CHANGELOG.md', 'angular-fullstack-deps']
}
},
buildcontrol: {
options: {
dir: 'demo',
commit: true,
push: true,
connectCommits: false,
message: 'Built using Angular Fullstack v<%= pkg.version %> from commit %sourceCommit%'
},
release: {
options: {
remote: 'origin',
branch: 'master'
}
}
},
david: {
gen: {
options: {}
},
app: {
options: {
package: 'test/fixtures/package.json'
}
}
}
});
grunt.registerTask('stage', 'git add files before running the release task', function () {
var files = grunt.config('stage.options').files;
gitCmd(['add'].concat(files), {}, this.async());
});
grunt.registerTask('commitNgFullstackDeps', function() {
grunt.config.requires(
'commitNgFullstackDeps.options.files',
'commitNgFullstackDeps.options.cwd'
);
var ops = grunt.config.get('commitNgFullstackDeps').options;
var version = require('./package.json').version || 'NO VERSION SET';
if (Array.isArray(ops.files) && ops.files.length > 0) {
gitCmd(['commit', '-m', version].concat(ops.files), {
cwd: path.resolve(__dirname, ops.cwd)
}, this.async());
} else {
grunt.log.writeln('No files were commited');
}
});
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,
testing: 'jasmine',
auth: true,
oauth: ['googleAuth', 'twitterAuth'],
ws: true
};
var deps = [
'../app',
[
helpers.createDummyGenerator(),
'ng-component:app'
]
];
var gen = helpers.createGenerator('angular-fullstack: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('deps', function(target) {
if (!target || target === 'app') grunt.task.run(['updateFixtures']);
grunt.task.run(['david:' + (target || '')]);
});
grunt.registerTask('demo', [
'clean:demo',
'generateDemo'
]);
grunt.registerTask('releaseDemo', [
'demo',
'releaseDemoBuild',
'buildcontrol:release'
]);
//grunt.registerTask('default', ['bump', 'changelog', 'stage', 'release']);
};