This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 231
/
gulpfile.js
138 lines (127 loc) · 3.87 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
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 inMemSrc = './src/in-mem/';
var jsCopySrc = ['*.js', '*.js.map', '*.d.ts', '*.metadata.json'].map(ext => inMemSrc + ext);
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('default', gulp.series('help'));
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'));
});
gulp.task('ngc', gulp.series('clean', function(done) {
runNgc('src/in-mem/', done);
}));
// Uses rollup-stream plugin https://www.npmjs.com/package/rollup-stream
gulp.task('umd', gulp.series('ngc', function() {
return rollup('rollup.config.js')
.pipe(source('in-memory-web-api.umd.js'))
.pipe(gulp.dest('./bundles'));
}));
gulp.task('build', gulp.series('umd', function(){
return gulp
.src(jsCopySrc)
.pipe(gulp.dest('./'));
}));
/**
* 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: ' + 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)) {
console.log(msg[item]);
}
}
} else {
console.log(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();
}
});
}