Skip to content
This repository was archived by the owner on Oct 12, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
.DS_STORE

# Don’t commit the following directories created by pub.
packages
pubspec.lock
.pub
.packages

/dist/
.buildlog
node_modules
bower_components

# Or broccoli working directory
tmp

# Or the files created by dart2js.
*.dart.js
*.dart.precompiled.js
*.js_
*.js.deps
*.js.map

# Files created by the template compiler
**/*.ngfactory.ts
**/*.css.ts
**/*.css.shim.ts

# Or type definitions we mirror from github
# (NB: these lines are removed in publish-build-artifacts.sh)
**/typings/**/*.d.ts
**/typings/tsd.cached.json

# Include when developing application packages.
pubspec.lock
.c9
.idea/
.settings/
*.swo
.vscode

# Don't check in secret files
*secret.js

# Ignore npm debug log
npm-debug.log
3 changes: 1 addition & 2 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash
cd ./service-worker/worker
npm install
tsd install
tsc --version

46 changes: 29 additions & 17 deletions service-worker/worker/gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ var concat = require('gulp-concat');
let jsmn = require('gulp-jasmine');
var runSequence = require('run-sequence');
var process = require('process');
var merge = require('merge-stream');

var systemCompilerConfig = JSON.parse(fs.readFileSync('./tsconfig.json')).compilerOptions;
var commonCompilerConfig = JSON.parse(fs.readFileSync('./tsconfig.cjs.json')).compilerOptions;

commonCompilerConfig.typescript = require('typescript');
systemCompilerConfig.typescript = require('typescript');

gulp.task('default', ['build']);

Expand All @@ -32,27 +34,37 @@ gulp.task('prepublish', done => runSequence(
['!bundle', 'copy:generator'],
done));

gulp.task('!build:system', () => gulp
.src([
'src/**/*.ts',
'!src/**/*.spec.ts',
'typings/browser/**/*.d.ts'
])
.pipe(ts(systemCompilerConfig))
.pipe(gulp.dest('dist/src')));
gulp.task('!build:system', () => {
const stream = gulp
.src([
'src/**/*.ts',
'!src/**/*.spec.ts',
'typings/globals/**/*.d.ts'
])
.pipe(ts(systemCompilerConfig));
return merge([
stream.js.pipe(gulp.dest(systemCompilerConfig.outDir)),
stream.dts.pipe(gulp.dest(systemCompilerConfig.outDir))
]);
});

gulp.task('!build:commonjs', () => gulp
.src([
'src/**/*.ts',
'typings/browser/**/*.d.ts'
])
.pipe(ts(commonCompilerConfig))
.pipe(gulp.dest('dist/src')));
gulp.task('!build:commonjs', () => {
const stream = gulp
.src([
'src/**/*.ts',
'typings/globals/**/*.d.ts'
])
.pipe(ts(commonCompilerConfig));
return merge([
stream.js.pipe(gulp.dest(commonCompilerConfig.outDir)),
stream.dts.pipe(gulp.dest(commonCompilerConfig.outDir))
]);
});

