forked from MortenHoustonLudvigsen/process-promises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
94 lines (75 loc) · 2.58 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
/// <binding AfterBuild='dist' Clean='clean' />
var gulp = require('gulp');
var gutil = require('gulp-util');
var rimraf = require('gulp-rimraf');
var jasmine = require('gulp-jasmine');
var Promise = require('bluebird');
var _resolve = require('resolve');
var split = require('split');
var spawn = require('child_process').spawn;
function tsc(projectDir) {
function locateTsc() {
return new Promise(function (resolve, reject) {
_resolve('typescript/lib/tsc.js', { basedir: __dirname }, function (err, res) {
if (err) {
reject(err);
} else {
gutil.log('resolved tsc: ' + res);
resolve(res);
}
});
});
}
function promiseTsc(tscPath) {
gutil.log('tsc: ' + tscPath);
return new Promise(function (resolve, reject) {
var childProcess = spawn('node', [tscPath, '-p', projectDir]);
childProcess.stdout.pipe(split()).on('data', function (line) {
if (line) gutil.log(line);
});
childProcess.stderr.pipe(split()).on('data', function (line) {
if (line) gutil.log('Error: ' + line);
});
childProcess.on('error', function (err) {
reject(err);
});
childProcess.on('close', function (exitCode) {
resolve(exitCode);
});
});
}
return locateTsc().then(promiseTsc);
};
var modulePath = 'node_modules/process-promises';
var moduleLib = modulePath + '/lib';
gulp.task('clean', function () {
var src = [];
src.push(modulePath);
src.push('build');
src.push('lib');
return gulp.src(src).pipe(rimraf());
});
gulp.task('init', ['clean'], function () {
return gulp.src('package.json').pipe(gulp.dest(modulePath));
});
gulp.task('compile', ['init'], function () {
return tsc('src');
});
gulp.task('compile:test', ['compile'], function () {
return tsc('test');
});
gulp.task('copy:test', ['compile:test'], function () {
return gulp
.src(['test/**/*.js', 'test/**/*.json'])
.pipe(gulp.dest('build/test'));
});
gulp.task('test', ['compile:test', 'copy:test'], function () {
return gulp.src('build/test/specs/**/*.js')
.pipe(jasmine({ verbose: true }));
});
gulp.task('dist', ['test'], function () {
return gulp
.src([moduleLib + '/**/*', '!**/*.map'])
.pipe(gulp.dest('lib'));
});
gulp.task('default', ['dist']);