-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathgulpfile.js
157 lines (139 loc) · 4.02 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
var gulp = require('gulp');
var $ = require('gulp-load-plugins')({lazy: true});
var args = require('yargs').argv;
var cp = require('child_process');
var del = require('del');
var path = require("path");
var Builder = require('systemjs-builder');
var tsOutput = './a2-in-memory-web-api/';
var jsCopySrc = [tsOutput+'*.js', tsOutput+'*.d.ts']
gulp.task('default', ['help']);
gulp.task('help', $.taskListing.withFilters(function (taskName) {
var isSubTask = taskName.substr(0, 1) == "_";
return isSubTask;
}, function (taskName) {
var shouldRemove = taskName === 'default';
return shouldRemove;
}));
gulp.task('build', ['tsc'], build);
gulp.task('build-only', build);
gulp.task('tsc', ['tsc-only'], function(){
return gulp
.src(jsCopySrc)
.pipe(gulp.dest('./'));
});
gulp.task('tsc-only',['clean'], function(done) {
runTSC('./', done);
});
gulp.task('clean', function(done) {
clean([tsOutput+'*.*', '*.js','*.d.ts','!gulpfile.js'], done);
});
/**
* Bump the version
* --type=pre will bump the prerelease version *.*.*-x
* --type=patch or no flag will bump the patch version *.*.x
* --type=minor will bump the minor version *.x.*
* --type=major will bump the major version x.*.*
* --version=1.2.3 will bump to a specific version and ignore other flags
*/
gulp.task('bump', function() {
var msg = 'Bumping versions';
var type = args.type;
var version = args.ver;
var options = {};
if (version) {
options.version = version;
msg += ' to ' + version;
} else {
options.type = type;
msg += ' for a ' + type;
}
log(msg);
return gulp
.src('package.json')
// .pipe($.print())
.pipe($.bump(options))
.pipe(gulp.dest('./'));
});
//////////
function build(done) {
var builder = new Builder({
paths: {'*': '*.js'},
map: {
angular2: 'node_modules/angular2',
rxjs: 'node_modules/rxjs'
},
meta: {
'angular2/*': { build: false },
'rxjs/*': { build: false }
},
packages: {
'angular2': {
defaultExtension: 'js',
main: 'core.js'
},
'rxjs': {
defaultExtension: 'js',
main: 'rx.js'
}
}
});
builder
// start building with the root module file in the folder with the intended module name
.bundle('a2-in-memory-web-api/core', 'web-api.js')
.then(function(output) {
console.log('Build complete');
})
.catch(function(err) {
console.log('Build error');
console.log(err);
})
.finally(done);
}
function clean(path, done) {
log('Cleaning: ' + $.util.colors.blue(path));
del(path, {dryRun:false})
.then(function(paths) {
console.log('Deleted files and folders:\n', paths.join('\n'));
})
.then(done,done);
}
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));
}
}
function runTSC(directory, done) {
directory = directory || './';
var tscjs = path.join(process.cwd(), 'node_modules/typescript/bin/tsc');
var childProcess = cp.spawn('node', [tscjs, '-p', directory], { cwd: process.cwd() });
childProcess.stdout.on('data', function (data) {
console.log(data.toString());
});
childProcess.stderr.on('data', function (data) {
console.log(data.toString());
});
childProcess.on('close', function () {
done();
});
}
// WILL THIS WORK? DOES IT PROMPT?
function runTypings(done) {
var typingsjs = path.join(process.cwd(), 'node_modules/typings/dist/bin/typings');
var childProcess = cp.spawn('node', [typingsjs, 'install'], { cwd: process.cwd() });
childProcess.stdout.on('data', function (data) {
console.log(data.toString());
});
childProcess.stderr.on('data', function (data) {
console.log(data.toString());
});
childProcess.on('close', function () {
done();
});
}