Skip to content
This repository was archived by the owner on Oct 12, 2021. It is now read-only.

Commit 1507011

Browse files
committed
chore(build): change the package layout to enable esm builds, and bump the package version
1 parent 0b0df9b commit 1507011

File tree

11 files changed

+188
-334
lines changed

11 files changed

+188
-334
lines changed

service-worker/worker/gulpfile.ts

Lines changed: 121 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ var exec = require('child_process').exec;
1515
var uglify = require('gulp-uglify');
1616
var rename = require('gulp-rename');
1717
var webpack = require('webpack');
18+
const childProcess = require('child_process');
19+
const rollup = require('rollup');
1820

1921
import AngularServiceWorkerPlugin from './src/webpack';
2022

@@ -41,19 +43,23 @@ var commonCompilerConfig = assign({},
4143
}
4244
);
4345

46+
var umdCompilerConfig = assign({},
47+
systemCompilerConfig,
48+
{
49+
"module": "umd"
50+
}
51+
);
52+
4453
gulp.task('default', ['worker:build']);
4554

4655
gulp.task('clean', (done) => {
47-
rimraf('./dist', done);
48-
});
49-
50-
gulp.task('clean:src', done => {
51-
rimraf('./dist/src', done);
56+
rimraf('./tmp', () => {
57+
rimraf('./dist', done);
58+
});
5259
});
5360

5461
gulp.task('prepublish', done => runSequence(
5562
'build',
56-
'clean:src',
5763
done
5864
));
5965

@@ -62,7 +68,8 @@ gulp.task('build', done => runSequence(
6268
[
6369
'task:companion:build',
6470
'task:webpack:build',
65-
'task:worker:build'
71+
'task:worker:build',
72+
'task:package:copy_deploy',
6673
],
6774
done
6875
));
@@ -76,19 +83,14 @@ gulp.task('companion:build', done => runSequence(
7683
'clean',
7784
'task:companion:build',
7885
done));
79-
80-
gulp.task('generator:build', done => runSequence(
81-
'clean',
82-
'task:generator:build',
83-
done));
8486