gulp.task('build:generator', () => gulp
.src([
'src/generator/**.ts',
'typings/main/**/*.d.ts'
'typings/globals/**/*.d.ts'
])
.pipe(ts(commonCompilerConfig))
.pipe(gulp.dest('dist/src/generator')));
Expand All @@ -71,7 +83,7 @@ gulp.task('build:test', (done) => runSequence(

gulp.task('test', ['build:test'], () => gulp
.src([
'dist/src/**/*.spec.js'
'dist/**/*.spec.js'
], {base: '.'})
.pipe(jsmn({
verbose: true,
Expand Down
10 changes: 6 additions & 4 deletions service-worker/worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"version": "0.2.0",
"description": "Experimental service worker by the Angular Mobile team",
"main": "dist/generator/index.js",
"typings": "dist/src/worker.d.ts",
"scripts": {
"prepublish": "gulp prepublish",
"prepublish": "typings install && gulp prepublish",
"build": "gulp build && gulp build:generator",
"test": "gulp test"
},
Expand All @@ -28,15 +29,16 @@
"gulp-typescript": "^2.12.1",
"gulp-util": "^3.0.7",
"jasmine": "^2.4.1",
"merge-stream": "^1.0.0",
"reflect-metadata": "0.1.2",
"rimraf": "^2.5.2",
"run-sequence": "^1.1.5",
"rxjs": "5.0.0-beta.6",
"systemjs": "^0.19.17",
"systemjs-builder": "^0.15.5",
"ts-node": "^0.5.5",
"tsd": "^0.6.5",
"typescript": "^1.8.9",
"ts-node": "^0.7.3",
"typescript": "1.9.0-dev.20160527-1.0",
"typings": "^1.0.4",
"vinyl": "^1.1.1",
"zone.js": "^0.6.5"
},
Expand Down
2 changes: 1 addition & 1 deletion service-worker/worker/src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class CacheManager {
}

load(cache: string, req: string | Request): Observable<Response> {
return Observable.defer(() => Observable.fromPromise(this
return <Observable<Response>>Observable.defer(() => Observable.fromPromise(this
.caches
.open(cache)
.then(cache => cache.match(this.normalize(req)))));
Expand Down
24 changes: 8 additions & 16 deletions service-worker/worker/src/generator/cli-sw.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
declare var require;
declare var module;


import {ManifestWriter, SourceResolver} from './generator';


declare class Promise<T> {
constructor(fn: Function);
static all<T>(promises: Promise<T>[]): Promise<T[]>;
static resolve<T>(val: T): Promise<T>;
then<V>(fn: (T) => V | Promise<V>): Promise<V>;
}

const fse = require('fs-extra');
const path = require('path');
const BroccoliPlugin:BroccoliPluginConstructor = require('broccoli-caching-writer');;
const MANIFEST_NAME = 'ngsw-manifest.json';
const WORKER_NAME = 'worker.js';
const WORKER_NAME = 'worker.js';
export const BroccoliPlugin: BroccoliPluginConstructor = require('broccoli-caching-writer');

interface BroccoliPluginConstructor {
new(inputNodes:any[], options?:any): BroccoliPluginConstructor
inputPaths: string[];
outputPath: string;
export interface BroccoliPluginConstructor {
new(inputNodes: any[], options?: any): BroccoliPluginConstructor;
inputPaths: string[];
outputPath: string;
}

class BroccoliSourceResolver implements SourceResolver {
Expand All @@ -35,7 +26,7 @@ class BroccoliSourceResolver implements SourceResolver {
}

export class ServiceWorkerPlugin extends BroccoliPlugin {
constructor(inputNodes:any, options?:any) {
constructor(inputNodes: any, options?: any) {
super([inputNodes]);
}

Expand Down Expand Up @@ -79,3 +70,4 @@ function recursiveReaddirSync(src) {
})
return files;
}

20 changes: 7 additions & 13 deletions service-worker/worker/src/generator/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ let File = require('vinyl');

let sha1 = new SHA1();

declare class Promise<T> {
constructor(fn: Function);
static all<T>(promises: Promise<T>[]): Promise<T[]>;
then<V>(fn: (T) => V | Promise<V>, errFn?: any): Promise<V>;
}

declare class Buffer {
constructor(data: string);
}
Expand Down Expand Up @@ -72,9 +66,9 @@ export function gulpGenManifest(manifest: Manifest, base?: string): any {
}

export class ManifestWriter {

constructor(private resolver: SourceResolver) {}

processRoute(out: any, route: Route): void {
if (!out.routing.hasOwnPropert('route')) {
out.routing.route = {};
Expand All @@ -83,7 +77,7 @@ export class ManifestWriter {
prefix: route.prefix
};
}

processGroup(out: any, group: Group): Promise<any> {
if (!out.group.hasOwnProperty(group.name)) {
out.group[group.name] = {
Expand All @@ -104,7 +98,7 @@ export class ManifestWriter {
})
);
}

process(manifest: Manifest, base?: string): Promise<string> {
let baseObj = base ? JSON.parse(base) : '';
let out = <any>{
Expand All @@ -113,11 +107,11 @@ export class ManifestWriter {
index: '/index.html'
}
};

if (!!manifest.routing && !!manifest.routing.index) {
out.routing.index = manifest.routing.index;
}

if (!!manifest.routing && !!manifest.routing.routes) {
manifest.routing.routes.forEach(route => this.processRoute(out, route));
}
Expand All @@ -128,7 +122,7 @@ export class ManifestWriter {
.then(() => _mergeObjects(baseObj, out))
.then(() => out);
}

generate(manifest: Manifest, base?: string): Promise<string> {
return this
.process(manifest, base)
Expand Down
1 change: 1 addition & 0 deletions service-worker/worker/src/generator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ declare var module;

export * from './cli-sw';
export * from './generator';

8 changes: 4 additions & 4 deletions service-worker/worker/src/manifest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import {stringStartsWith} from './builtins';
import {SHA1} from 'jshashes';

Expand Down Expand Up @@ -57,7 +56,7 @@ export interface CacheEntryMap {
export interface CacheEntry {
url: string;
group: CacheGroup;

hash?: string;
}

Expand Down Expand Up @@ -101,12 +100,12 @@ export function diffManifests(current: string, previous: string): ManifestDelta
return delta;
}
delta.previous = parseManifest(previous);

let groups = _mergeKeys(
delta.current.group,
delta.previous.group
);

groups.forEach(name => {
let prevGroup = _groupOrEmpty(delta.previous, name);
let currGroup = _groupOrEmpty(delta.current, name);
Expand Down Expand Up @@ -178,3 +177,4 @@ function postProcessGroup(group: CacheGroup) {
.join(':'));
}
}

30 changes: 30 additions & 0 deletions service-worker/worker/src/manual_typings/service-worker.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/// <reference path="../../typings/globals/whatwg-fetch/index.d.ts" />
/// <reference path="../../typings/globals/es6-promise/index.d.ts" />

declare class ServiceWorkerContext {
}

declare interface Cache {
add(request: Request): Promise<void>;
addAll(requests: Request[]): Promise<void>;
delete(request: Request, options?: CacheOptions): Promise<void>;
keys(request?: Request, options?: CacheOptions): Promise<Request[]>;
match(request: Request, options?: CacheOptions): Promise<Response>;
matchAll(request: Request, options?: CacheOptions): Promise<Response[]>;
put(request: Request, response: Response): Promise<void>;
}

declare interface CacheStorage {
delete(cacheName: string): Promise<boolean>;
has(cacheName: string): Promise<boolean>;
keys(): Promise<string[]>;
match(request: Request, options?: CacheOptions): Promise<Response>;
open(cacheName: string): Promise<Cache>;
}

declare interface CacheOptions {
ignoreSearch?: boolean;
ignoreMethod?: boolean;
ignoreVary?: boolean;
cacheName?: string;
}
6 changes: 3 additions & 3 deletions service-worker/worker/src/testing/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class TestWorkerDriver {
scope: TestWorkerScope;
caches: MockCacheStorage = new MockCacheStorage();
lifecycle: Promise<any> = Promise.resolve(null);

constructor(private createWorker: TestWorkerCreationFn) {
this.refresh();
}
Expand All @@ -128,12 +128,12 @@ export class TestWorkerDriver {

refresh(): void {
this.scope = new TestWorkerScope(this.caches);

let workerAdapter = new TestAdapter();
let cache = new CacheManager(this.scope, workerAdapter);
let fetch = new Fetch(this.scope, workerAdapter);
let events = new Events(this.scope);

this.instance = this.createWorker(this.scope, workerAdapter, cache, fetch, events);
}

Expand Down
Loading