-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
plugins.js
370 lines (301 loc) · 11.6 KB
/
plugins.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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
var fs = require('fs');
var path = require('canonical-path');
var util = require('./utils.js');
var semver = require('semver');
var shell = require('shelljs');
var ngdoc = require('../../node_modules/grunt-ngdocs/src/ngdoc.js');
var reader = require('../../node_modules/grunt-ngdocs/src/reader.js');
var projectPath = path.resolve(__dirname, '../..');
var pkg = require(path.resolve(projectPath, 'package.json'));
module.exports = function(grunt) {
/*
*
* Create tasks
*
*/
grunt.registerMultiTask('tests', '**Use `grunt test` instead**', function(){
util.startKarma.call(util, this.data, true, this.async());
});
// Run tests on multiple versions of angular
grunt.registerTask('karmangular', 'Run tests against multiple versions of angular', function() {
// Start karma servers
var karmaOpts = grunt.config('karma');
if (grunt.option('browsers')) {
grunt.config('karma.options.browsers', grunt.option('browsers').split(/,/).map(function(b) { return b.trim(); }));
}
var angularTasks = [];
for (var o in karmaOpts) {
if (/^angular-/.test(o)) {
angularTasks.push(o);
}
}
// If there's a start/run argument, run that argument on each angular task
if (this.args.length > 0) {
// Run a test on the most recent angular
if (this.args[0] === 'latest') {
var latest = 'angular-' + util.latestAngular();
var configNamespace = 'karma.' + grunt.config.escape(latest);
grunt.config(configNamespace + '.background', false);
grunt.config(configNamespace + '.singleRun', true);
grunt.task.run('karma:' + latest);
}
if (this.args[0] === 'start') {
angularTasks.forEach(function(t) {
// Set this karma config to background running
var configNamespace = 'karma.' + grunt.config.escape(t);
grunt.config(configNamespace + '.background', true);
grunt.config(configNamespace + '.singleRun', false);
grunt.task.run('karma:' + t + ':start');
});
}
else if (this.args[0] === 'run') {
angularTasks.forEach(function(t) {
// Set this karma config to background running
var configNamespace = 'karma.' + grunt.config.escape(t);
grunt.config(configNamespace + '.background', true);
grunt.config(configNamespace + '.singleRun', false);
grunt.task.run('karma:' + t + ':run');
});
}
}
else {
angularTasks.forEach(function(t) {
// Set this task to single running
var configNamespace = 'karma.' + grunt.config.escape(t);
grunt.config(configNamespace + '.background', false);
grunt.config(configNamespace + '.singleRun', true);
grunt.task.run('karma:' + t);
});
}
});
// Run multiple tests serially, but continue if one of them fails.
// Adapted from http://stackoverflow.com/questions/16487681/gruntfile-getting-error-codes-from-programs-serially
grunt.registerTask('serialsauce', function(){
// util.travisFoldStart('serialsauce');
var options = grunt.config('serialsauce');
var done = this.async();
var tasks = {}; options.map(function(t) { tasks[t] = 0 });
var success = true;
grunt.util.async.forEachSeries(Object.keys(tasks),
function(task, next) {
grunt.util.spawn({
grunt: true, // use grunt to spawn
args: [task], // spawn this task
opts: { stdio: 'inherit' } // print to the same stdout
}, function(err, result, code) {
tasks[task] = code;
if (code !== 0) {
success = false;
}
next();
});
},
function() {
// util.travisFoldEnd('serialsauce');
done(success);
});
});
grunt.registerTask('coverage', function () {
var latest = 'angular-' + util.latestAngular();
var configNamespace = 'karma.' + grunt.config.escape(latest);
grunt.config(configNamespace + '.background', false);
grunt.config(configNamespace + '.singleRun', true);
grunt.config(configNamespace + '.reporters', ['coverage']);
grunt.config(configNamespace + '.preprocessors', {
'src/**/!(*.spec)+(.js)': ['coverage']
});
grunt.config(configNamespace + '.coverageReporter', {
type: 'lcov',
dir: 'coverage',
subdir: '.'
});
grunt.task.run('karma:' + latest);
});
grunt.registerTask('angulars', 'List available angular versions', function() {
grunt.log.subhead("AngularJS versions available");
grunt.log.writeln();
util.angulars().forEach(function (a) {
grunt.log.writeln(a);
});
});
grunt.registerTask('saucebrowsers', 'List available saucelabs browsers', function() {
grunt.log.subhead('SauceLabs Browsers Configured');
grunt.log.writeln();
var browsers = util.customLaunchers();
for (var name in browsers) {
var b = browsers[name];
var outs = [];
['browserName', 'version', 'platform'].map(function (o) {
if (b[o]) { outs.push(b[o]); }
});
grunt.log.write(grunt.log.wordlist([name], { color: 'yellow' }));
grunt.log.writeln(grunt.log.wordlist([
' [',
outs.join(' | '),
']'
], { color: 'green', separator: '' }));
};
});
// Utility functions for showing the version
grunt.registerTask('current-version', function () {
grunt.log.writeln(util.getVersion());
});
grunt.registerTask('stable-version', function () {
grunt.log.writeln(util.getStableVersion());
});
grunt.registerMultiTask('cut-release', 'Release the built code', function() {
// Require the build and ngdocs tassk to be run first
grunt.task.requires(['build']);
var options = this.options({
stableSuffix: '',
unstableSuffix: '-unstable',
cleanup: false
});
var done = this.async(),
self = this;
var tag = util.getVersion();
var currentTag = util.getCurrentTag();
grunt.log.writeln("Version: " + tag);
if (!tag) {
grunt.fatal("Couldn't get git version");
}
// Figure out if the tag is stable or not (if it has a hyphen in it it's unstable)
var stable = !/-.+$/.test(tag);
grunt.log.writeln('stable', stable);
// Log release type
grunt.log.writeln(
'Preparing '
+ grunt.log.wordlist([stable ? 'stable' : 'unstable'], { color: stable ? 'green' : 'yellow'})
+ ' release version '
+ tag
);
// If this is a stable release, create a directory for it in the releases dir
var extension = stable ? options.stableSuffix : options.unstableSuffix;
self.files.forEach(function (file) {
var releaseDir;
// If we're on a stable release or we want to keep unstable releases, create a directory for this release and copy the built files there
if (currentTag || options.keepUnstable) {
grunt.log.writeln("DEST: " + file.dest);
grunt.log.writeln("TAG: " + tag);
releaseDir = path.join(file.dest, tag);
}
file.src.forEach(function (f) {
var oldFileName = path.basename(f);
var ext = path.extname(f);
var basename = path.basename(f, ext);
if (basename.match(/.min/)) {
ext = '.min' + ext;
basename = path.basename(f, ext);
}
// Skip file if it was already released
var exp;
if (options.stableSuffix !== ''){
exp = '(' + options.stableSuffix + '|' + options.unstableSuffix + ')';
} else {
exp = '(' + options.unstableSuffix + ')';
}
var re = new RegExp(exp);
if (basename.match(re)) {
grunt.log.writeln("Skipping file: " + f);
return;
}
// Insert -unstable or -stable into the filename for .css and .js files
var newFileName;
if (/(css|js)/.test(ext)) {
newFileName = basename + extension + ext;
}
else {
newFileName = basename + ext;
}
// If this is a stable release
if (releaseDir) {
// Create the stable directory if it doesn't exist
if (!fs.existsSync(releaseDir)) {
fs.mkdirSync(releaseDir);
}
var releasePath = path.join(releaseDir, oldFileName);
if (path.normalize(f) !== path.normalize(releasePath)) {
grunt.log.writeln('Copying ' + f + ' to ' + releasePath);
// fs.createReadStream(f).pipe(fs.createWriteStream(stablePath));
shell.cp('-f', f, releasePath);
}
}
var newPath = path.join(file.dest, newFileName);
if (path.normalize(f) !== path.normalize(newPath)) {
grunt.log.writeln('Copying ' + f + ' to ' + newPath);
// fs.createReadStream(f).pipe(fs.createWriteStream(newPath));
shell.cp('-f', f, newPath);
}
if (options.cleanup && path.normalize(f) !== path.normalize(newPath)) {
grunt.log.writeln('Unlinking ' + f, newPath);
shell.rm(f);
}
});
//Run tasks for a stable release
if (currentTag && options.stableTasks) {
grunt.task.run(options.stableTasks);
}
});
done();
});
// Create the bower.json file
grunt.registerTask('update-bower-json', function () {
var currentTag = semver.clean( util.getVersion() );
var taggedReleaseDir = path.join(path.resolve(process.cwd()), 'dist', 'release', currentTag);
// Get the list of files from the release directory
var releaseFiles = fs.readdirSync(taggedReleaseDir)
// Filter out minified files and the bower.json file, if it's there already
.filter(function (f) {
return !/\.min\./.test(f)
&& !/^bower\.json$/.test(f)
&& !/^package\.json$/.test(f);
})
// Preprend "./" to each file path
.map(function (f) { return './' + f; });
// Copy a README file
var readme = path.resolve(projectPath, 'misc/publish/README.md');
shell.cp('-f', readme, taggedReleaseDir);
var bowerJsonFile = path.join(taggedReleaseDir, 'bower.json');
var pkgJsonFile = path.join(taggedReleaseDir, 'package.json');
var json = {
'name': 'angular-ui-grid',
'description': pkg.description,
'main': releaseFiles,
'ignore': [],
'dependencies': {
'angular': '>=1.2.16 1.4.x'
},
'repository': pkg.repository,
'homepage': 'http://ui-grid.info',
'bugs': { url : 'https://github.com/angular-ui/ui-grid/issues' },
'keywords': pkg.keywords,
'license': pkg.license
};
fs.writeFileSync(bowerJsonFile, JSON.stringify(json, null, 2));
// Add version for package.json
json.version = currentTag;
fs.writeFileSync(pkgJsonFile, JSON.stringify(json, null, 2));
});
// Publish release to NPM
grunt.registerTask('npm-publish', function (done) {
var done = this.async();
var currentTag = semver.clean( util.getCurrentTag() );
var taggedReleaseDir = path.join(path.resolve(process.cwd()), 'dist', 'release', currentTag);
process.chdir(taggedReleaseDir);
shell.exec('npm publish', function (code, output) {
done();
});
});
grunt.registerTask('blah', function () {
reader.docs = []
grunt.file.recurse(path.resolve(process.cwd(), 'src'), function (abspath, rootdir, subdir, filename) {
if (!/style\.js$/.test(filename)) { return; }
var contents = fs.readFileSync(abspath, 'utf8');
// var d = new ngdoc.Doc(contents);
// d.parse();
// console.log(d);
reader.process(contents, abspath);
});
console.log(reader.docs[0].convertUrlToAbsolute());
});
};