This repository has been archived by the owner on Mar 1, 2021. It is now read-only.
/
gulpfile.js
232 lines (200 loc) · 5.96 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
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
if (typeof Meteor === typeof undefined) {
// eslint-disable-next-line vars-on-top, no-var
var r = require
var gulp = r('gulp'),
version,
replace = r('gulp-replace'),
rename = r('gulp-rename'),
gutil = r('gulp-util'),
shell = r('gulp-shell'),
jshint = r('gulp-jshint'),
jshStylish = r('jshint-stylish'),
exec = r('child_process').exec,
runSequence = r('run-sequence'),
prompt = r('gulp-prompt'),
mocha = r('gulp-mocha'),
babel = r('babel-core/register'),
concat = r('gulp-concat'),
gulpReactDocs = r('gulp-react-docs'),
gulpJsdoc2md = r('gulp-jsdoc-to-markdown'),
debug = r('gulp-debug'),
runSequence = r('run-sequence'),
insert = r('gulp-insert'),
del = r('del')
// jsdoc = r('gulp-jsdoc3'), // very nice but does not support markdown
// documentation = r('gulp-documentation'), does not work
// markdown = r('gulp-markdown'),
// toc = require('gulp-doctoc'),
// marked = require('gulp-marked')
// RSG = require('react-styleguide-generator'), // jsdoc style does not work
// docco = r("gulp-jsx-docco"), no nav / table of contents
/*
* Docs
*/
var DOC_DEST_FOLDER = './.docs';
var API_DOC_DEST_FOLDER = './.apiDocs';
var UI_DOC_DEST_FOLDER = DOC_DEST_FOLDER + '/ui';
gulp.task('doc', function(done){
runSequence(
'doc:clean',
// 'doc:react',
// 'doc:api',
// 'doc:build',
function(){
gutil.log(gutil.colors.green('OK : docs built at ', DOC_DEST_FOLDER ))
done()
}
)
})
gulp.task('doc:clean', function() {
// Return the Promise from del()
return del([
API_DOC_DEST_FOLDER,
UI_DOC_DEST_FOLDER,
DOC_DEST_FOLDER+'/index.md',
DOC_DEST_FOLDER+'/api.md',
DOC_DEST_FOLDER+'/ui.md',
], { force : true});
});
gulp.task('doc:build', function(cb){
return gulp.src('./README.md')
.pipe(concat('index.md'))
.pipe(gulp.dest(DOC_DEST_FOLDER))
})
gulp.task('doc:react', function() {
return gulp.src('./imports/client/ui/components/**/*.jsx')
.pipe(gulpReactDocs())
// .pipe(insert.prepend('#')) // make h3
.pipe(insert.transform(function(contents, file) {
// QUICKFIX: add some nicer header stuff
var path = './imports/' + file.path.split('topogram/imports')[1].split(".")[0] + '.jsx'
var link = 'File: [' + path + '](../' + path + ')\n';
var name = file.path.split('/imports')[1].split("/").pop().split('.')[0]
var header = link + '\n'
return header + contents;
}))
.pipe(debug())
.pipe(gulp.dest(UI_DOC_DEST_FOLDER))
.pipe(concat('ui.md'))
.pipe(insert.prepend('# UI Components\n'))
.pipe(gulp.dest(DOC_DEST_FOLDER))
});
gulp.task('doc:api', function (cb) {
return gulp.src([
'./imports/api/**/*.js',
'!./imports/api/**/*.test.js'
])
.pipe(gulpJsdoc2md())
.on('error', function (err) {
gutil.log(gutil.colors.red('jsdoc2md failed'), err.message)
})
.pipe(rename(function (path) {
path.extname = '.md'
}))
.pipe(debug())
.pipe(gulp.dest(API_DOC_DEST_FOLDER))
.pipe(concat('api.md'))
.pipe(insert.prepend('# API Methods\n'))
.pipe(gulp.dest(DOC_DEST_FOLDER));
});
/*
* Testing
*/
gulp.task('test-meteor',
shell.task(['meteor test --once --driver-package=dispatch:mocha-phantomjs'], { verbose : true})
)
gulp.task('test', function() {
gulp.src( [
'./tests/*.js',
'./imports/ui/components/**/tests/*.spec.js',
], { read: false } )
.pipe( mocha( {
reporter:'nyan',
require : ['ignore-styles'],
compilers: {
js: babel
}
} ) )
})
/*
* Rebuild and pass tests on watch
*/
gulp.task('watch', function() {
gulp.watch(['./tests/*.js', './imports/**/*.js', './imports/**/*.jsx'], ['test']);
});
/*
* Versioning
*/
gulp.task('publish', [], function( next ){
runSequence('confver', 'lint', 'pkgver', 'push', 'tag', next);
});
gulp.task('confver', ['version'], function(){
return gulp.src('.')
.pipe( prompt.confirm({ message: 'Are you sure version `' + version + '` is OK to publish?' }) )
;
});
gulp.task('version', function( next ){
var now = new Date();
version = process.env['VERSION'];
if( version ){
done();
} else {
exec('git rev-parse HEAD', function( error, stdout ){
var sha = stdout.substring(0, 10); // shorten so not huge filename
version = [ 'snapshot', sha, +now ].join('-');
done();
});
}
function done(){
console.log('Using version number `%s` for building', version);
next();
}
});
gulp.task('pkgver', ['version'], function(){
return gulp.src([
'package.json',
'bower.json'
])
.pipe( replace(/\"version\"\:\s*\".*?\"/, '"version": "' + version + '"') )
.pipe( gulp.dest('./') )
;
});
gulp.task('push', shell.task([
'git add -A',
'git commit -m "pushing changes for v$VERSION release"',
'git push'
]));
gulp.task('tag', shell.task([
'git tag -a $VERSION -m "tagging v$VERSION"',
'git push origin $VERSION'
]));
gulp.task('npm', shell.task([
'npm publish .'
]));
// http://www.jshint.com/docs/options/
gulp.task('lint', function(){
return gulp.src( 'imports/*.js' )
.pipe( jshint({
esversion: 6,
funcscope: true,
laxbreak: true,
loopfunc: true,
strict: true,
unused: 'vars',
eqnull: true,
sub: true,
shadow: true,
laxcomma: true
}) )
.pipe( jshint.reporter(jshStylish) )
//.pipe( jshint.reporter('fail') )
;
});
/*
*
*/
gulp.task('default', [], function( next ){
console.log('You must explicitly call `gulp publish` to publish the extension');
next();
});
}