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

Commit ffea4ac

Browse files
committed
feat(worker): Support push notifications in the service worker, and add a companion library through which the application can access them.
1 parent 7f8825f commit ffea4ac

33 files changed

+895
-60
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ tmp
3030
# (NB: these lines are removed in publish-build-artifacts.sh)
3131
**/typings/**/*.d.ts
3232
**/typings/tsd.cached.json
33+
!/service-worker/worker/src/typings
3334

3435
# Include when developing application packages.
3536
pubspec.lock

service-worker/worker/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ build/
22
dist/
33
node_modules/
44
/typings
5+
/ngsw-config.json

service-worker/worker/.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ build/
22
node_modules/
33
typings/
44
dist/src/
5+
/ngsw-config.json

service-worker/worker/gulpfile.ts

+101-17
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ gulp.task('prepublish', ['build']);
4949
gulp.task('build', done => runSequence(
5050
'clean',
5151
[
52+
'task:companion:build',
5253
'task:generator:build',
5354
'task:worker:build'
5455
],
@@ -59,13 +60,21 @@ gulp.task('worker:build', done => runSequence(
5960
'clean',
6061
'task:worker:build',
6162
done));
63+
64+
gulp.task('companion:build', done => runSequence(
65+
'clean',
66+
'task:companion:build',
67+
done));
6268

6369
gulp.task('generator:build', done => runSequence(
6470
'clean',
6571
'task:generator:build',
66-
done
67-
));
72+
done));
6873

74+
gulp.task('task:companion:build', done => runSequence(
75+
'task:companion:compile',
76+
'task:companion:copy_deploy',
77+
done));
6978