8587
gulp.task('task:webpack_test:pack', done => {
8688
console.log(process.cwd());
8789
webpack({
8890
context: `${process.cwd()}/src/test/webpack`,
8991
entry: './index.js',
9092
output: {
91-
path: `${process.cwd()}/dist/src/test/webpack`,
93+
path: `${process.cwd()}/tmp/src/test/webpack`,
9294
filename: 'index.js'
9395
},
9496
plugins: [
@@ -103,32 +105,87 @@ gulp.task('task:webpack:build', done => runSequence(
103105
done
104106
));
105107

106-
gulp.task('task:webpack:compile', () => gulp
107-
.src([
108-
'src/webpack/**/*.ts'
109-
], {
110-
base: 'src/webpack'
111-
})
112-
.pipe(ts(commonCompilerConfig))
113-
.pipe(gulp.dest('dist')));
108+
gulp.task('task:webpack:compile', done => {
109+
childProcess.execSync('node_modules/.bin/tsc -p tsconfig.webpack.json');
110+
done();
111+
});
114112

115113
gulp.task('task:webpack:copy_deploy', () => gulp
116114
.src([
117-
'dist/src/webpack/index.js'
115+
'tmp/es5/src/webpack/**/*.d.ts',
116+
'tmp/es5/src/webpack/**/*.js',
117+
'tmp/es5/src/webpack/**/*.js.map',
118118
], {
119-
base: 'dist/src/webpack'
119+
base: 'tmp/es5/src/webpack'
120120
})
121121
.pipe(gulp.dest('dist/webpack')));
122122

123123
gulp.task('task:companion:build', done => runSequence(
124-
'task:companion:compile',
124+
'task:companion:compile_esm',
125+
'task:companion:bundle',
126+
'task:companion:minify',
125127
'task:companion:copy_deploy',
126128
done));
127129

130+
gulp.task('task:companion:compile_esm', done => {
131+
childProcess.execSync('node_modules/.bin/ngc -p tsconfig.companion.json');
132+
done();
133+
});
134+
135+
gulp.task('task:companion:bundle', done => {
136+
rollup.rollup({
137+
entry: 'tmp/esm/src/companion/index.js',
138+
}).then(bundle => bundle.write({
139+
format: 'umd',
140+
moduleName: 'ng.serviceWorker',
141+
dest: 'tmp/es5/src/companion/bundles/service-worker.umd.js',
142+
globals: {
143+
'@angular/core': 'ng.core',
144+
'base64-js': 'Base64Js',
145+
'rxjs/add/observable/concat': 'Rx',
146+
'rxjs/add/observable/defer': 'Rx',
147+
'rxjs/add/observable/empty': 'Rx',
148+
'rxjs/add/observable/from': 'Rx',
149+
'rxjs/add/observable/fromEvent': 'Rx',
150+
'rxjs/add/observable/merge': 'Rx',
151+
'rxjs/add/observable/of': 'Rx',
152+
'rxjs/add/observable/timer': 'Rx',
153+
'rxjs/add/operator/cache': 'Rx',
154+
'rxjs/add/operator/concatMap': 'Rx',
155+
'rxjs/add/operator/do': 'Rx',
156+
'rxjs/add/operator/expand': 'Rx',
157+
'rxjs/add/operator/filter': 'Rx',
158+
'rxjs/add/operator/first': 'Rx',
159+
'rxjs/add/operator/let': 'Rx',
160+
'rxjs/add/operator/mergeMap': 'Rx',
161+
'rxjs/add/operator/map': 'Rx',
162+
'rxjs/add/operator/reduce': 'Rx',
163+
'rxjs/add/operator/switchMap': 'Rx',
164+
'rxjs/add/operator/publishReplay': 'Rx',
165+
'rxjs/add/operator/share': 'Rx',
166+
'rxjs/add/operator/take': 'Rx',
167+
'rxjs/add/operator/takeWhile': 'Rx',
168+
'rxjs/Observable': 'Rx'
169+
}
170+
}))
171+
.catch(err => console.log(err))
172+
.then(() => done());
173+
});
174+
175+
gulp.task('task:companion:minify', () => gulp
176+
.src([
177+
'tmp/es5/src/companion/bundles/service-worker.umd.js'
178+
], {base: 'tmp'})
179+
.pipe(uglify())
180+
.pipe(rename({suffix: '.min'}))
181+
.pipe(gulp.dest('tmp')));
182+
128183
gulp.task('task:worker:build', done =>
129184
runSequence(
130185
'task:worker:compile_system',
131186
'task:worker:bundle',
187+
'task:worker:minify',
188+
'task:worker:copy_deploy',
132189
done
133190
));
134191

@@ -162,33 +219,21 @@ gulp.task('task:worker:compile_common', () => {
162219
]);
163220
});
164221

165-
gulp.task('task:companion:compile', () => {
166-
const stream = gulp
167-
.src([
168-
'src/companion/**/*.ts',
169-
'src/typings/**/*.d.ts',
170-
'typings/globals/**/*.d.ts',
171-
'typings/modules/**/*.d.ts'
172-
])
173-
.pipe(ts(commonCompilerConfig));
174-
return merge([
175-
stream.js.pipe(gulp.dest(commonCompilerConfig.outDir)),
176-
stream.dts.pipe(gulp.dest(commonCompilerConfig.outDir))
177-
]);
178-
});
179-
180222
gulp.task('task:companion:copy_deploy', () => gulp
181223
.src([
182-
'dist/src/companion/**/*.js',
183-
'dist/src/companion/**/*.d.ts'
224+
'tmp/es5/src/companion/**/*.js',
225+
'tmp/esm/src/companion/**/*.d.ts',
226+
'tmp/esm/src/companion/**/*.js',
227+
'tmp/esm/src/companion/**/*.js.map',
228+
'tmp/esm/src/companion/**/*.metadata.json',
184229
])
185-
.pipe(gulp.dest('dist/companion')));
230+
.pipe(gulp.dest('dist')));
186231

187232
gulp.task('task:worker:bundle', done => {
188233
var builder = new Builder();
189234
builder.config({
190235
map: {
191-
'worker': 'dist/src/worker',
236+
'worker': 'tmp/es5/src/worker',
192237
'rxjs': 'node_modules/rxjs',
193238
'jshashes': 'node_modules/jshashes/hashes.js'
194239
},
@@ -202,37 +247,24 @@ gulp.task('task:worker:bundle', done => {
202247
}
203248
});
204249
builder
205-
.buildStatic('worker/browser_entry', 'dist/worker.js')
250+
.buildStatic('worker/browser_entry', 'tmp/es5/worker.js')
206251
.then(() => done());
207252
});
208253

209254
gulp.task('task:worker:minify', () => gulp
210255
.src([
211-
'dist/worker.js'
212-
], {base: 'dist'})
256+
'tmp/es5/worker.js'
257+
], {base: 'tmp/es5'})
213258
.pipe(uglify())
214259
.pipe(rename({suffix: '.min'}))
215-
.pipe(gulp.dest('dist')));
216-
217-
gulp.task('task:generator:build', done => runSequence(
218-
'task:generator:compile',
219-
'task:generator:copy_deploy',
220-
done));
260+
.pipe(gulp.dest('tmp/es5')));
221261

