From ad36aa987d96049b5e53e8059fe524d88755d049 Mon Sep 17 00:00:00 2001 From: Alex Rickabaugh Date: Thu, 22 Sep 2016 10:21:48 -0700 Subject: [PATCH] refactor(app-shell): redo project layout, build system, test runner, package layout, and exports Also moves shell-parser to an experimental directory until it can be updated. --- app-shell/angular-cli-build.js | 22 ---- app-shell/angular-cli.json | 25 ---- app-shell/config/karma-test-shim.js | 52 --------- app-shell/config/karma.conf.js | 52 --------- app-shell/gulpfile.ts | 110 ++++++++++++++++++ app-shell/package.json | 89 +++++++------- app-shell/public/.gitignore | 0 app-shell/public/.npmignore | 0 app-shell/src/app/index.ts | 31 +---- app-shell/src/app/is-prerender.service.ts | 17 --- app-shell/src/app/module.ts | 29 +++++ app-shell/src/app/prerender.spec.ts | 20 ++++ app-shell/src/app/prerender.ts | 3 + app-shell/src/app/shared/index.ts | 0 .../src/app/shell-no-render.directive.spec.ts | 62 ---------- .../src/app/shell-no-render.directive.ts | 20 ---- .../src/app/shell-render.directive.spec.ts | 64 ---------- app-shell/src/app/shell-render.directive.ts | 22 ---- app-shell/src/app/shell.spec.ts | 70 +++++++++++ app-shell/src/app/shell.ts | 39 +++++++ .../shell-parser/ast/ast-node.ts | 0 .../shell-parser/ast/index.ts | 0 .../shell-parser/config.ts | 0 .../shell-parser/context.ts | 0 .../shell-parser/index.ts | 0 .../node-matcher/css-node-matcher.spec.ts | 0 .../node-matcher/css-node-matcher.ts | 0 .../css-selector/css-selector.spec.ts | 0 .../node-matcher/css-selector/css-selector.ts | 0 .../node-matcher/css-selector/index.ts | 0 .../shell-parser/node-matcher/index.ts | 0 .../shell-parser/node-matcher/node-matcher.ts | 0 .../shell-parser/node-visitor/index.ts | 0 .../shell-parser/node-visitor/node-visitor.ts | 0 .../node-visitor/resource-inline/index.ts | 0 ...line-style-resource-inline-visitor.spec.ts | 0 .../inline-style-resource-inline-visitor.ts | 0 .../resource-inline-visitor.ts | 0 ...stylesheet-resource-inline-visitor.spec.ts | 0 .../stylesheet-resource-inline-visitor.ts | 0 .../template-strip-visitor.spec.ts | 0 .../node-visitor/template-strip-visitor.ts | 0 .../shell-parser/shell-parser-factory.ts | 0 .../shell-parser/shell-parser.spec.ts | 0 .../shell-parser/shell-parser.ts | 0 .../shell-parser/template-parser/index.ts | 0 .../parse5/drop-named-entities-patch.spec.ts | 0 .../parse5/drop-named-entities-patch.ts | 0 .../parse5/parse5-template-parser.spec.ts | 0 .../parse5/parse5-template-parser.ts | 0 .../tokenizer-case-sensitivity-patch.spec.ts | 0 .../tokenizer-case-sensitivity-patch.ts | 0 .../template-parser/template-parser.ts | 0 .../shell-parser/testing/context-mock.ts | 0 .../shell-parser/testing/index.ts | 0 .../shell-parser/testing/mock-caches.ts | 0 .../shell-parser/testing/mock-requests.ts | 0 app-shell/src/index.html | 0 app-shell/src/index.ts | 1 + .../src/manual_typings/service-worker.d.ts | 29 ----- app-shell/src/package.json | 33 ------ app-shell/src/system-config.ts | 66 ----------- app-shell/src/tsconfig.json | 21 ---- app-shell/src/typings.d.ts | 3 - app-shell/src/unit_tests.ts | 19 +++ .../tsconfig.es5.json | 26 ++--- ...sconfig.publish.json => tsconfig.esm.json} | 21 ++-- app-shell/tsconfig.json | 18 +++ app-shell/typings.json | 13 --- test.sh | 3 +- 70 files changed, 379 insertions(+), 601 deletions(-) delete mode 100644 app-shell/angular-cli-build.js delete mode 100644 app-shell/angular-cli.json delete mode 100644 app-shell/config/karma-test-shim.js delete mode 100644 app-shell/config/karma.conf.js create mode 100644 app-shell/gulpfile.ts delete mode 100644 app-shell/public/.gitignore delete mode 100644 app-shell/public/.npmignore delete mode 100644 app-shell/src/app/is-prerender.service.ts create mode 100644 app-shell/src/app/module.ts create mode 100644 app-shell/src/app/prerender.spec.ts create mode 100644 app-shell/src/app/prerender.ts delete mode 100644 app-shell/src/app/shared/index.ts delete mode 100644 app-shell/src/app/shell-no-render.directive.spec.ts delete mode 100644 app-shell/src/app/shell-no-render.directive.ts delete mode 100644 app-shell/src/app/shell-render.directive.spec.ts delete mode 100644 app-shell/src/app/shell-render.directive.ts create mode 100644 app-shell/src/app/shell.spec.ts create mode 100644 app-shell/src/app/shell.ts rename app-shell/src/{app => experimental}/shell-parser/ast/ast-node.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/ast/index.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/config.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/context.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/index.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/node-matcher/css-node-matcher.spec.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/node-matcher/css-node-matcher.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/node-matcher/css-selector/css-selector.spec.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/node-matcher/css-selector/css-selector.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/node-matcher/css-selector/index.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/node-matcher/index.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/node-matcher/node-matcher.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/node-visitor/index.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/node-visitor/node-visitor.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/node-visitor/resource-inline/index.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/node-visitor/resource-inline/inline-style-resource-inline-visitor.spec.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/node-visitor/resource-inline/inline-style-resource-inline-visitor.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/node-visitor/resource-inline/resource-inline-visitor.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/node-visitor/resource-inline/stylesheet-resource-inline-visitor.spec.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/node-visitor/resource-inline/stylesheet-resource-inline-visitor.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/node-visitor/template-strip-visitor.spec.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/node-visitor/template-strip-visitor.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/shell-parser-factory.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/shell-parser.spec.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/shell-parser.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/template-parser/index.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/template-parser/parse5/drop-named-entities-patch.spec.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/template-parser/parse5/drop-named-entities-patch.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/template-parser/parse5/parse5-template-parser.spec.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/template-parser/parse5/parse5-template-parser.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/template-parser/parse5/tokenizer-case-sensitivity-patch.spec.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/template-parser/parse5/tokenizer-case-sensitivity-patch.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/template-parser/template-parser.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/testing/context-mock.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/testing/index.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/testing/mock-caches.ts (100%) rename app-shell/src/{app => experimental}/shell-parser/testing/mock-requests.ts (100%) delete mode 100644 app-shell/src/index.html create mode 100644 app-shell/src/index.ts delete mode 100644 app-shell/src/manual_typings/service-worker.d.ts delete mode 100644 app-shell/src/package.json delete mode 100644 app-shell/src/system-config.ts delete mode 100644 app-shell/src/tsconfig.json delete mode 100644 app-shell/src/typings.d.ts create mode 100644 app-shell/src/unit_tests.ts rename hello-mobile/src/tsconfig.json => app-shell/tsconfig.es5.json (55%) rename app-shell/{src/tsconfig.publish.json => tsconfig.esm.json} (68%) create mode 100644 app-shell/tsconfig.json delete mode 100644 app-shell/typings.json diff --git a/app-shell/angular-cli-build.js b/app-shell/angular-cli-build.js deleted file mode 100644 index 9774f5e..0000000 --- a/app-shell/angular-cli-build.js +++ /dev/null @@ -1,22 +0,0 @@ -/* global require, module */ - -var Angular2App = require('angular-cli/lib/broccoli/angular2-app'); - -module.exports = function(defaults) { - return new Angular2App(defaults, { - vendorNpmFiles: [ - 'systemjs/dist/system-polyfills.js', - 'systemjs/dist/system.src.js', - 'zone.js/dist/*.js', - 'es6-shim/es6-shim.js', - 'reflect-metadata/*.js', - 'reflect-metadata/*.map', - 'rxjs/**/*.js', - 'rxjs/**/*.map', - '@angular/**/*.js', - '@angular/**/*.map', - 'parse5/**/*.js', - 'traceur/**/*.js' - ] - }); -}; diff --git a/app-shell/angular-cli.json b/app-shell/angular-cli.json deleted file mode 100644 index ad01350..0000000 --- a/app-shell/angular-cli.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "project": { - "version": "0.0.35", - "name": "app-shell" - }, - "apps": [ - {"main": "src/main.ts", "tsconfig": "src/tsconfig.json"} - ], - "addons": [], - "packages": [], - "e2e": { - "protractor": { - "config": "config/protractor.conf.js" - } - }, - "test": { - "karma": { - "config": "config/karma.conf.js" - } - }, - "defaults": { - "prefix": "app", - "sourceDir": "src" - } -} diff --git a/app-shell/config/karma-test-shim.js b/app-shell/config/karma-test-shim.js deleted file mode 100644 index 3022d26..0000000 --- a/app-shell/config/karma-test-shim.js +++ /dev/null @@ -1,52 +0,0 @@ -/*global jasmine, __karma__, window*/ -Error.stackTraceLimit = Infinity; -jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000; - -__karma__.loaded = function () { -}; - -var distPath = '/base/dist/'; -var appPath = distPath + 'app/'; - -function isJsFile(path) { - return path.slice(-3) == '.js'; -} - -function isSpecFile(path) { - return path.slice(-8) == '.spec.js'; -} - -function isAppFile(path) { - return isJsFile(path) && (path.substr(0, appPath.length) == appPath); -} - -var allSpecFiles = Object.keys(window.__karma__.files) - .filter(isSpecFile) - .filter(isAppFile); - -// Load our SystemJS configuration. -System.config({ - baseURL: distPath -}); - -System.import('system-config.js').then(function() { - // Load and configure the TestComponentBuilder. - return Promise.all([ - System.import('@angular/core/testing'), - System.import('@angular/platform-browser-dynamic/testing') - ]).then(function (providers) { - var TestBed = providers[0].TestBed; - var testingBrowser = providers[1]; - TestBed.initTestEnvironment( - testingBrowser.BrowserDynamicTestingModule, - testingBrowser.platformBrowserDynamicTesting() - ); - }); -}).then(function() { - // Finally, load all spec files. - // This will run the tests directly. - return Promise.all( - allSpecFiles.map(function (moduleName) { - return System.import(moduleName); - })); -}).then(__karma__.start, __karma__.error); \ No newline at end of file diff --git a/app-shell/config/karma.conf.js b/app-shell/config/karma.conf.js deleted file mode 100644 index 0c42cbe..0000000 --- a/app-shell/config/karma.conf.js +++ /dev/null @@ -1,52 +0,0 @@ -module.exports = function (config) { - config.set({ - basePath: '..', - frameworks: ['jasmine'], - plugins: [ - require('karma-jasmine'), - require('karma-chrome-launcher') - ], - customLaunchers: { - // chrome setup for travis CI using chromium - Chrome_travis_ci: { - base: 'Chrome', - flags: ['--no-sandbox'] - } - }, - files: [ - { pattern: 'dist/vendor/es6-shim/es6-shim.js', included: true, watched: false }, - - { pattern: 'dist/vendor/zone.js/dist/zone.js', included: true, watched: false }, - { pattern: 'dist/vendor/zone.js/dist/proxy.js', included: true, watched: false }, - { pattern: 'dist/vendor/zone.js/dist/sync-test.js', included: true, watched: false }, - { pattern: 'dist/vendor/zone.js/dist/jasmine-patch.js', included: true, watched: false }, - { pattern: 'dist/vendor/zone.js/dist/async-test.js', included: true, watched: false }, - { pattern: 'dist/vendor/zone.js/dist/fake-async-test.js', included: true, watched: false }, - - { pattern: 'dist/vendor/reflect-metadata/Reflect.js', included: true, watched: false }, - { pattern: 'dist/vendor/systemjs/dist/system-polyfills.js', included: true, watched: false }, - { pattern: 'dist/vendor/systemjs/dist/system.src.js', included: true, watched: false }, - - { pattern: 'config/karma-test-shim.js', included: true, watched: true }, - - // Distribution folder. - { pattern: 'dist/**/*', included: false, watched: true } - ], - exclude: [ - // Vendor packages might include spec files. We don't want to use those. - 'dist/vendor/**/*.spec.js' - ], - preprocessors: {}, - reporters: ['progress'], - port: 9876, - colors: true, - logLevel: config.LOG_INFO, - autoWatch: true, - browsers: ['Chrome'], - singleRun: false - }); - if (process.env.TRAVIS || process.env.CIRCLECI) { - config.browsers = ['Chrome_travis_ci']; - config.singleRun = true; - } -}; diff --git a/app-shell/gulpfile.ts b/app-shell/gulpfile.ts new file mode 100644 index 0000000..22ab223 --- /dev/null +++ b/app-shell/gulpfile.ts @@ -0,0 +1,110 @@ +declare var require; + +const childProcess = require('child_process'); +const commonjs = require('rollup-plugin-commonjs'); +const gulp = require('gulp'); +const jsmn = require('gulp-jasmine'); +const rimraf = require('rimraf'); +const rollup = require('rollup'); +const nodeResolve = require('rollup-plugin-node-resolve'); +const runSequence = require('run-sequence'); + + +gulp.task('clean', done => { + rimraf('./tmp', () => { + rimraf('./dist', done); + }); +}); + +gulp.task('build', done => runSequence( + 'clean', + 'task:build', + 'task:deploy', + done)); + +gulp.task('test', done => runSequence( + 'clean', + 'task:test', + done)); + +gulp.task('task:build', done => runSequence( + 'task:app:compile_esm', + 'task:app:bundle', + done)); + +gulp.task('task:test', done => runSequence( + 'task:app:compile_es5', + 'task:app:test', + done)) + +gulp.task('task:deploy', done => runSequence( + [ + 'task:app:deploy', + 'task:bundles:deploy', + 'task:package:deploy', + ], + done)); + +gulp.task('task:app:compile_es5', () => { + childProcess.execSync('node_modules/.bin/tsc -p tsconfig.es5.json'); +}); + +gulp.task('task:app:compile_esm', () => { + childProcess.execSync('node_modules/.bin/ngc -p tsconfig.esm.json'); +}); + +gulp.task('task:app:bundle', done => rollup + .rollup({ + entry: 'tmp/esm/src/index.js', + plugins: [ + nodeResolve({jsnext: true, main: true}), + commonjs({ + include: 'node_modules/**', + }), + ], + external: [ + '@angular/core', + ] + }) + .then(bundle => bundle.write({ + format: 'umd', + moduleName: 'ng.appShell', + dest: 'tmp/es5/bundles/app-shell.umd.js', + globals: { + '@angular/core': 'ng.core', + }, + }))); + +gulp.task('task:app:deploy', () => gulp + .src([ + 'tmp/esm/src/index.d.ts', + 'tmp/esm/src/index.js', + 'tmp/esm/src/index.js.map', + 'tmp/esm/src/index.metadata.json', + 'tmp/esm/src/app/**/*.d.ts', + 'tmp/esm/src/app/**/*.js', + 'tmp/esm/src/app/**/*.js.map', + 'tmp/esm/src/app/**/*.metadata.json', + ], {base: 'tmp/esm/src'}) + .pipe(gulp.dest('dist'))); + +gulp.task('task:app:test', () => gulp + .src([ + 'tmp/es5/src/unit_tests.js', + ], {base: '.'}) + .pipe(jsmn({ + verbose: true, + }))); + +gulp.task('task:bundles:deploy', () => gulp + .src([ + 'tmp/es5/bundles/**/*.js', + 'tmp/es5/bundles/**/*.js.map', + ], {base: 'tmp/es5'}) + .pipe(gulp.dest('dist'))); + +gulp.task('task:package:deploy', () => gulp + .src([ + 'package.json' + ]) + .pipe(gulp.dest('dist'))); diff --git a/app-shell/package.json b/app-shell/package.json index 511cfdd..3528d9c 100644 --- a/app-shell/package.json +++ b/app-shell/package.json @@ -1,51 +1,52 @@ { - "name": "app-shell", - "version": "0.0.0", + "name": "@angular/app-shell", + "description": "App Shell runtime library for Angular 2 Progressive Web Apps.", + "version": "0.1.0", + "repository": { + "type": "git", + "url": "git+https://github.com/angular/mobile-toolkit.git" + }, + "contributors": [ + "Jeff Cross ", + "Minko Gechev ", + "Alex Rickabaugh " + ], + "keywords": [ + "angular2", + "pwa", + "progressive web apps", + "app shell" + ], "license": "MIT", "angular-cli": {}, - "scripts": { - "start": "ng server", - "postinstall": "typings install", - "lint": "tslint \"src/**/*.ts\"", - "format": "clang-format -i -style=file --glob=src/**/*.ts", - "pree2e": "webdriver-manager update", - "e2e": "protractor", - "clean": "rm -rf dist", - "build": "mkdir -p dist/app && ngc -p src/tsconfig.publish.json && cp src/package.json dist/app/package.json", - "build_parser": "echo '' > dist/vendor/parse5/lib/tokenizer/named_entity_trie.js && browserify dist/app/shell-parser/index.js -s shellParserFactory > dist/app/shell-parser.js && rm -rf dist/app/shell-parser && rm -rf dist/app/vendor", - "build_publish": "npm run clean && npm run build" - }, + "scripts": {}, + "main": "bundles/app-shell.umd.js", + "module": "index.js", "private": true, - "dependencies": { - "@angular/common": "^2.0.0-rc.6", - "@angular/compiler": "^2.0.0-rc.6", - "@angular/core": "^2.0.0-rc.6", - "@angular/platform-browser": "^2.0.0-rc.6", - "@angular/platform-browser-dynamic": "^2.0.0-rc.6", - "es6-shim": "^0.35.0", - "reflect-metadata": "0.1.3", - "rxjs": "5.0.0-beta.11", - "systemjs": "0.19.26", - "zone.js": "^0.6.17" - }, + "dependencies": {}, "devDependencies": { - "@angular/compiler-cli": "^0.6.0", - "@angular/platform-server": "^2.0.0-rc.6", - "angular-cli": "0.0.*", - "browserify": "^13.0.1", - "clang-format": "^1.0.35", - "codelyzer": "0.0.14", - "ember-cli-inject-live-reload": "^1.4.0", - "jasmine-core": "^2.4.1", - "jasmine-spec-reporter": "^2.4.0", - "karma": "^0.13.15", - "karma-chrome-launcher": "^0.2.3", - "karma-jasmine": "^0.3.8", - "parse5": "2.1.5", - "protractor": "^3.3.0", - "ts-node": "^0.5.5", - "tslint": "^3.6.0", - "typescript": "^2.0.2", - "typings": "^1.0.4" + "@angular/common": "^2.0.0", + "@angular/compiler": "^2.0.0", + "@angular/compiler-cli": "^0.6.2", + "@angular/core": "^2.0.0", + "@angular/platform-browser": "^2.0.0", + "@angular/platform-browser-dynamic": "^2.0.0", + "@angular/platform-server": "^2.0.0", + "@types/jasmine": "^2.2.34", + "gulp": "^3.9.1", + "gulp-jasmine": "^2.4.1", + "reflect-metadata": "^0.1.8", + "rimraf": "^2.5.4", + "rollup": "^0.36.0", + "rollup-plugin-commonjs": "^5.0.4", + "rollup-plugin-node-resolve": "^2.0.0", + "run-sequence": "^1.2.2", + "rxjs": "^5.0.0-beta.12", + "ts-node": "^1.3.0", + "typescript": "^2.0.3", + "zone.js": "^0.6.25" + }, + "peerDependencies": { + "@angular/core": "^2.0.0" } } diff --git a/app-shell/public/.gitignore b/app-shell/public/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git a/app-shell/public/.npmignore b/app-shell/public/.npmignore deleted file mode 100644 index e69de29..0000000 diff --git a/app-shell/src/app/index.ts b/app-shell/src/app/index.ts index 741a1b0..d9c2768 100644 --- a/app-shell/src/app/index.ts +++ b/app-shell/src/app/index.ts @@ -1,28 +1,3 @@ -import { Type, NgModule, ModuleWithProviders } from '@angular/core'; -import { ShellRender } from './shell-render.directive'; -import { ShellNoRender } from './shell-no-render.directive'; -import { IS_PRERENDER } from './is-prerender.service'; -import { APP_SHELL_RUNTIME_PROVIDERS, APP_SHELL_BUILD_PROVIDERS } from './is-prerender.service'; - -export * from './is-prerender.service'; -export * from './shell-no-render.directive'; -export * from './shell-render.directive'; - -const APP_SHELL_DIRECTIVES: Type[] = [ - ShellRender, - ShellNoRender -]; - -@NgModule({ - exports: APP_SHELL_DIRECTIVES, - declarations: APP_SHELL_DIRECTIVES -}) -export class AppShellModule { - static forRoot(): ModuleWithProviders { - return { - ngModule: AppShellModule, - providers: [APP_SHELL_RUNTIME_PROVIDERS, APP_SHELL_BUILD_PROVIDERS] - }; - } -} - +export * from './module'; +export * from './prerender'; +export * from './shell'; diff --git a/app-shell/src/app/is-prerender.service.ts b/app-shell/src/app/is-prerender.service.ts deleted file mode 100644 index 3599417..0000000 --- a/app-shell/src/app/is-prerender.service.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { OpaqueToken, Provider } from '@angular/core'; - -export const IS_PRERENDER = new OpaqueToken('IsPrerender'); - -export const APP_SHELL_RUNTIME_PROVIDERS: Provider[] = [ - { - provide: IS_PRERENDER, - useValue: false - } -]; - -export const APP_SHELL_BUILD_PROVIDERS: Provider[] = [ - { - provide: IS_PRERENDER, - useValue: true - } -]; diff --git a/app-shell/src/app/module.ts b/app-shell/src/app/module.ts new file mode 100644 index 0000000..a66f23c --- /dev/null +++ b/app-shell/src/app/module.ts @@ -0,0 +1,29 @@ +import {ModuleWithProviders, NgModule} from '@angular/core'; +import {IS_PRERENDER} from './prerender'; +import {ShellNoRender, ShellRender} from './shell'; + +@NgModule({ + declarations: [ + ShellNoRender, + ShellRender, + ], + exports: [ + ShellNoRender, + ShellRender, + ], +}) +export class AppShellModule { + static prerender(): ModuleWithProviders { + return { + ngModule: AppShellModule, + providers: [{provide: IS_PRERENDER, useValue: true}] + } + } + + static runtime(): ModuleWithProviders { + return { + ngModule: AppShellModule, + providers: [{provide: IS_PRERENDER, useValue: false}], + }; + } +} diff --git a/app-shell/src/app/prerender.spec.ts b/app-shell/src/app/prerender.spec.ts new file mode 100644 index 0000000..6131f6c --- /dev/null +++ b/app-shell/src/app/prerender.spec.ts @@ -0,0 +1,20 @@ +import {inject, TestBed} from '@angular/core/testing'; +import {IS_PRERENDER} from './prerender'; +import {AppShellModule} from './module'; + +export default function () { + describe('IS_PRERENDER', () => { + it('should be true at prerender time', () => { + const prerender = TestBed + .configureTestingModule({imports: [AppShellModule.prerender()]}) + .get(IS_PRERENDER); + expect(prerender).toBeTruthy(); + }); + it('should be false at runtime', () => { + const prerender = TestBed + .configureTestingModule({imports: [AppShellModule.runtime()]}) + .get(IS_PRERENDER); + expect(prerender).toBeFalsy(); + }); + }); +} diff --git a/app-shell/src/app/prerender.ts b/app-shell/src/app/prerender.ts new file mode 100644 index 0000000..2e1ea6c --- /dev/null +++ b/app-shell/src/app/prerender.ts @@ -0,0 +1,3 @@ +import {OpaqueToken} from '@angular/core'; + +export const IS_PRERENDER = new OpaqueToken('IsPrerender'); diff --git a/app-shell/src/app/shared/index.ts b/app-shell/src/app/shared/index.ts deleted file mode 100644 index e69de29..0000000 diff --git a/app-shell/src/app/shell-no-render.directive.spec.ts b/app-shell/src/app/shell-no-render.directive.spec.ts deleted file mode 100644 index 79f7bbb..0000000 --- a/app-shell/src/app/shell-no-render.directive.spec.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { - ComponentFixture, - async, - inject, - TestBed -} from '@angular/core/testing'; -import { Component } from '@angular/core'; - -import { ShellNoRender } from './shell-no-render.directive'; -import { APP_SHELL_RUNTIME_PROVIDERS, APP_SHELL_BUILD_PROVIDERS } from './is-prerender.service'; -import { - AppShellModule -} from './index'; - -@Component({ - selector: 'test-component', - template: `
Rendered
` -}) -class TestComponent {} - -describe('ShellNoRender Directive', () => { - - describe('prerender', () => { - - beforeEach(() => { - TestBed.configureTestingModule({ - imports: [AppShellModule], - providers: [APP_SHELL_BUILD_PROVIDERS], - declarations: [TestComponent] - }); - TestBed.compileComponents(); - }); - - it('should NOT render the element', () => { - const fixture = TestBed.createComponent(TestComponent); - fixture.detectChanges(); - expect(fixture.debugElement.childNodes.length).toBe(1); - expect(fixture.debugElement.childNodes[0].nativeNode.textContent).toBe('template bindings={}'); - }); - }); - - - describe('runtime', () => { - - beforeEach(() => { - TestBed.configureTestingModule({ - imports: [AppShellModule], - providers: [APP_SHELL_RUNTIME_PROVIDERS], - declarations: [TestComponent] - }); - TestBed.compileComponents(); - }); - - it('should render the element', () => { - const fixture = TestBed.createComponent(TestComponent); - fixture.detectChanges(); - expect(fixture.debugElement.childNodes.length).toBe(2); - expect(fixture.debugElement.childNodes[0].nativeNode.textContent).toBe('template bindings={}'); - expect(fixture.debugElement.childNodes[1].nativeNode.textContent).toBe('Rendered'); - }); - }); -}); diff --git a/app-shell/src/app/shell-no-render.directive.ts b/app-shell/src/app/shell-no-render.directive.ts deleted file mode 100644 index e379a01..0000000 --- a/app-shell/src/app/shell-no-render.directive.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { Directive, Inject, OnInit, ViewContainerRef, TemplateRef } from '@angular/core'; - -import { IS_PRERENDER } from './is-prerender.service'; - -@Directive({selector: '[shellNoRender]'}) -export class ShellNoRender implements OnInit { - constructor( - private _viewContainer: ViewContainerRef, - private _templateRef: TemplateRef, - @Inject(IS_PRERENDER) private _isPrerender: boolean) { - } - - ngOnInit () { - if (this._isPrerender) { - this._viewContainer.clear(); - } else { - this._viewContainer.createEmbeddedView(this._templateRef); - } - } -} diff --git a/app-shell/src/app/shell-render.directive.spec.ts b/app-shell/src/app/shell-render.directive.spec.ts deleted file mode 100644 index 1780130..0000000 --- a/app-shell/src/app/shell-render.directive.spec.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { - async, - inject, - ComponentFixture, - TestBed -} from '@angular/core/testing'; -import { Component } from '@angular/core'; - -import { ShellRender } from './shell-render.directive'; -import { APP_SHELL_RUNTIME_PROVIDERS, APP_SHELL_BUILD_PROVIDERS } from './is-prerender.service'; -import { - AppShellModule -} from './index'; - -@Component({ - selector: 'test-component', - template: `
Rendered
` -}) -class TestComponent {} - -describe('ShellRender Directive', () => { - - describe('prerender', () => { - - beforeEach(() => { - TestBed.configureTestingModule({ - imports: [AppShellModule], - providers: [APP_SHELL_BUILD_PROVIDERS], - declarations: [TestComponent] - }); - TestBed.compileComponents(); - }); - - it('should render the element', () => { - const fixture = TestBed.createComponent(TestComponent); - fixture.detectChanges(); - expect(fixture.debugElement.childNodes.length).toBe(2); - expect(fixture.debugElement.childNodes[0].nativeNode.textContent).toBe('template bindings={}'); - expect(fixture.debugElement.childNodes[1].nativeNode.textContent).toBe('Rendered'); - }); - }); - - - describe('runtime', () => { - - beforeEach(() => { - TestBed.configureTestingModule({ - imports: [AppShellModule], - providers: [APP_SHELL_RUNTIME_PROVIDERS], - declarations: [TestComponent] - }); - TestBed.compileComponents(); - }); - - it('should NOT render the element', () => { - const fixture = TestBed.createComponent(TestComponent); - fixture.detectChanges(); - expect(fixture.debugElement.childNodes.length).toBe(1); - expect(fixture.debugElement.childNodes[0].nativeNode.textContent).toBe('template bindings={}'); - }); - }); -}); - - diff --git a/app-shell/src/app/shell-render.directive.ts b/app-shell/src/app/shell-render.directive.ts deleted file mode 100644 index 6f53a01..0000000 --- a/app-shell/src/app/shell-render.directive.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Directive, Inject, OnInit, ViewContainerRef, TemplateRef } from '@angular/core'; - -import { IS_PRERENDER } from './is-prerender.service'; - -@Directive({ - selector: '[shellRender]' -}) -export class ShellRender implements OnInit { - constructor( - private _viewContainer: ViewContainerRef, - private _templateRef: TemplateRef, - @Inject(IS_PRERENDER) private _isPrerender: boolean) { - } - - ngOnInit () { - if (this._isPrerender) { - this._viewContainer.createEmbeddedView(this._templateRef); - } else { - this._viewContainer.clear(); - } - } -} diff --git a/app-shell/src/app/shell.spec.ts b/app-shell/src/app/shell.spec.ts new file mode 100644 index 0000000..8a33d56 --- /dev/null +++ b/app-shell/src/app/shell.spec.ts @@ -0,0 +1,70 @@ +import {Component} from '@angular/core'; +import {TestBed} from '@angular/core/testing'; +import {AppShellModule} from './module'; +import {ShellNoRender, ShellRender} from './shell'; + +export default function () { + describe('ShellNoRender Directive', () => { + @Component({ + selector: 'test-component', + template: `
Rendered
`, + }) + class NoRenderTestComponent {} + + it('should NOT render the element at prerender time', () => { + const fixture = TestBed + .configureTestingModule({ + declarations: [NoRenderTestComponent], + imports: [AppShellModule.prerender()] + }) + .createComponent(NoRenderTestComponent); + fixture.detectChanges(); + expect(fixture.debugElement.childNodes.length).toBe(1); + expect(fixture.debugElement.childNodes[0].nativeNode.data).toBe('template bindings={}'); + }); + it('should render the element at runtime', () => { + const fixture = TestBed + .configureTestingModule({ + declarations: [NoRenderTestComponent], + imports: [AppShellModule.runtime()] + }) + .createComponent(NoRenderTestComponent); + fixture.detectChanges(); + expect(fixture.debugElement.childNodes.length).toBe(2); + expect(fixture.debugElement.childNodes[0].nativeNode.data).toBe('template bindings={}'); + expect(fixture.debugElement.childNodes[1].nativeNode.name).toBe('div'); + }); + }); + + describe('ShellRender Directive', () => { + @Component({ + selector: 'test-component', + template: `
Rendered
`, + }) + class RenderTestComponent {} + + it('should render the element at prerender time', () => { + const fixture = TestBed + .configureTestingModule({ + declarations: [RenderTestComponent], + imports: [AppShellModule.prerender()], + }) + .createComponent(RenderTestComponent); + fixture.detectChanges(); + expect(fixture.debugElement.childNodes.length).toBe(2); + expect(fixture.debugElement.childNodes[0].nativeNode.data).toBe('template bindings={}'); + expect(fixture.debugElement.childNodes[1].nativeNode.name).toBe('div'); + }); + it('should NOT render the element at runtime', () => { + const fixture = TestBed + .configureTestingModule({ + declarations: [RenderTestComponent], + imports: [AppShellModule.runtime()], + }) + .createComponent(RenderTestComponent); + fixture.detectChanges(); + expect(fixture.debugElement.childNodes.length).toBe(1); + expect(fixture.debugElement.childNodes[0].nativeNode.data).toBe('template bindings={}'); + }); + }); +} diff --git a/app-shell/src/app/shell.ts b/app-shell/src/app/shell.ts new file mode 100644 index 0000000..a44d6b8 --- /dev/null +++ b/app-shell/src/app/shell.ts @@ -0,0 +1,39 @@ +import { Directive, Inject, OnInit, ViewContainerRef, TemplateRef } from '@angular/core'; +import {IS_PRERENDER} from './prerender'; + +@Directive({ + selector: '[shellNoRender]' +}) +export class ShellNoRender implements OnInit { + + constructor( + private _viewContainer: ViewContainerRef, + private _templateRef: TemplateRef, + @Inject(IS_PRERENDER) private _isPrerender: boolean) {} + + ngOnInit() { + if (this._isPrerender) { + this._viewContainer.clear(); + } else { + this._viewContainer.createEmbeddedView(this._templateRef); + } + } +} + +@Directive({ + selector: '[shellRender]' +}) +export class ShellRender implements OnInit { + constructor( + private _viewContainer: ViewContainerRef, + private _templateRef: TemplateRef, + @Inject(IS_PRERENDER) private _isPrerender: boolean) {} + + ngOnInit() { + if (this._isPrerender) { + this._viewContainer.createEmbeddedView(this._templateRef); + } else { + this._viewContainer.clear(); + } + } +} diff --git a/app-shell/src/app/shell-parser/ast/ast-node.ts b/app-shell/src/experimental/shell-parser/ast/ast-node.ts similarity index 100% rename from app-shell/src/app/shell-parser/ast/ast-node.ts rename to app-shell/src/experimental/shell-parser/ast/ast-node.ts diff --git a/app-shell/src/app/shell-parser/ast/index.ts b/app-shell/src/experimental/shell-parser/ast/index.ts similarity index 100% rename from app-shell/src/app/shell-parser/ast/index.ts rename to app-shell/src/experimental/shell-parser/ast/index.ts diff --git a/app-shell/src/app/shell-parser/config.ts b/app-shell/src/experimental/shell-parser/config.ts similarity index 100% rename from app-shell/src/app/shell-parser/config.ts rename to app-shell/src/experimental/shell-parser/config.ts diff --git a/app-shell/src/app/shell-parser/context.ts b/app-shell/src/experimental/shell-parser/context.ts similarity index 100% rename from app-shell/src/app/shell-parser/context.ts rename to app-shell/src/experimental/shell-parser/context.ts diff --git a/app-shell/src/app/shell-parser/index.ts b/app-shell/src/experimental/shell-parser/index.ts similarity index 100% rename from app-shell/src/app/shell-parser/index.ts rename to app-shell/src/experimental/shell-parser/index.ts diff --git a/app-shell/src/app/shell-parser/node-matcher/css-node-matcher.spec.ts b/app-shell/src/experimental/shell-parser/node-matcher/css-node-matcher.spec.ts similarity index 100% rename from app-shell/src/app/shell-parser/node-matcher/css-node-matcher.spec.ts rename to app-shell/src/experimental/shell-parser/node-matcher/css-node-matcher.spec.ts diff --git a/app-shell/src/app/shell-parser/node-matcher/css-node-matcher.ts b/app-shell/src/experimental/shell-parser/node-matcher/css-node-matcher.ts similarity index 100% rename from app-shell/src/app/shell-parser/node-matcher/css-node-matcher.ts rename to app-shell/src/experimental/shell-parser/node-matcher/css-node-matcher.ts diff --git a/app-shell/src/app/shell-parser/node-matcher/css-selector/css-selector.spec.ts b/app-shell/src/experimental/shell-parser/node-matcher/css-selector/css-selector.spec.ts similarity index 100% rename from app-shell/src/app/shell-parser/node-matcher/css-selector/css-selector.spec.ts rename to app-shell/src/experimental/shell-parser/node-matcher/css-selector/css-selector.spec.ts diff --git a/app-shell/src/app/shell-parser/node-matcher/css-selector/css-selector.ts b/app-shell/src/experimental/shell-parser/node-matcher/css-selector/css-selector.ts similarity index 100% rename from app-shell/src/app/shell-parser/node-matcher/css-selector/css-selector.ts rename to app-shell/src/experimental/shell-parser/node-matcher/css-selector/css-selector.ts diff --git a/app-shell/src/app/shell-parser/node-matcher/css-selector/index.ts b/app-shell/src/experimental/shell-parser/node-matcher/css-selector/index.ts similarity index 100% rename from app-shell/src/app/shell-parser/node-matcher/css-selector/index.ts rename to app-shell/src/experimental/shell-parser/node-matcher/css-selector/index.ts diff --git a/app-shell/src/app/shell-parser/node-matcher/index.ts b/app-shell/src/experimental/shell-parser/node-matcher/index.ts similarity index 100% rename from app-shell/src/app/shell-parser/node-matcher/index.ts rename to app-shell/src/experimental/shell-parser/node-matcher/index.ts diff --git a/app-shell/src/app/shell-parser/node-matcher/node-matcher.ts b/app-shell/src/experimental/shell-parser/node-matcher/node-matcher.ts similarity index 100% rename from app-shell/src/app/shell-parser/node-matcher/node-matcher.ts rename to app-shell/src/experimental/shell-parser/node-matcher/node-matcher.ts diff --git a/app-shell/src/app/shell-parser/node-visitor/index.ts b/app-shell/src/experimental/shell-parser/node-visitor/index.ts similarity index 100% rename from app-shell/src/app/shell-parser/node-visitor/index.ts rename to app-shell/src/experimental/shell-parser/node-visitor/index.ts diff --git a/app-shell/src/app/shell-parser/node-visitor/node-visitor.ts b/app-shell/src/experimental/shell-parser/node-visitor/node-visitor.ts similarity index 100% rename from app-shell/src/app/shell-parser/node-visitor/node-visitor.ts rename to app-shell/src/experimental/shell-parser/node-visitor/node-visitor.ts diff --git a/app-shell/src/app/shell-parser/node-visitor/resource-inline/index.ts b/app-shell/src/experimental/shell-parser/node-visitor/resource-inline/index.ts similarity index 100% rename from app-shell/src/app/shell-parser/node-visitor/resource-inline/index.ts rename to app-shell/src/experimental/shell-parser/node-visitor/resource-inline/index.ts diff --git a/app-shell/src/app/shell-parser/node-visitor/resource-inline/inline-style-resource-inline-visitor.spec.ts b/app-shell/src/experimental/shell-parser/node-visitor/resource-inline/inline-style-resource-inline-visitor.spec.ts similarity index 100% rename from app-shell/src/app/shell-parser/node-visitor/resource-inline/inline-style-resource-inline-visitor.spec.ts rename to app-shell/src/experimental/shell-parser/node-visitor/resource-inline/inline-style-resource-inline-visitor.spec.ts diff --git a/app-shell/src/app/shell-parser/node-visitor/resource-inline/inline-style-resource-inline-visitor.ts b/app-shell/src/experimental/shell-parser/node-visitor/resource-inline/inline-style-resource-inline-visitor.ts similarity index 100% rename from app-shell/src/app/shell-parser/node-visitor/resource-inline/inline-style-resource-inline-visitor.ts rename to app-shell/src/experimental/shell-parser/node-visitor/resource-inline/inline-style-resource-inline-visitor.ts diff --git a/app-shell/src/app/shell-parser/node-visitor/resource-inline/resource-inline-visitor.ts b/app-shell/src/experimental/shell-parser/node-visitor/resource-inline/resource-inline-visitor.ts similarity index 100% rename from app-shell/src/app/shell-parser/node-visitor/resource-inline/resource-inline-visitor.ts rename to app-shell/src/experimental/shell-parser/node-visitor/resource-inline/resource-inline-visitor.ts diff --git a/app-shell/src/app/shell-parser/node-visitor/resource-inline/stylesheet-resource-inline-visitor.spec.ts b/app-shell/src/experimental/shell-parser/node-visitor/resource-inline/stylesheet-resource-inline-visitor.spec.ts similarity index 100% rename from app-shell/src/app/shell-parser/node-visitor/resource-inline/stylesheet-resource-inline-visitor.spec.ts rename to app-shell/src/experimental/shell-parser/node-visitor/resource-inline/stylesheet-resource-inline-visitor.spec.ts diff --git a/app-shell/src/app/shell-parser/node-visitor/resource-inline/stylesheet-resource-inline-visitor.ts b/app-shell/src/experimental/shell-parser/node-visitor/resource-inline/stylesheet-resource-inline-visitor.ts similarity index 100% rename from app-shell/src/app/shell-parser/node-visitor/resource-inline/stylesheet-resource-inline-visitor.ts rename to app-shell/src/experimental/shell-parser/node-visitor/resource-inline/stylesheet-resource-inline-visitor.ts diff --git a/app-shell/src/app/shell-parser/node-visitor/template-strip-visitor.spec.ts b/app-shell/src/experimental/shell-parser/node-visitor/template-strip-visitor.spec.ts similarity index 100% rename from app-shell/src/app/shell-parser/node-visitor/template-strip-visitor.spec.ts rename to app-shell/src/experimental/shell-parser/node-visitor/template-strip-visitor.spec.ts diff --git a/app-shell/src/app/shell-parser/node-visitor/template-strip-visitor.ts b/app-shell/src/experimental/shell-parser/node-visitor/template-strip-visitor.ts similarity index 100% rename from app-shell/src/app/shell-parser/node-visitor/template-strip-visitor.ts rename to app-shell/src/experimental/shell-parser/node-visitor/template-strip-visitor.ts diff --git a/app-shell/src/app/shell-parser/shell-parser-factory.ts b/app-shell/src/experimental/shell-parser/shell-parser-factory.ts similarity index 100% rename from app-shell/src/app/shell-parser/shell-parser-factory.ts rename to app-shell/src/experimental/shell-parser/shell-parser-factory.ts diff --git a/app-shell/src/app/shell-parser/shell-parser.spec.ts b/app-shell/src/experimental/shell-parser/shell-parser.spec.ts similarity index 100% rename from app-shell/src/app/shell-parser/shell-parser.spec.ts rename to app-shell/src/experimental/shell-parser/shell-parser.spec.ts diff --git a/app-shell/src/app/shell-parser/shell-parser.ts b/app-shell/src/experimental/shell-parser/shell-parser.ts similarity index 100% rename from app-shell/src/app/shell-parser/shell-parser.ts rename to app-shell/src/experimental/shell-parser/shell-parser.ts diff --git a/app-shell/src/app/shell-parser/template-parser/index.ts b/app-shell/src/experimental/shell-parser/template-parser/index.ts similarity index 100% rename from app-shell/src/app/shell-parser/template-parser/index.ts rename to app-shell/src/experimental/shell-parser/template-parser/index.ts diff --git a/app-shell/src/app/shell-parser/template-parser/parse5/drop-named-entities-patch.spec.ts b/app-shell/src/experimental/shell-parser/template-parser/parse5/drop-named-entities-patch.spec.ts similarity index 100% rename from app-shell/src/app/shell-parser/template-parser/parse5/drop-named-entities-patch.spec.ts rename to app-shell/src/experimental/shell-parser/template-parser/parse5/drop-named-entities-patch.spec.ts diff --git a/app-shell/src/app/shell-parser/template-parser/parse5/drop-named-entities-patch.ts b/app-shell/src/experimental/shell-parser/template-parser/parse5/drop-named-entities-patch.ts similarity index 100% rename from app-shell/src/app/shell-parser/template-parser/parse5/drop-named-entities-patch.ts rename to app-shell/src/experimental/shell-parser/template-parser/parse5/drop-named-entities-patch.ts diff --git a/app-shell/src/app/shell-parser/template-parser/parse5/parse5-template-parser.spec.ts b/app-shell/src/experimental/shell-parser/template-parser/parse5/parse5-template-parser.spec.ts similarity index 100% rename from app-shell/src/app/shell-parser/template-parser/parse5/parse5-template-parser.spec.ts rename to app-shell/src/experimental/shell-parser/template-parser/parse5/parse5-template-parser.spec.ts diff --git a/app-shell/src/app/shell-parser/template-parser/parse5/parse5-template-parser.ts b/app-shell/src/experimental/shell-parser/template-parser/parse5/parse5-template-parser.ts similarity index 100% rename from app-shell/src/app/shell-parser/template-parser/parse5/parse5-template-parser.ts rename to app-shell/src/experimental/shell-parser/template-parser/parse5/parse5-template-parser.ts diff --git a/app-shell/src/app/shell-parser/template-parser/parse5/tokenizer-case-sensitivity-patch.spec.ts b/app-shell/src/experimental/shell-parser/template-parser/parse5/tokenizer-case-sensitivity-patch.spec.ts similarity index 100% rename from app-shell/src/app/shell-parser/template-parser/parse5/tokenizer-case-sensitivity-patch.spec.ts rename to app-shell/src/experimental/shell-parser/template-parser/parse5/tokenizer-case-sensitivity-patch.spec.ts diff --git a/app-shell/src/app/shell-parser/template-parser/parse5/tokenizer-case-sensitivity-patch.ts b/app-shell/src/experimental/shell-parser/template-parser/parse5/tokenizer-case-sensitivity-patch.ts similarity index 100% rename from app-shell/src/app/shell-parser/template-parser/parse5/tokenizer-case-sensitivity-patch.ts rename to app-shell/src/experimental/shell-parser/template-parser/parse5/tokenizer-case-sensitivity-patch.ts diff --git a/app-shell/src/app/shell-parser/template-parser/template-parser.ts b/app-shell/src/experimental/shell-parser/template-parser/template-parser.ts similarity index 100% rename from app-shell/src/app/shell-parser/template-parser/template-parser.ts rename to app-shell/src/experimental/shell-parser/template-parser/template-parser.ts diff --git a/app-shell/src/app/shell-parser/testing/context-mock.ts b/app-shell/src/experimental/shell-parser/testing/context-mock.ts similarity index 100% rename from app-shell/src/app/shell-parser/testing/context-mock.ts rename to app-shell/src/experimental/shell-parser/testing/context-mock.ts diff --git a/app-shell/src/app/shell-parser/testing/index.ts b/app-shell/src/experimental/shell-parser/testing/index.ts similarity index 100% rename from app-shell/src/app/shell-parser/testing/index.ts rename to app-shell/src/experimental/shell-parser/testing/index.ts diff --git a/app-shell/src/app/shell-parser/testing/mock-caches.ts b/app-shell/src/experimental/shell-parser/testing/mock-caches.ts similarity index 100% rename from app-shell/src/app/shell-parser/testing/mock-caches.ts rename to app-shell/src/experimental/shell-parser/testing/mock-caches.ts diff --git a/app-shell/src/app/shell-parser/testing/mock-requests.ts b/app-shell/src/experimental/shell-parser/testing/mock-requests.ts similarity index 100% rename from app-shell/src/app/shell-parser/testing/mock-requests.ts rename to app-shell/src/experimental/shell-parser/testing/mock-requests.ts diff --git a/app-shell/src/index.html b/app-shell/src/index.html deleted file mode 100644 index e69de29..0000000 diff --git a/app-shell/src/index.ts b/app-shell/src/index.ts new file mode 100644 index 0000000..665a3d9 --- /dev/null +++ b/app-shell/src/index.ts @@ -0,0 +1 @@ +export * from './app'; diff --git a/app-shell/src/manual_typings/service-worker.d.ts b/app-shell/src/manual_typings/service-worker.d.ts deleted file mode 100644 index 3d392fe..0000000 --- a/app-shell/src/manual_typings/service-worker.d.ts +++ /dev/null @@ -1,29 +0,0 @@ -declare class ServiceWorkerContext { -} - -declare interface Cache { - add(request: Request): Promise; - addAll(requests: Request[]): Promise; - delete(request: Request, options?: CacheOptions): Promise; - keys(request?: Request, options?: CacheOptions): Promise; - match(request: Request, options?: CacheOptions): Promise; - matchAll(request: Request, options?: CacheOptions): Promise; - put(request: Request, response: Response): Promise; -} - -declare interface CacheStorage { - delete(cacheName: string): Promise; - has(cacheName: string): Promise; - keys(): Promise; - match(request: Request, options?: CacheOptions): Promise; - open(cacheName: string): Promise; -} - -declare interface CacheOptions { - ignoreSearch?: boolean; - ignoreMethod?: boolean; - ignoreVary?: boolean; - cacheName?: string; -} - -declare var caches: CacheStorage; diff --git a/app-shell/src/package.json b/app-shell/src/package.json deleted file mode 100644 index 681545c..0000000 --- a/app-shell/src/package.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "name": "@angular/app-shell", - "version": "0.0.0", - "description": "App Shell runtime library for Angular 2 Progressive Web Apps.", - "main": "index.js", - "jsnext:main": "esm/index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/angular/mobile-toolkit.git" - }, - "contributors": [ - "Minko Gechev ", - "Jeff Cross " - ], - "keywords": [ - "angular2", - "pwa", - "progressive web apps", - "app shell" - ], - "author": "", - "license": "MIT", - "bugs": { - "url": "https://github.com/angular/mobile-toolkit/issues" - }, - "homepage": "https://github.com/angular/mobile-toolkit#readme", - "peerDependencies": { - "@angular/core": "~2.0.0-rc.1" - } -} diff --git a/app-shell/src/system-config.ts b/app-shell/src/system-config.ts deleted file mode 100644 index 409083f..0000000 --- a/app-shell/src/system-config.ts +++ /dev/null @@ -1,66 +0,0 @@ -/** Only use System here. */ -declare var System: any; - -const barrels: string[] = [ - // Parse5 barrels - 'parse5', - 'parse5/parser', - 'parse5/serializer', - 'parse5/common', - 'parse5/tokenizer', - 'parse5/tree_adapter', - 'parse5/location_info', - - 'rxjs', - - // App specific barrels. - 'app', - 'app/shared', - 'app/shell-parser', - 'app/shell-parser/template-parser', - 'app/shell-parser/node-visitor', - 'app/shell-parser/node-visitor/resource-inline', - 'app/shell-parser/node-matcher', - 'app/shell-parser/node-matcher/css-selector', - 'app/shell-parser/ast', - 'app/shell-parser/testing', - /** @cli-barrel */ -]; - -// Angular CLI SystemJS configuration. -System.config({ - map: { - 'parse5': 'vendor/parse5/lib', - 'rxjs': 'vendor/rxjs', - 'traceur': 'vendor/traceur/bin/traceur.js', - 'main': 'main.js' - }, - paths: { - '@angular/common': 'vendor/@angular/common/bundles/common.umd.js', - '@angular/compiler': 'vendor/@angular/compiler/bundles/compiler.umd.js', - '@angular/core': 'vendor/@angular/core/bundles/core.umd.js', - '@angular/platform-browser': 'vendor/@angular/platform-browser/bundles/platform-browser.umd.js', - '@angular/platform-browser-dynamic': 'vendor/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js', - - '@angular/common/testing': 'vendor/@angular/common/bundles/common-testing.umd.js', - '@angular/compiler/testing': 'vendor/@angular/compiler/bundles/compiler-testing.umd.js', - '@angular/core/testing': 'vendor/@angular/core/bundles/core-testing.umd.js', - '@angular/platform-browser/testing': 'vendor/@angular/platform-browser/bundles/platform-browser-testing.umd.js', - '@angular/platform-browser-dynamic/testing': 'vendor/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic-testing.umd.js', - - }, - packages: barrels.reduce((barrelConfig: any, barrelName: string) => { - barrelConfig[barrelName] = { - main: 'index' - }; - return barrelConfig; - }, {}) -}); - - -// Add your custom SystemJS configuration here. -System.config({ - packages: { - // Add your custom SystemJS packages here. - } -}); diff --git a/app-shell/src/tsconfig.json b/app-shell/src/tsconfig.json deleted file mode 100644 index 93acefc..0000000 --- a/app-shell/src/tsconfig.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "compilerOptions": { - "declaration": true, - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "module": "commonjs", - "target": "es5", - "moduleResolution": "node", - "noEmitOnError": true, - "noImplicitAny": true, - "outDir": "../dist/app", - "rootDir": "./app", - "sourceMap": true, - "inlineSources": true - }, - - "files": [ - "app/index.ts", - "typings.d.ts" - ] -} diff --git a/app-shell/src/typings.d.ts b/app-shell/src/typings.d.ts deleted file mode 100644 index 6b5faa4..0000000 --- a/app-shell/src/typings.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -/// - diff --git a/app-shell/src/unit_tests.ts b/app-shell/src/unit_tests.ts new file mode 100644 index 0000000..96dd37c --- /dev/null +++ b/app-shell/src/unit_tests.ts @@ -0,0 +1,19 @@ +import 'reflect-metadata'; +import 'zone.js'; +import 'zone.js/dist/long-stack-trace-zone.js'; +import 'zone.js/dist/proxy.js'; +import 'zone.js/dist/sync-test.js'; +import 'zone.js/dist/jasmine-patch.js'; +import 'zone.js/dist/async-test.js'; +import 'zone.js/dist/fake-async-test.js'; + +import {TestBed} from '@angular/core/testing'; +import {platformServerTesting, ServerTestingModule} from '@angular/platform-server/testing'; + +import prerenderTests from './app/prerender.spec'; +import shellTests from './app/shell.spec'; + +TestBed.initTestEnvironment(ServerTestingModule, platformServerTesting()); + +prerenderTests(); +shellTests(); diff --git a/hello-mobile/src/tsconfig.json b/app-shell/tsconfig.es5.json similarity index 55% rename from hello-mobile/src/tsconfig.json rename to app-shell/tsconfig.es5.json index 65fbda3..2950459 100644 --- a/hello-mobile/src/tsconfig.json +++ b/app-shell/tsconfig.es5.json @@ -1,24 +1,20 @@ { - "compileOnSave": false, "compilerOptions": { - "declaration": false, + "module": "commonjs", + "target": "es5", + "noImplicitAny": false, "emitDecoratorMetadata": true, "experimentalDecorators": true, - "mapRoot": "", - "module": "commonjs", + "declaration": false, + "outDir": "tmp/es5", + "sourceMap": false, "moduleResolution": "node", - "noEmitOnError": true, - "noImplicitAny": false, - "outDir": "../dist/", "rootDir": ".", - "sourceMap": true, - "target": "es5", - "inlineSources": true - }, - + "baseUrl": ".", + "lib": ["es2015", "dom"] + }, "files": [ - "main.ts", - "main-app-shell.ts", - "typings.d.ts" + "src/index.ts", + "src/unit_tests.ts" ] } diff --git a/app-shell/src/tsconfig.publish.json b/app-shell/tsconfig.esm.json similarity index 68% rename from app-shell/src/tsconfig.publish.json rename to app-shell/tsconfig.esm.json index ab4bda0..7a72dd8 100644 --- a/app-shell/src/tsconfig.publish.json +++ b/app-shell/tsconfig.esm.json @@ -1,22 +1,21 @@ { "compilerOptions": { - "declaration": true, - "emitDecoratorMetadata": true, - "experimentalDecorators": true, "module": "es2015", "target": "es5", - "moduleResolution": "node", - "noImplicitAny": true, - "outDir": "../dist/app", + "noImplicitAny": false, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "declaration": true, + "outDir": "tmp/esm", "sourceMap": true, - "inlineSources": true + "moduleResolution": "node", + "rootDir": ".", + "baseUrl": ".", + "lib": ["es2015", "dom"] }, - "files": [ - "app/index.ts", - "typings.d.ts" + "src/index.ts" ], - "angularCompilerOptions": { "skipTemplateCodegen": true } diff --git a/app-shell/tsconfig.json b/app-shell/tsconfig.json new file mode 100644 index 0000000..8c50afb --- /dev/null +++ b/app-shell/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es5", + "noImplicitAny": false, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "declaration": true, + "outDir": "dist", + "sourceMap": false, + "moduleResolution": "node", + "rootDir": ".", + "baseUrl": "." + }, + "exclude": [ + "node_modules" + ] +} diff --git a/app-shell/typings.json b/app-shell/typings.json deleted file mode 100644 index 31e9d15..0000000 --- a/app-shell/typings.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "globalDevDependencies": { - "angular-protractor": "registry:dt/angular-protractor#1.5.0+20160425143459", - "jasmine": "registry:dt/jasmine#2.2.0+20160505161446", - "selenium-webdriver": "registry:dt/selenium-webdriver#2.44.0+20160317120654" - }, - "globalDependencies": { - "es6-shim": "registry:dt/es6-shim#0.31.2+20160602141504", - "node": "registry:dt/node#6.0.0+20160602155235", - "parse5": "registry:dt/parse5#2.1.5+20160602151856", - "whatwg-fetch": "registry:dt/whatwg-fetch#0.0.0+20160524142046" - } -} diff --git a/test.sh b/test.sh index 5e61b9a..688fa6b 100755 --- a/test.sh +++ b/test.sh @@ -2,5 +2,4 @@ cd ./service-worker/worker gulp test cd ../../app-shell -./node_modules/.bin/ng test --watch=false - +gulp test