This repository has been archived by the owner on Nov 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
163 lines (145 loc) · 3.57 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
const gulp = require('gulp');
const gulpMerge = require('merge2');
const gulpRunSequence = require('run-sequence');
const gulpConcat = require('gulp-concat');
const tsc = require('gulp-typescript');
const karma = require('karma');
const gulpClean = require('gulp-clean');
const path = require('path');
const exec = require('child_process').exec;
let isTestRun = false;
/**
* Copy the tsconfig to the staging folder
*/
gulp.task(':build:copy', () => {
return gulp
.src('./tsconfig.json')
.pipe(gulp.dest('./staging'));
});
/**
* Inline styles and templates and output the result into staging
*/
gulp.task(':build:inline', () => {
return gulp.src(['./src/**/*.ts', '!./src/**/*.spec.ts'])
.pipe(gulp.dest('./staging/src'))
})
/**
* Compile typescrypt using ngc.
*/
gulp.task(':build:ngc', (cb) => {
exec('npm run ngc', function (err, stdout, stderr) {
if (err && err.message.includes('npm ERR!')) {
console.log(stdout);
cb(new Error(err.message.substring(0, err.message.indexOf('npm ERR!')).trim()));
return;
}
cb(err);
});
})
/**
* Remove the staging folder
*/
gulp.task(':build:clean', () => gulp.src('staging', { read: false }).pipe(gulpClean(null)));
/**
* Copy compiled code into the dist folder, excluding the typescript source.
*/
gulp.task(':build:copyFinal', () => {
return gulp
.src(['./staging/src/**/*', '!./staging/src/**/*.ts'])
.pipe(gulp.dest('./dist'));
})
/**
* Copy the typedefs to dist, this was missing in :build:copyFinal.
*/
gulp.task(':build:typeDefs', () => {
return gulp
.src(['./staging/src/**/*.d.ts'])
.pipe(gulp.dest('./dist'));
})
/**
* Inline and then compile the lib.
*/
gulp.task(':build:app', (cb) => gulpRunSequence(
':build:inline',
':build:copy',
':build:ngc',
[
':build:copyFinal',
':build:typeDefs',
],
cb
));
/**
* Cleans the build folder
*/
gulp.task('clean', () => gulp.src('dist', { read: false }).pipe(gulpClean(null)));
/**
* Builds the main framework to the build folder
*/
gulp.task('build', (cb) => gulpRunSequence(
[
'clean',
':build:clean',
],
[
':build:app',
],
':build:clean',
cb
));
/**
* Inline the templates and styles, and the compile to javascript.
*/
gulp.task(':test:build', () => {
const tsProject = tsc.createProject('tsconfig.json', {
module: 'commonjs',
});
const src = ['./src/**/*.ts'];
return gulp.src(src)
.pipe(tsProject())
.pipe(gulp.dest('./dist'));
});
/**
* Bundles vendor files for test access
*/
gulp.task(':test:vendor', function () {
const npmVendorFiles = [
'@angular', 'core-js/client', 'rxjs', 'systemjs/dist', 'zone.js/dist'
];
return gulpMerge(
npmVendorFiles.map(root =>
gulp.src(path.join('node_modules', path.join(root, '**/*.+(js|js.map)')))
.pipe(gulp.dest(path.join('dist/vendor', root)))
));
});
/**
* Bundles systemjs files
*/
gulp.task(':test:system', () => {
gulp.src('test/bin/**.*')
.pipe(tsc())
.pipe(gulp.dest('dist/bin'));
});
/**
* Pre-test setup task
*/
gulp.task(':test:deps', (cb) => {
isTestRun = true;
gulpRunSequence(
'clean',
[
':test:system',
':test:vendor',
':test:build',
],
cb
);
});
/**
* Karma unit-testing
*/
gulp.task('test', [':test:deps'], (done) => {
new karma.Server({
configFile: path.join(process.cwd(), 'test/karma.conf.js')
}, done).start();
});