forked from angular/in-memory-web-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
140 lines (128 loc) · 3.92 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
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 rollup = require('rollup-stream');
var source = require('vinyl-source-stream');
var path = require("path");
var inMemSrc = './src/in-mem/';
var jsCopySrc = ['*.js', '*.js.map', '*.d.ts', '*.metadata.json'].map(ext => inMemSrc + ext);
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', ['umd'], function(){
return gulp
.src(jsCopySrc)
.pipe(gulp.dest('./'));
});
gulp.task('ngc', ['clean'], function(done) {
runNgc('src/in-mem/', done);
});
// Uses rollup-stream plugin https://www.npmjs.com/package/rollup-stream
gulp.task('umd', ['ngc'], function(done) {
return rollup('rollup.config.js')
.pipe(source('in-memory-web-api.umd.js'))
.pipe(gulp.dest('./bundles'));
});
gulp.task('clean', function() {
return Promise.all([
clean([
'aot/**/*.*',
'src/**/*.d.ts',
'src/**/*.js.map',
'src/**/*.metadata.json',
'src/**/*.ngfactory.ts',
'src/**/*.ngsummary.json'
]),
clean([
'src/app/**.*js',
'src/in-mem/**.*js',
'src/in-mem/node_modules/**/*.*',
]),
clean([ /* root-level copies of in-mem web api files */
'./backend.service.*',
'./http-status-codes.*',
'./http-backend.service.*',
'./http-client-backend.service.*',
'./interfaces.*',
'./http-in-memory-web-api.module.*',
'./http-client-in-memory-web-api.module.*',
'./in-memory-web-api.module.*',
'./index.*',
'./bundles/in-memory-web-api.umd.js'
])
])
.then(() => console.log('Cleaned successfully'));
});
/**
* 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 clean(path) {
log('Cleaning: ' + $.util.colors.blue(path));
return del(path, {dryRun:false})
.then(function(paths) {
console.log('Deleted files and folders:\n', paths.join('\n'));
});
}
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 runNgc(directory, done) {
directory = directory || './';
//var ngcjs = path.join(process.cwd(), 'node_modules/typescript/bin/tsc');
//ngcjs = path.join(process.cwd(), 'node_modules/.bin/ngc');
var ngcjs = './node_modules/@angular/compiler-cli/src/main.js';
var childProcess = cp.spawn('node', [ngcjs, '-p', './tsconfig-ngc.json'], { 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 (code) {
if (code !== 0) {
throw(new Error('ngc compilation exited with an error code'))
} else {
done();
}
});
}