222-
gulp.task('task:generator:compile', () => gulp
262+
gulp.task('task:worker:copy_deploy', () => gulp
223263
.src([
224-
'src/generator/**.ts',
225-
'typings/globals/**/*.d.ts',
226-
'typings/modules/**/*.d.ts'
227-
])
228-
.pipe(ts(commonCompilerConfig))
229-
.pipe(gulp.dest('dist')));
230-
231-
gulp.task('task:generator:copy_deploy', () => gulp
232-
.src([
233-
'dist/src/generator/**/*.js'
234-
])
235-
.pipe(gulp.dest('dist/generator')));
264+
'tmp/es5/worker.js',
265+
'tmp/es5/worker.min.js',
266+
], {base: 'tmp/es5'})
267+
.pipe(gulp.dest('dist/worker')));
236268

237269
gulp.task('e2e_harness:build', done => runSequence(
238270
'clean',
@@ -269,22 +301,14 @@ gulp.task('task:e2e_harness:build_worker', done => runSequence(
269301
'task:e2e_harness:copy_worker',
270302
done));
271303

272-
gulp.task('task:e2e_harness:build_companion', done => runSequence(
273-
'task:companion:compile',
274-
[
275-
'task:e2e_harness:copy_companion',
276-
'task:companion:copy_deploy'
277-
],
278-
done));
279-
280304
gulp.task('task:e2e_harness:compile', () => gulp
281305
.src([,
282306
'src/test/e2e/harness/client/**/*.ts',
283307
'typings/globals/**/*.d.ts',
284308
'typings/modules/**/*.d.ts'
285309
], {base: '.'})
286310
.pipe(ts(systemCompilerConfig))
287-
.pipe(gulp.dest('dist')));
311+
.pipe(gulp.dest('tmp/es5')));
288312

289313
gulp.task('task:e2e_harness:copy_modules', () => gulp
290314
.src([
@@ -295,32 +319,35 @@ gulp.task('task:e2e_harness:copy_modules', () => gulp
295319
'node_modules/rxjs/**/*.js',
296320
'node_modules/base64-js/base64js.min.js'
297321
], {base: '.'})
298-
.pipe(gulp.dest('dist/src/test/e2e/harness/client')));
322+
.pipe(gulp.dest('tmp/es5/src/test/e2e/harness/client')));
299323

300324
gulp.task('task:e2e_harness:copy_debug', () => gulp
301325
.src([
302326
'src/test/e2e/harness/client/debug/**/*.*'
303327
], {base: 'src/test/e2e/harness/client/debug'})
304-
.pipe(gulp.dest('dist/src/test/e2e/harness/client')));
328+
.pipe(gulp.dest('tmp/es5/src/test/e2e/harness/client')));
305329

