This repository has been archived by the owner on Dec 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathgulpfile.js
executable file
·366 lines (282 loc) · 10.2 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
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
/*jslint node: true*/
// Configuration options
var testDir = './test/',
buildDir = 'dist',
ritaDir = '../RiTa',
tmpDir = '/tmp';
///////////////////////////////////////////////////////
// Load package.json & plugins
var pjson = require('./package.json'),
gulp = require('gulp'),
scp = require('gulp-scp'),
browserify = require('browserify'),
reactify = require('reactify'),
source = require('vinyl-source-stream'),
exec = require('child_process').exec,
tasks = require('gulp-task-listing'),
gutil = require('gulp-util'),
qunit = require('gulp-qunit'),
jshint = require('gulp-jshint'),
replace = require('gulp-replace'),
concat = require('gulp-concat'),
rename = require('gulp-rename'),
argv = require('yargs').argv,
uglify = require('gulp-uglify'),
sym = require('gulp-symlink'),
del = require('del'),
version = pjson.version;
var bower = 'rita.min.js',
full = pjson.name + '-' + version + '.js',
min = pjson.name + '-' + version + '.min.js',
micro = pjson.name + '-' + version + '.micro.js',
mbify = pjson.name + '.micro.browserified.js',
bify = pjson.name + '.browserified.js',
ritext = 'ritext' + '-' + version + '.js';
//microp5 = pjson.name + '-' + version + '.microp5.js';
// Display gulp tasks
gulp.task('help', tasks);
///////////////////////////////////////////////////////
// Clean the build dir
gulp.task('clean', function(f) {
del(buildDir, f);
});
// create 2 browserify bundles (micro and regular)
gulp.task('build-browserify', ['build.js'], function() {
var tmp, b = browserify();
b.transform(reactify);
b.add(['./dist/rita.micro.js']);
tmp = b.bundle()
.pipe(source('rita.micro.js'))
.pipe(rename(mbify))
.pipe(gulp.dest('./dist/'));
b = browserify();
b.transform(reactify);
b.add(['./dist/rita.min.js']);
return tmp && b.bundle()
.pipe(source('rita.min.js'))
.pipe(rename(bify))
.pipe(gulp.dest('./dist/'));
});
/*
* publish js to host (red-or-local)
* link js on host
* update index.html on host
* update node
gulp.task('update', function() { // NEEDED?
if (1) return;
var host = argv.host ? argv.host : 'localhost';
var port = host === 'localhost' ? 22022 : 22;
console.log('Publishing to ' + host);
// publish (4) js files to www/rita/download
gulp.src(buildDir + '/rita-' + version + '*.js')
.pipe(scp({
host: host,
path: '~/www/rita/download',
user: process.env.USER,
port: port
}));
// publish new www/rita/download/index.html with version#
gulp.src(ritaDir + '/www/download/index.html')
.pipe(replace('##version##', version))
.pipe(gulp.dest(tmpDir))
.pipe(scp({
host: host,
path: '~/www/rita/download',
user: process.env.USER,
port: port
}));
}); */
gulp.task('pub-npm', ['build.node'], function(cb) { // not-ready
console.log('gulp: npm publish ');
var tgz = buildDir + '/rita-' + version + '.tgz';
console.log('npm publish ' + tgz);
if (1) return;
exec('npm publish ' + tgz, function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
// Concatenate & minify RiTaJS (3) into dist
gulp.task('bower-update', ['clean' ], function() {
// update version # in bower.json
return gulp.src(['bower.tmpl'])
.pipe(replace('##version##', version))
.pipe(concat('bower.json'))
.pipe(gulp.dest('.'));
});
//gulp.task('build.js', gsync.sync(['build.js-pre', 'symlink-min']));
// Concatenate & minify RiTaJS (3) into dist
gulp.task('build-pre.js', [ 'bower-update' ], function() {
// create micro version (only rita.js minified)
var tmp = gulp.src('src/rita.js')
.pipe(replace('##version##', version))
.pipe(concat(micro))
.pipe(uglify())
.pipe(gulp.dest(buildDir));
// create ritext version
tmp = tmp && gulp.src('src/ritext.js')
.pipe(concat(ritext))
.pipe(uglify())
.pipe(gulp.dest(buildDir));
// create 2 regular versions -- full, min
return tmp && gulp.src('src/rita*.js')
.pipe(replace('##version##', version))
.pipe(concat(full))
.pipe(gulp.dest(buildDir))
.pipe(rename(min))
.pipe(uglify())
.pipe(gulp.dest(buildDir));
});
gulp.task('build.js', ['build-pre.js'], function() {
var tmp = gulp.src(buildDir + '/' + micro)
.pipe(sym(buildDir + '/' + micro.replace('-'+version, '')));
return tmp && gulp.src(buildDir + '/' + min)
.pipe(sym(buildDir + '/' + min.replace('-'+version, '')));
});
gulp.task('handle-error', ['clean'], function(cb) {
var combiner = require('stream-combiner2');
var combined = combiner.obj( [
gulp.src('src/rita*.js'),
uglify(),
gulp.dest(buildDir + '/node/rita/lib')
] );
combined.on('error', console.error.bind(console));
return combined;
});
// Concatenate & minify RiTaJS + node pkg resources, into dist
gulp.task('build.node', ['clean'], function(cb) {
// copy in the node readme
gulp.src('./README.node.md')
.pipe(rename('README.md'))
.pipe(gulp.dest(buildDir + '/node/rita'));
// copy in other loose files
gulp.src(['./AUTHORS', './LICENSE', './package.json', './gulpfile.js'])
.pipe(gulp.dest(buildDir + '/node/rita'));
// copy in the tests
gulp.src([testDir + 'LibStructure*.*', testDir + '/Ri*.*', testDir + '/qunit*'])
//.pipe(gulpIgnore.exclude("KnownIssues*"))
.pipe(gulp.dest(buildDir + '/node/rita/test'));
// copy in the docs
//gulp.src(ritaDir + '/www/reference/**/*')
//.pipe(gulp.dest(buildDir + '/node/rita/doc'));
// copy in rita.js (min)
gulp.src('src/rita*.js')
.pipe(replace('##version##', version))
.pipe(concat(pjson.name + '-' + version + '-node.js'))
.pipe(rename(pjson.name + '.js'))
.pipe(uglify())
.pipe(gulp.dest(buildDir + '/node/rita/lib'));
/* FAILING (tgz is incomplete) */
// call npm pack & move the .tgz to build
/*exec("cd build/node/rita; npm pack", function (err, stdout, stderr) {
console.log(stdout);
gulp.src('./rita-'+version+'.tgz')
.pipe(clean());
gulp.src('./rita-'+version+'.tgz')
.pipe(gulp.dest(buildDir));
console.log(stderr);
cb(err);
});*/
});
// Watch Files For Changes
gulp.task('watch-src', function() {
gulp.watch('src/*.js', ['lint', 'build', 'build-node']);
});
// Lint Task
gulp.task('lint', function() {
var opts = {
asi: 1,
expr: 1,
laxbreak: 1
};
return gulp.src('src/*.js')
.pipe(jshint(opts))
.pipe(jshint.reporter('default'));
});
// Test(node): gulp test.node (all) || gulp test.node --name RiString
gulp.task('test.node.pkg', function(cb) {
var testrunner = require("qunit");
var tests = [
'test/LibStructure-tests',
'test/RiTaEvent-tests',
'test/RiString-tests',
'test/RiTa-tests',
//'test/RiGrammar-tests',
// TODO: figure out why this one test fails
'test/RiMarkov-tests',
'test/RiLexicon-tests'
];
if (argv.name) {
tests = [testDir + argv.name + '-tests'];
console.log('[INFO] Testing ' + tests[0]);
}
testrunner.setup({
maxBlockDuration: 20000,
log: {
globalSummary: true,
errors: true
}
});
testrunner.run({
code: "lib/rita.js",
deps: [
"test/qunit-helpers.js"
],
tests: tests
}, function(err, report) {
if (err) console.error(err);
});
});
// Test(node): gulp test.node (all) || gulp test.node --name RiString
gulp.task('test', function(cb) {
var testrunner = require("qunit");
var tests = [
'test/LibStructure-tests',
'test/RiTaEvent-tests',
'test/RiString-tests',
'test/RiTa-tests',
'test/RiGrammar-tests',
'test/RiMarkov-tests',
'test/RiLexicon-tests',
'test/UrlLoading-tests'
];
if (argv.name) {
tests = [testDir + argv.name + '-tests'];
console.log('[INFO] Testing ' + tests[0]);
}
testrunner.setup({
maxBlockDuration: 20000,
log: {
globalSummary: true,
errors: true
}
});
testrunner.run({
code: "src/rita.js",
deps: [
"src/rita_lts.js",
"src/rita_dict.js",
"test/qunit-helpers.js"
],
tests: tests
}, function(err, report) {
if (err) console.error(err);
});
});
// Test(phantom): gulp test (all) || gulp test --name RiString
gulp.task('test.phantom', function() {
var tests = [testDir + 'LibStructure-tests.html', testDir + '/Ri*.html'];
if (argv.name) {
tests = testDir + argv.name + '-tests.html';
if (!require('fs').existsSync(tests))
throw Error('Unable to load: ' + tests);
console.log('Running ' + tests);
}
return gulp.src(tests).pipe(qunit({
timeout: 20
}));
});
//gulp.task('node', [ 'clean','test','build.node','copy-node' ]);
gulp.task('build', ['build.js']); // 'build.node' ]);
gulp.task('default', ['help']);