-
Notifications
You must be signed in to change notification settings - Fork 73
/
gulpfile.js
331 lines (288 loc) · 9.86 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
var args = require('yargs').argv;
var config = require('./gulp.config')();
var gulp = require('gulp');
var path = require('path');
var cp = require('child_process');
var $ = require('gulp-load-plugins')({ lazy: true });
var del = require('del');
var mocha = require("gulp-mocha");
var gutil = require("gulp-util");
var colors = $.util.colors;
var envenv = $.util.env;
var gulp_typedoc = require("gulp-typedoc");
var typedoc = require('typedoc');
/**
* yargs variables can be passed in to alter the behavior, when present.
* Example: gulp serve-dev
*
* --verbose : Various tasks will produce more output to the console.
* --nosync : Don't launch the browser with browser-sync when serving code.
* --debug : Launch debugger with node-inspector.
* --debug-brk: Launch debugger and break on 1st line with node-inspector.
* --startServers: Will start servers for midway tests on the test task.
*/
/**
* List the available gulp tasks
*/
gulp.task('help', $.taskListing);
gulp.task('default', ['help']);
gulp.task('build', ['ts-compile']);
gulp.task('build-all', ['ts-compile', 'ts-compile-amd']);//, 'ts-compile-tests', 'ts-compile-amd-tests']);
//gulp.task('ts-clean', function(done) {
// clean(config.ts.output, done);
//});
//
//gulp.task('ts-vet', function () {
// var reporter = args.verbose ? 'verbose' : 'prose';
// return gulp
// .src(config.ts.allts)
// .pipe($.if(args.verbose, $.print()))
// .pipe($.tslint())
// .pipe($.tslint.report(reporter));
//});
/**
* Creates the app.d.ts file with all references to *.ts files
* Not needed if we use the `files: undefined` in tsconfig.json
*/
//gulp.task('ts-create-refs', function () {
// var source = gulp.src(config.ts.allts, { read: false });
// var injectOptions = {
// starttag: '//{',
// endtag: '//}',
// transform: config.ts.transformFn
// };
//
// fs.writeFile(config.ts.refs, '//{\n//}', function(err) {
// if(err) { return log(err); }
// log('The file was saved!');
// });
//
// return gulp.src(config.ts.refs)
// .pipe($.inject(source, injectOptions))
// .pipe($.if(args.verbose, $.print()))
// .pipe(gulp.dest(config.ts.typings));
//});
/**
* Watch TypeScript and recompile and create refs
*/
gulp.task('ts-watcher', function () {
gulp.watch(config.ts.files, ['ts-compile']);
});
/**
* Compiles *.js files, sourcemaps,
* and optionally d.ts files (if passed --dts)
*/
gulp.task('ts-compile', function (done) {
var outdir = path.join(process.cwd(), 'build/output/node');
runTSC('.', outdir, [], done);
});
function runTSC(inputDir, outputDir, tsArgs, done) {
var tscjs = path.join(process.cwd(), 'node_modules/typescript/bin/tsc');
//console.log(outputDir);
var tsArguments = [tscjs, '-p', inputDir, '--outDir', outputDir];
tsArgs.forEach(function (arg) {
tsArguments.push(arg);
});
var childProcess = cp.spawn('node', tsArguments, { cwd: process.cwd() });
childProcess.stdout.on('data', function (data) {
// Ticino will read the output
console.log(data.toString());
});
childProcess.stderr.on('data', function (data) {
// Ticino will read the output
console.log(data.toString());
});
childProcess.on('close', function () {
done();
});
}
/**
* Compiles *.js files, sourcemaps,
* and optionally d.ts files (if passed --dts)
*/
gulp.task('ts-compile-amd', function (done) {
var outdir = path.join(process.cwd(), 'build/output/amd');
runTSC('.', outdir, ["--module", "amd"], done);
});
/**
* Compiles *.js files, sourcemaps,
* and optionally d.ts files (if passed --dts)
*/
// gulp.task('ts-compile-tests', [], function (done) {
// var outdir = path.join(process.cwd(), 'build/output/node/test/mocha/');
// runTSC("./test", outdir, [ '--listFiles'], done);
// });
gulp.task('tests', [], function (done) {
return gulp.src([
'./build/output/node/test/mocha/**/*.js',
], { read: false })
.pipe(mocha({ reporter: 'spec' }))
.on('error', gutil.log);
});
// gulp.task('ts-compile-amd-tests', function (done) {
// var outdir = path.join(process.cwd(), 'build/output/amd/test/mocha');
// runTSC('./test', outdir, ["--module", "amd"], done);
// });
// gulp.task('amd-tests', ['ts-compile-amd-tests'], function (done) {
// return gulp.src(['./build/output/amd/test/mocha/*.js'], { read: false })
// .pipe(mocha({ reporter: 'spec' }))
// .on('error', gutil.log);
// });
gulp.task('serve-dev', function (done) {
var childProcess = cp.spawn('http-server', ['./build/output/amd'], { cwd: process.cwd() });
childProcess.stdout.on('data', function (data) {
// Ticino will read the output
console.log(data.toString());
});
childProcess.stderr.on('data', function (data) {
// Ticino will read the output
console.log(data.toString());
});
childProcess.on('close', function () {
done();
});
});
gulp.task("npm-prep", function () {
gulp.src([
"./README.md",
"./LICENSE",
"./COPYRIGHT",
"./package.json"
])
.pipe(gulp.dest("./build/output/node/src"));
return gulp.src(["./typings/ExchangeWebService.d.ts"])
.pipe(gulp.dest("./build/output/node/src/typings"));
});
gulp.task('ts-def-compile', function (done) {
var outdir = path.join(process.cwd(), 'build/output/.tmp');
runTSC('.', outdir, ["--declaration"], done);
});
/** import statement regex "^import\s*\{\s*.*\s*\}.*from.*;" */
var concat = require('gulp-concat');
var replace = require('gulp-replace');
var deleteLines = require('gulp-delete-lines');
gulp.task("ts-def-prep", ["ts-def-compile"], function () {
return gulp.src([
"./build/output/.tmp/src/**/*.d.ts"
])
.pipe(deleteLines({
'filters': [
/^\s*$/
]
}))
.pipe(concat("temp.d.ts"))
.pipe(replace(/^.*import.*\{.*\}.*from.*\;/gm, ''))
.pipe(replace("import * as moment from 'moment-timezone';", ''))
.pipe(replace(/^.*export.*\{.*\}.*from.*\;/gm, ''))
.pipe(replace(/^.*export.*\{.*\};$/gm, ''))
.pipe(replace(/^.*\/\/\/\s*\<reference.*\>/gm, ''))
.pipe(replace(/^\s*private\s.*;/gm, ''))
.pipe(replace('\r\n\r\n', ''))
.pipe(replace('\n\n', ''))
.pipe(replace('export declare', ''))
.pipe(gulp.dest("./build/output/.tmp/"));
});
gulp.task("ts-def-concat", ["ts-def-prep"], function () {
return gulp.src([
"./config/tsd.start",
"./build/output/.tmp/temp.d.ts",
"./config/tsd.end"
])
.pipe(concat("ExchangeWebService.d.ts"))
.pipe(gulp.dest("./typings/"));
});
gulp.task('ts-def-clean', ["ts-def-concat"], function (done) {
var delconfig = [].concat("build/output/.tmp/*");
log('Cleaning: ' + $.util.colors.blue(delconfig));
del(delconfig, done);
});
gulp.task("build-typedef", ['ts-def-clean'])
/**
* When files change, log it
* @param {Object} event - event that fired
*/
function changeEvent(event) {
var srcPattern = new RegExp('/.*(?=/' + config.source + ')/');
log('File ' + event.path.replace(srcPattern, '') + ' ' + event.type);
}
/**
* 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));
}
}
/**
* replace line [reflection.name = '"' + _this.basePath.trim(name) + '"';] with [reflection.name = _this.basePath.trim(name);] to avoid '"' in names
*/
gulp.task("typedocX", function () {
process.chdir("./src/js/");
return gulp
.src(config.typedocFiles)
.pipe(gulp_typedoc({
// TypeScript options (see typescript docs)
module: "commonjs",
target: "es5",
includeDeclarations: true,
// Output options (see typedoc docs)
out: "./build/docs",
//json: "./build/docs/file.json",
// TypeDoc options (see typedoc docs)
name: "EWS JavaScript Api",
theme: "default",
//plugins: ["my", "plugins"],
ignoreCompilerErrors: true,
//version: true,
}));
});
gulp.task("typedocFile", function () {
var options = {
target: "ES5",
module: "commonjs",
//experimentalDecorators: true,
//emitDecoratorMetadata: true,
//allowUnreachableCode: true,
ignoreCompilerErrors: true,
name: "Ews JavaScript Api",
verbose: false,
//entryPoint:'"Core/ExchangeService"',
exclude: "**/*.d*.ts",
excludeExternals: true,
theme: "default",
mode: "File",
readme: "none"
}
var app = new typedoc.Application(options);
return app.generateDocs(app.expandInputFiles(['.\\src\\js']), ".\\build\\docs\\FileMode");
//return app.generateDocs(app.expandInputFiles(['.\\src\\js\\Core\\ServiceObjects\\Items']), ".\\build\\doc\\File");
});
gulp.task("typedocModules", function () {
var options = {
target: "ES5",
module: "commonjs",
//experimentalDecorators: true,
//emitDecoratorMetadata: true,
//allowUnreachableCode: true,
ignoreCompilerErrors: true,
name: "Ews JavaScript Api",
verbose: false,
//entryPoint:'Core/ExchangeService',
exclude: "**/*.d*.ts",
excludeExternals: true,
theme: "default",
mode: "Modules",
readme: "none"
}
var app = new typedoc.Application(options);
return app.generateDocs(app.expandInputFiles(['.\\src\\js']), ".\\build\\docs\\ModulesMode");
});
gulp.task("typedoc", ["typedocFile", "typedocModules"]);
module.exports = gulp;