306330
gulp.task('task:e2e_harness:copy_companion', () => gulp
307331
.src([
308-
'dist/src/companion/**/*.js'
309-
], {base: 'dist/src'})
310-
.pipe(gulp.dest('dist/src/test/e2e/harness/client/node_modules/@angular/service-worker/dist')));
332+
'tmp/es5/src/companion/**/*.d.ts',
333+
'tmp/es5/src/companion/**/*.js',
334+
'tmp/es5/src/companion/**/*.metadata.json',
335+
'tmp/es5/src/companion/**/*.js.map'
336+
], {base: 'tmp/es5/src/companion'})
337+
.pipe(gulp.dest('tmp/es5/src/test/e2e/harness/client/node_modules/@angular/service-worker')));
311338

312339
gulp.task('task:e2e_harness:copy_worker', () => gulp
313340
.src([
314-
'dist/worker.js',
315-
], {base: 'dist'})
316-
.pipe(gulp.dest('dist/src/test/e2e/harness/client')));
341+
'tmp/es5/worker.js',
342+
], {base: 'tmp/es5'})
343+
.pipe(gulp.dest('tmp/es5/src/test/e2e/harness/client')));
317344

318345
gulp.task('task:e2e_harness:copy_index', () => gulp
319346
.src([
320347
'src/test/e2e/harness/client/index.html',
321348
'src/test/e2e/harness/client/manifest.webapp'
322349
], {base: '.'})
323-
.pipe(gulp.dest('dist')));
350+
.pipe(gulp.dest('tmp/es5')));
324351

325352
gulp.task('task:e2e_tests:build', done => runSequence([
326353
'task:e2e_tests:compile',
@@ -336,13 +363,13 @@ gulp.task('task:e2e_tests:compile', () => gulp
336363
'typings/modules/**/*.d.ts'
337364
], {base: '.'})
338365
.pipe(ts(commonCompilerConfig))
339-
.pipe(gulp.dest('dist')));
366+
.pipe(gulp.dest('tmp/es5')));
340367

341368
gulp.task('task:e2e_tests:copy_protractor', () => gulp
342369
.src([
343370
'src/test/e2e/spec/protractor.config.js'
344371
], {base: '.'})
345-
.pipe(gulp.dest('dist')));
372+
.pipe(gulp.dest('tmp/es5')));
346373

347374
gulp.task('task:unit_tests:compile', () => gulp
348375
.src([
@@ -353,7 +380,7 @@ gulp.task('task:unit_tests:compile', () => gulp
353380
'typings/modules/**/*.d.ts'
354381
], {base: '.'})
355382
.pipe(ts(commonCompilerConfig))
356-
.pipe(gulp.dest('dist')));
383+
.pipe(gulp.dest('tmp/es5')));
357384

358385
gulp.task('test', done => runSequence(
359386
'test:unit',
@@ -373,7 +400,7 @@ gulp.task('test:unit', done => runSequence(
373400

374401
gulp.task('task:unit_tests:run', () => gulp
375402
.src([
376-
'dist/**/*.spec.js'
403+
'tmp/**/*.spec.js'
377404
], {base: '.'})
378405
.pipe(jsmn({
379406
verbose: true,
@@ -400,9 +427,15 @@ gulp.task('task:e2e_tests:config_check', done => {
400427
});
401428

402429
gulp.task('task:e2e_tests:run', done => {
403-
exec('protractor dist/src/test/e2e/spec/protractor.config.js', (err, stdout, stderr) => {
430+
exec('protractor tmp/es5/src/test/e2e/spec/protractor.config.js', (err, stdout, stderr) => {
404431
console.log(stdout);
405432
console.log(stderr);
406433
done();
407434
});
408435
});
436+
437+
gulp.task('task:package:copy_deploy', () => gulp
438+
.src([
439+
'package.json'
440+
])
441+
.pipe(gulp.dest('dist')));

0 commit comments

Comments
 (0)