This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
202 lines (183 loc) · 5 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
/*jslint browser: true, node: true, vars: true*/
'use strict';
var gulp = require('gulp'),
mocha = require('gulp-mocha'),
gulpLoadPlugins = require('gulp-load-plugins'),
gutil = require('gulp-util'),
plugins = gulpLoadPlugins(),
jsdoc = require('gulp-jsdoc3'),
del = require('del'),
watch = require('gulp-watch'),
batch = require('gulp-batch'),
typescript = require('gulp-typescript'),
webpack = require('webpack-stream-fixed'),
config = require('./webpack.config.js'),
tsConfig = require('./tsconfig.json'),
spawn = require('child_process').spawn,
sourcemaps = require('gulp-sourcemaps'),
v8 = require('v8'),
Server = require('karma').Server,
stopper = require('karma').stopper;
//v8.setFlagsFromString('--trace_gc');
//v8.setFlagsFromString('--max_old_space_size=2048');
//v8.setFlagsFromString('--max_new_space_size=2048');
var cp = null;
//var DEBUG = '';
//var DEBUG = 'partout:*';
//var DEBUG = 'feathers-authentication:main';
//var DEBUG = 'feathers-authentication:authentication:utils';
//var DEBUG = 'sails-arangodb:connection, sails-arangodb:adapter, partout:app';
//var DEBUG = 'feathers-authentication-local:verify';
//var DEBUG = 'api:routes';
/*
* Currently env does not determine the arangodb being selected here, as all
* tests are using a mock-up of any required controllers. This will probably
* change in the near future when unit-tests come out of the current fine-
* granularity and in to wider more inclusive tests (e.g. from the app itself).
*/
var env = process.env.NODE_ENV || 'development';
//gulp.task('clean', function () {
// return del('dist/**/*');
//});
// Webpack does its own watching, see weback.config.js
gulp.task('webpack', function () {
// delay to let gulp start up the app
setTimeout(function () {
gulp.src('app/main.ts')
.pipe(
webpack(config, require('webpack'))
.on('error', function (err) {
gutil.log('WEBPACK ERROR:', err);
// if (cp) {
// console.log('killing partout');
// cp.kill();
// }
this.emit('end');
})
)
.pipe(gulp.dest('dist'));
}, 3000);
});
//gulp.task('run', ['compile'], function (done) {
gulp.task('run', function (done) {
// exec bin/partout
console.log('starting partout');
cp = spawn('bin/partout', {
env: {
NODE_ENV: env,
DEBUG: process.env.DEBUG
}, stdio: 'inherit'
});
done();
});
//gulp.task('chain', ['webpack', 'run']);
gulp.task('watch', function () {
watch([
// 'systemjs.config.js',
'app.js',
'appApi.js',
'appUi.js',
// 'app/**',
'lib/**',
'etc/*.js',
'etc/*.json',
'agent/lib/utils/**/*.js',
'agent/lib/pfs.js',
'server/**/*.js',
'public/**/*.js',
//'public/views/*.html',
// 'test/**'
], {
ignoreInitial: false,
verbose: true,
readDelay: 2000 // filter duplicate changed events from Brackets
}, batch(function (events, done) {
if (cp) {
console.log('killing partout');
cp.kill();
}
gulp.start('run', done);
}));
});
gulp.task('default', ['watch', 'webpack']);
gulp.task('mocha', function (done) {
process.env.NODE_ENV = 'test';
var cp = spawn('node_modules/.bin/nyc', [
'node_modules/.bin/mocha',
'test/**/*.js'
], {stdio: 'inherit'});
cp.on('close', (rc) => {
done(rc === 0 ? null : new Error('mocha failed rc=' + rc));
});
});
gulp.task('watch-mocha', function () {
watch([
'systemjs.config.js',
'app.js',
'appApi.js',
'appUi.js',
'app/**',
'lib/**',
'etc/*.js',
'agent/lib/utils/**/*.js',
'agent/lib/pfs.js',
'server/**/*.js',
'public/**/*.js',
//'public/views/*.html',
'test/**'
], {
ignoreInitial: false,
verbose: false,
readDelay: 1500 // filter duplicate changed events from Brackets
}, batch(function (events, done) {
gulp.start('mocha', done);
}));
});
// Karma / Jasmine
gulp.task('karma', function (done) {
const server = new Server({
configFile: __dirname + '/karma.conf.js',
singleRun: true
});
server.on('run_complete', (browsersCollection, results) => {
console.info('karma server run complete, stopping... results:', results);
stopper.stop({ port: 9876 });
const exitCode = results.exitCode;
done(exitCode === 0 ? null : new Error('Karma failed rc=' + exitCode));
});
server.start();
});
gulp.task('docs', function (cb) {
del(['./jsdocs/**']);
gulp.src([
'./app.js', 'lib/**/*.js',
'docs/*.md', './README.md'
])
.pipe(jsdoc(
{
opts: {
destination: './jsdocs'
},
plugins: [
'plugins/markdown'
],
templates: {
"cleverLinks": false,
"monospaceLinks": false,
"default": {
"outputSourceFiles": true
},
"path": "ink-docstrap",
"theme": "cerulean",
"navType": "vertical",
"linenums": true,
"dateFormat": "MMMM Do YYYY, h:mm:ss a"
},
"source": {
"includePattern": ".+\\.(js|p2|md)$",
"excludePattern": "node_modules"
}
},
cb
));
});