forked from angular-ui/ui-router
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
281 lines (265 loc) · 9.24 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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/*global module:false*/
module.exports = function (grunt) {
require('load-grunt-tasks')(grunt);
var files = require('./files').files;
var systemjs = require('systemjs');
//var jspm = require('jspm');
// Project configuration.
grunt.initConfig({
builddir: 'build',
pkg: grunt.file.readJSON('package.json'),
buildtag: '-dev-' + grunt.template.today('yyyy-mm-dd'),
meta: {
banner: '/**\n' +
' * <%= pkg.description %>\n' +
' * @version v<%= pkg.version %><%= buildtag %>\n' +
' * @link <%= pkg.homepage %>\n' +
' * @license MIT License, http://www.opensource.org/licenses/MIT\n' +
' */'
},
clean: [ '<%= builddir %>' ],
ts: {
ng1: { tsconfig: 'tsconfig.json' },
ng2: { tsconfig: 'tsconfig-ng2.json' }
},
uglify: {
options: {
banner: '<%= meta.banner %>\n',
mangle: true
},
build: {
files: {
'<%= builddir %>/ui-router-ng2.min.js': ['<banner:meta.banner>', '<%= builddir %>/ui-router-ng2.js'],
'<%= builddir %>/angular-ui-router.min.js': ['<banner:meta.banner>', '<%= builddir %>/angular-ui-router.js'],
'<%= builddir %>/ng1/stateEvents.min.js': ['<banner:meta.banner>', '<%= builddir %>/ng1/stateEvents.js']
}
}
},
webpack: {
build: {
entry: files.ng1CommonJsEntrypoint,
output: {
path: '<%= builddir %>',
filename: 'angular-ui-router.js',
library: 'ui.router',
libraryTarget: 'umd'
},
module: { loaders: [] },
externals: [
{ angular: { root: 'angular', commonjs2: 'angular', commonjs: 'angular' } }
]
},
ng2: {
entry: files.ng2CommonJsEntrypoint,
output: {
path: '<%= builddir %>',
filename: 'ui-router-ng2.js',
library: 'uiRouter',
libraryTarget: 'umd'
},
module: { loaders: [] },
externals: [{
'angular2/core': {root: ['ng', 'core'], commonjs: 'angular2/core', commonjs2: 'angular2/core', amd: 'angular2/core'},
'angular2/common': {root: ['ng', 'common'], commonjs: 'angular2/common', commonjs2: 'angular2/common', amd: 'angular2/common'}
}]
}
//,core: {
// entry: files.justjsCommonJsEntrypoint,
// output: {
// path: '<%= builddir %>',
// filename: 'ui-router-justjs.js',
// library: 'uiRouter',
// libraryTarget: 'umd'
// },
// module: {
// loaders: []
// }
//}
},
release: {
files: ['<%= pkg.name %>.js', '<%= pkg.name %>.min.js'],
src: '<%= builddir %>',
dest: 'release'
},
watch: {
files: ['src/**/*.ts', 'src/**/*.js', 'test/**/*.js'],
tasks: ['ts:es5', 'webpack', 'karma:ng14']
},
connect: {
server: {},
sample: {
options:{
port: 5555,
keepalive: true
}
}
},
karma: {
options: {
configFile: 'config/karma.js',
// Serve and load angular files using regular Karma mode
browsers: [ grunt.option('browser') || 'PhantomJS' ]
},
// Same as karma:base
unit: {
},
// Launch Karma in Chrome, click debug button, debug tests
debug: {
singleRun: false,
background: false,
autoWatch: true,
autoWatchInterval: 1,
browsers: [ grunt.option('browser') || 'Chrome' ]
},
// Test with angular 1.2
ng12: {
options: { files: files.karmaServedFiles('1.2.28') }
},
// Test with angular 1.3
ng13: {
options: { files: files.karmaServedFiles('1.3.16') }
},
// Test with angular 1.4
ng14: {
options: { files: files.karmaServedFiles('1.4.9') }
},
// Test with angular 1.5
ng15: {
options: { files: files.karmaServedFiles('1.5.0') }
},
background: {
background: true
},
// PhantomJS in the console; watch for changes to tests/src
watch: {
singleRun: false,
autoWatch: true,
autoWatchInterval: 1
}
},
changelog: {
options: {
dest: 'CHANGELOG.md'
}
},
ngdocs: {
options: {
dest: 'site',
styles: [ 'ngdoc_assets/uirouter-docs.css' ],
html5Mode: false,
title: 'UI Router',
startPage: '/api/ui.router',
navTemplate: 'ngdoc_assets/docnav.html'
},
api: {
src: ['src/**/*.js'],
title: 'API Reference'
}
}
});
grunt.registerTask('integrate', ['clean', 'build', 'karma:ng12', 'karma:ng13', 'karma:ng14', 'karma:ng15']);
grunt.registerTask('default', ['build', 'karma:unit', 'docs']);
grunt.registerTask('build', 'Perform a normal build', ['clean', 'ts', 'bundles', 'uglify']);
grunt.registerTask('dist-docs', 'Perform a clean build and generate documentation', ['build', 'ngdocs']);
grunt.registerTask('release', 'Tag and perform a release', ['prepare-release', 'build', 'perform-release']);
grunt.registerTask('dev', 'Run dev server and watch for changes', ['build', 'connect:server', 'karma:background', 'watch']);
grunt.registerTask('sample', 'Run connect server with keepalive:true for sample app development', ['connect:sample']);
grunt.registerTask('docs', 'Generate documentation to _doc', function() {
promising(this,
system('./node_modules/typedoc/bin/typedoc --experimentalDecorators --readme ./README.md --name "UI-Router" --theme ./typedoctheme --mode modules --module commonjs --target es5 --out _doc src typings/es6-shim/es6-shim.d.ts typings/angularjs/angular.d.ts')
);
});
grunt.registerTask('bundles', 'Create the bundles and reorganize any additional dist files (addons, etc)', function() {
var builddir = grunt.config('builddir');
grunt.task.requires([ 'clean', 'ts' ]);
grunt.task.run(['webpack']);
['stateEvents.js', 'stateEvents.js.map'].forEach(function(file) {
grunt.file.copy(builddir + "/es5/ng1/" + file, builddir + "/ng1/" + file);
})
});
grunt.registerTask('publish-pages', 'Publish a clean build, docs, and sample to github.io', function () {
promising(this,
ensureCleanMaster().then(function () {
shjs.rm('-rf', 'build');
return system('git checkout gh-pages');
}).then(function () {
return system('git merge master');
}).then(function () {
return system('grunt dist-docs');
}).then(function () {
return system('git commit -a -m \'Automatic gh-pages build\'');
}).then(function () {
return system('git checkout master');
})
);
});
grunt.registerTask('push-pages', 'Push published pages', function () {
promising(this,
ensureCleanMaster().then(function () {
shjs.rm('-rf', 'build');
return system('git checkout gh-pages');
}).then(function () {
return system('git push origin gh-pages');
}).then(function () {
return system('git checkout master');
})
);
});
grunt.registerTask('prepare-release', function () {
var bower = grunt.file.readJSON('bower.json'),
component = grunt.file.readJSON('component.json'),
version = bower.version;
if (version != grunt.config('pkg.version')) throw new Error('Version mismatch in bower.json');
if (version != component.version) throw new Error('Version mismatch in component.json');
promising(this,
ensureCleanMaster().then(function () {
return exec('git tag -l \'' + version + '\'');
}).then(function (result) {
if (result.stdout.trim() !== '') throw new Error('Tag \'' + version + '\' already exists');
grunt.config('buildtag', '');
grunt.config('builddir', 'release');
})
);
});
grunt.registerTask('perform-release', function () {
var version = grunt.config('pkg.version'), releasedir = grunt.config('builddir');
grunt.task.requires([ 'prepare-release', 'build' ]);
grunt.file.delete(releasedir + "/es5");
grunt.file.delete(releasedir + "/es6");
promising(this,
system('git add \'' + releasedir + '\'').then(function () {
return system('git commit -m \'release ' + version + '\'');
}).then(function () {
return system('git tag \'' + version + '\'');
})
);
});
// Helpers for custom tasks, mainly around promises / exec
var exec = require('faithful-exec'), shjs = require('shelljs');
function system(cmd) {
grunt.log.write('% ' + cmd + '\n');
return exec(cmd).then(function (result) {
grunt.log.write(result.stderr + result.stdout);
}, function (error) {
grunt.log.write(error.stderr + '\n');
throw new Error('Failed to run \'' + cmd + '\'');
});
}
function promising(task, promise) {
var done = task.async();
promise.then(function () {
done();
}, function (error) {
grunt.log.write(error + '\n');
done(false);
});
}
function ensureCleanMaster() {
return exec('git symbolic-ref HEAD').then(function (result) {
if (result.stdout.trim() !== 'refs/heads/master') throw new Error('Not on master branch, aborting');
return exec('git status --porcelain');
}).then(function (result) {
if (result.stdout.trim() !== '') throw new Error('Working copy is dirty, aborting');
});
}
};