forked from OfficeDev/generator-office
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
133 lines (113 loc) · 3.53 KB
/
gulpfile.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
'use strict';
var args = require('yargs').argv;
var spawn = require('child_process').spawn;
var chalk = require('chalk');
var which = require('which');
var path = require('path');
var config = require('./gulp.config.js');
var gulp = require('gulp');
var $ = require('gulp-load-plugins')({lazy: true});
var cwd = process.cwd();
/**
* yargs variables can be passed in to alter the behavior, when present.
* Example: gulp vet
* or: gulp vet --verbose
*
* --verbose : Various tasks will produce more output to the console.
*/
/**
* List the available gulp tasks
*/
gulp.task('help', $.taskListing);
gulp.task('default', ['help']);
/* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */
/**
* Vets all JS for code style.
*/
gulp.task('vet', function(){
log('Analyzing source with JSHint and JSCS');
return gulp
.src(config.allJs, {base: './'})
.pipe($.if(args.verbose, $.print()))
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish', {verbose: true}))
.pipe($.jscs());
});
/**
* Run all tests with code coverage.
*/
gulp.task('test', function(done){
gulp.src([path.join(cwd, 'generators/**/.js')])
.pipe($.if(args.verbose, $.print()))
.pipe($.istanbul()) // covering files
.pipe($.istanbul.hookRequire()) // force 'require' to return coverd files
.on('finish', function(){
gulp.src([path.join(cwd, 'test/**/*.js')])
.pipe($.mocha()) // run tests
.on('error', handleError)
.pipe($.istanbul.writeReports()) // write coverage reports
.on('end', done);
});
});
/**
* Run the Yeoman generator in debug mode.
*/
gulp.task('run-yo', function(){
log(chalk.yellow('BE AWARE!!! - Running this with default options will scaffold the project ' +
'in the generator\'s source folder.'));
// determine correct path for platform
var yeomanCliPath = 'lib/node_modules/yo/lib/cli.js';
if (process.platform === 'win32'){
yeomanCliPath = 'npm/node_modules/yo/lib/cli.js';
}
spawn('node',
[
'--debug',
path.join(which.sync('yo'), '../../', yeomanCliPath),
'office',
' --skip-install'
], {
stdio: 'inherit'
});
});
/* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */
/* auto / watch tasks */
/* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */
/**
* Watch for changes in any JS files to changes, then vet's & tests them.
*/
gulp.task('autotest', function(done){
gulp.watch(['generators/**', 'test/**'], ['vet', 'test']);
});
/**
* Watches for changes in scripts and auto-vets the JS with JSHint & JSCS.
*/
gulp.task('autovet', function(done){
gulp.watch(['./.jscsrc', './.jshintrc', '**/*.js'], ['vet']);
});
/* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */
/* utility methods */
/* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */
/**
* Log a message or series of messages using chalk's blue color.
* Can pass in a string, object or array.
*/
function log(msg){
if (typeof (msg) === 'object') {
for (var item in msg) {
if (msg.hasOwnProperty(item)) {
$.util.log($.util.colors.blue(msg[item]));
}
}
} else {
$.util.log($.util.colors.blue(msg));
}
}
/**
* Handle errors by writing to the log, then emit an end event.
*/
function handleError(err){
$.util.log(err.toString());
this.emit('end'); // jshint ignore:line
}
module.exports = gulp;