7079
gulp.task('task:worker:build', done =>
7180
runSequence(
@@ -79,7 +88,8 @@ gulp.task('task:worker:compile_system', () => {
7988
.src([
8089
'src/worker/**/*.ts',
8190
'src/typings/**/*.d.ts',
82-
'typings/globals/**/*.d.ts'
91+
'typings/globals/**/*.d.ts',
92+
'typings/modules/**/*.d.ts'
8393
])
8494
.pipe(ts(systemCompilerConfig));
8595
return merge([
@@ -93,7 +103,23 @@ gulp.task('task:worker:compile_common', () => {
93103
.src([
94104
'src/worker/**/*.ts',
95105
'src/typings/**/*.d.ts',
96-
'typings/globals/**/*.d.ts'
106+
'typings/globals/**/*.d.ts',
107+
'typings/modules/**/*.d.ts'
108+
])
109+
.pipe(ts(commonCompilerConfig));
110+
return merge([
111+
stream.js.pipe(gulp.dest(commonCompilerConfig.outDir)),
112+
stream.dts.pipe(gulp.dest(commonCompilerConfig.outDir))
113+
]);
114+
});
115+
116+
gulp.task('task:companion:compile', () => {
117+
const stream = gulp
118+
.src([
119+
'src/companion/**/*.ts',
120+
'src/typings/**/*.d.ts',
121+
'typings/globals/**/*.d.ts',
122+
'typings/modules/**/*.d.ts'
97123
])
98124
.pipe(ts(commonCompilerConfig));
99125
return merge([
@@ -102,6 +128,13 @@ gulp.task('task:worker:compile_common', () => {
102128
]);
103129
});
104130

131+
gulp.task('task:companion:copy_deploy', () => gulp
132+
.src([
133+
'dist/src/companion/**/*.js',
134+
'dist/src/companion/**/*.d.ts'
135+
])
136+
.pipe(gulp.dest('dist/companion')));
137+
105138
gulp.task('task:worker:bundle', done => {
106139
var builder = new Builder();
107140
builder.config({
@@ -140,7 +173,8 @@ gulp.task('task:generator:build', done => runSequence(
140173
gulp.task('task:generator:compile', () => gulp
141174
.src([
142175
'src/generator/**.ts',
143-
'typings/globals/**/*.d.ts'
176+
'typings/globals/**/*.d.ts',
177+
'typings/modules/**/*.d.ts'
144178
])
145179
.pipe(ts(commonCompilerConfig))
146180
.pipe(gulp.dest('dist')));
@@ -154,26 +188,51 @@ gulp.task('task:generator:copy_deploy', () => gulp
154188
gulp.task('e2e_harness:build', done => runSequence(
155189
'clean',
156190
'task:e2e_harness:build',
157-
done
158-
));
191+
done));
192+
193+
gulp.task('e2e_harness:debug', done => runSequence(
194+
'clean',
195+
'task:e2e_harness:debug',
196+
done));
159197

160198
gulp.task('task:e2e_harness:build', done => runSequence([
161199
'task:e2e_harness:build_worker',
162-
'task:e2e_harness:compile',
163200
'task:e2e_harness:copy_modules',
164-
'task:e2e_harness:copy_index'
201+
'task:e2e_harness:copy_index',
202+
'task:e2e_harness:build_primary'
165203
], done));
166204

205+
gulp.task('task:e2e_harness:debug', done => runSequence([
206+
'task:e2e_harness:build',
207+
'task:e2e_harness:copy_debug'
208+
]));
209+
210+
gulp.task('task:e2e_harness:build_primary', done => runSequence(
211+
'task:companion:build',
212+
[
213+
'task:e2e_harness:compile',
214+
'task:e2e_harness:copy_companion'
215+
],
216+
done));
217+
167218
gulp.task('task:e2e_harness:build_worker', done => runSequence(
168219
'task:worker:build',
169220
'task:e2e_harness:copy_worker',
170-
done
171-
));
221+
done));
222+
223+
gulp.task('task:e2e_harness:build_companion', done => runSequence(
224+
'task:companion:compile',
225+
[
226+
'task:e2e_harness:copy_companion',
227+
'task:companion:copy_deploy'
228+
],
229+
done));
172230

173231
gulp.task('task:e2e_harness:compile', () => gulp
174232
.src([,
175233
'src/test/e2e/harness/client/**/*.ts',
176-
'typings/globals/**/*.d.ts'
234+
'typings/globals/**/*.d.ts',
235+
'typings/modules/**/*.d.ts'
177236
], {base: '.'})
178237
.pipe(ts(systemCompilerConfig))
179238
.pipe(gulp.dest('dist')));
@@ -184,11 +243,23 @@ gulp.task('task:e2e_harness:copy_modules', () => gulp
184243
'node_modules/systemjs/dist/system.js',
185244
'node_modules/reflect-metadata/Reflect.js',
186245
'node_modules/zone.js/dist/zone.js',
187-
'node_modules/rxjs/**/*.js'
246+
'node_modules/rxjs/**/*.js',
247+
'node_modules/base64-js/base64js.min.js'
188248
], {base: '.'})
189249
.pipe(gulp.dest('dist/src/test/e2e/harness/client')));
190250

191-
251+
gulp.task('task:e2e_harness:copy_debug', () => gulp
252+
.src([
253+
'src/test/e2e/harness/client/debug/**/*.*'
254+
], {base: 'src/test/e2e/harness/client/debug'})
255+
.pipe(gulp.dest('dist/src/test/e2e/harness/client')));
256+
257+
gulp.task('task:e2e_harness:copy_companion', () => gulp
258+
.src([
259+
'dist/src/companion/**/*.js'
260+
], {base: 'dist/src'})
261+
.pipe(gulp.dest('dist/src/test/e2e/harness/client/node_modules/@angular/service-worker/dist')));
262+
192263
gulp.task('task:e2e_harness:copy_worker', () => gulp
193264
.src([
194265
'dist/worker.js',
@@ -197,7 +268,8 @@ gulp.task('task:e2e_harness:copy_worker', () => gulp
197268

198269
gulp.task('task:e2e_harness:copy_index', () => gulp
199270
.src([
200-
'src/test/e2e/harness/client/index.html'
271+
'src/test/e2e/harness/client/index.html',
272+
'src/test/e2e/harness/client/manifest.webapp'
201273
], {base: '.'})
202274
.pipe(gulp.dest('dist')));
203275

@@ -211,7 +283,8 @@ gulp.task('task:e2e_tests:compile', () => gulp
211283
'src/test/e2e/spec/**/*.ts',
212284
'src/test/e2e/harness/server/**/*.ts',
213285
'src/typings/**/*.d.ts',
214-
'typings/globals/**/*.d.ts'
286+
'typings/globals/**/*.d.ts',
287+
'typings/modules/**/*.d.ts'
215288
], {base: '.'})
216289
.pipe(ts(commonCompilerConfig))
217290
.pipe(gulp.dest('dist')));
@@ -227,7 +300,8 @@ gulp.task('task:unit_tests:compile', () => gulp
227300
'src/test/unit/**/*.ts',
228301
'src/testing/**/*.ts',
229302
'src/typings/**/*.d.ts',
230-
'typings/globals/**/*.d.ts'
303+
'typings/globals/**/*.d.ts',
304+
'typings/modules/**/*.d.ts'
231305
], {base: '.'})
232306
.pipe(ts(commonCompilerConfig))
233307
.pipe(gulp.dest('dist')));
@@ -258,6 +332,7 @@ gulp.task('task:unit_tests:run', () => gulp
258332

259333
gulp.task('test:e2e', done => runSequence(
260334
'clean',
335+
'task:e2e_tests:config_check',
261336
[
262337
'task:e2e_tests:build',
263338
'task:e2e_harness:build',
@@ -266,6 +341,15 @@ gulp.task('test:e2e', done => runSequence(
266341
done
267342
));
268343

344+
gulp.task('task:e2e_tests:config_check', done => {
345+
fs.exists('./ngsw-config.json', (exists) => {
346+
if (!exists) {
347+
throw `ERROR: can't run e2e tests without a ngsw-config.json file`;
348+
}
349+
done();
350+
});
351+
});
352+
269353
gulp.task('task:e2e_tests:run', done => {
270354
exec('protractor dist/src/test/e2e/spec/protractor.config.js', (err, stdout, stderr) => {
271355
console.log(stdout);

service-worker/worker/package.json

+10-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@angular/service-worker",
33
"version": "0.2.0",
44
"description": "Experimental service worker by the Angular Mobile team",
5-
"main": "dist/generator/index.js",
5+
"main": "dist/companion/index.js",
66
"typings": "dist/src/worker.d.ts",
77
"scripts": {
88
"prepublish": "typings install && gulp prepublish",
@@ -20,11 +20,11 @@
2020
},
2121
"homepage": "https://github.com/angular/progressive#readme",
2222
"devDependencies": {
23-
"@angular/common": "^2.0.0-rc.1",
24-
"@angular/compiler": "^2.0.0-rc.1",
25-
"@angular/platform-browser": "^2.0.0-rc.1",
26-
"@angular/platform-browser-dynamic": "^2.0.0-rc.1",
27-
"es6-shim": "^0.33.13",
23+
"@angular/common": "^2.0.0-rc.4",
24+
"@angular/compiler": "^2.0.0-rc.4",
25+
"@angular/platform-browser": "^2.0.0-rc.4",
26+
"@angular/platform-browser-dynamic": "^2.0.0-rc.4",
27+
"es6-promise": "^3.0.2",
2828
"express": "^4.13.4",
2929
"gulp": "^3.9.0",
3030
"gulp-clean": "^0.3.1",
@@ -48,15 +48,14 @@
4848
"typescript": "1.9.0-dev.20160527-1.0",
4949
"typings": "^1.0.4",
5050
"vinyl": "^1.1.1",
51+
"web-push": "^2.1.1",
5152
"zone.js": "^0.6.5"
5253
},
5354
"dependencies": {
54-
"@angular/core": "^2.0.0-rc.1",
55+
"@angular/core": "^2.0.0-rc.4",
56+
"base64-js": "^1.1.2",
5557
"broccoli-caching-writer": "^2.2.1",
56-
"es6-promise": "^3.0.2",
57-
"es6-shim": "^0.35.0",
5858
"fs-extra": "^0.30.0",
59-
"jshashes": "^1.0.5",
60-
"vinyl": "^1.1.1"
59+
"jshashes": "^1.0.5"
6160
}
6261
}

0 commit comments

Comments
 (0)