From 61d7ea93b952e9d6a120a6cf4701aeef05211d0e Mon Sep 17 00:00:00 2001 From: Tim Lancina Date: Mon, 28 Jan 2019 13:42:03 -0800 Subject: [PATCH 1/3] chore(angular): update dependencies --- builders/cordova-serve/index.ts | 4 ++-- package.json | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/builders/cordova-serve/index.ts b/builders/cordova-serve/index.ts index 87466b7..f067353 100644 --- a/builders/cordova-serve/index.ts +++ b/builders/cordova-serve/index.ts @@ -1,5 +1,5 @@ import { BuildEvent, Builder, BuilderConfiguration, BuilderContext, BuilderDescription } from '@angular-devkit/architect'; -import { BrowserBuilderSchema } from '@angular-devkit/build-angular/src/browser/schema'; +import { NormalizedBrowserBuilderSchema } from '@angular-devkit/build-angular/src/browser/schema'; import { DevServerBuilder, DevServerBuilderOptions } from '@angular-devkit/build-angular/src/dev-server'; import { Path, virtualFs } from '@angular-devkit/core'; import * as fs from 'fs'; @@ -52,7 +52,7 @@ class CordovaDevServerBuilder extends DevServerBuilder { super(context); } - buildWebpackConfig(root: Path, projectRoot: Path, host: virtualFs.Host, browserOptions: BrowserBuilderSchema) { + buildWebpackConfig(root: Path, projectRoot: Path, host: virtualFs.Host, browserOptions: NormalizedBrowserBuilderSchema) { const builder = new CordovaBuildBuilder(this.context); builder.prepareBrowserConfig(this.cordovaBuildOptions, browserOptions); diff --git a/package.json b/package.json index 02d5ac6..f587c34 100644 --- a/package.json +++ b/package.json @@ -32,11 +32,11 @@ "dependencies": { "@schematics/angular": "^7.0.3", "tslib": "^1.9.0", - "typescript": "~3.1.0" + "typescript": "^3.2.4" }, "devDependencies": { - "@angular-devkit/architect": "^0.11.3", - "@angular-devkit/build-angular": "^0.11.3", + "@angular-devkit/architect": "^0.12.3", + "@angular-devkit/build-angular": "^0.12.3", "@angular-devkit/core": "^7.1.3", "@angular-devkit/schematics": "^7.1.3", "@semantic-release/changelog": "^3.0.0", From 2672743891f36952f8cae728a33a7192c832605b Mon Sep 17 00:00:00 2001 From: Tim Lancina Date: Mon, 28 Jan 2019 15:40:18 -0800 Subject: [PATCH 2/3] feat(build): add cordovaMock option Add support for adding a blank cordova.js to the build with --cordovaMock --- builders/cordova-build/index.ts | 21 ++++++++++++++++++++- builders/cordova-build/schema.d.ts | 3 ++- builders/cordova-build/schema.json | 8 ++++++-- builders/cordova-serve/index.ts | 5 +++-- builders/cordova-serve/schema.d.ts | 4 +++- builders/cordova-serve/schema.json | 13 +++++++++++-- 6 files changed, 45 insertions(+), 9 deletions(-) diff --git a/builders/cordova-build/index.ts b/builders/cordova-build/index.ts index a88af77..219e4b0 100644 --- a/builders/cordova-build/index.ts +++ b/builders/cordova-build/index.ts @@ -23,12 +23,25 @@ export class CordovaBuildBuilder implements Builder { tap(description => browserDescription = description), concatMap(() => this.context.architect.validateBuilderOptions(browserConfig, browserDescription)), tap(config => browserConfig = config), + tap(() => this.validateBuilderConfig(builderConfig.options)), tap(() => this.prepareBrowserConfig(builderConfig.options, browserConfig.options)), concatMap(() => of(this.context.architect.getBuilder(browserDescription, this.context))), concatMap(builder => builder.run(browserConfig)) ); } + // Mutates builderOptions + validateBuilderConfig(builderOptions: CordovaBuildBuilderSchema) { + // if we're mocking cordova.js, don't build cordova bundle + if (builderOptions.cordovaMock) { + builderOptions.cordovaAssets = false; + } + + if (builderOptions.cordovaAssets && !builderOptions.platform) { + throw new Error('The `--platform` option is required with `--cordova-assets`'); + } + } + // Mutates browserOptions prepareBrowserConfig(options: CordovaBuildBuilderSchema, browserOptions: BrowserBuilderSchema) { const cordovaBasePath = normalize(options.cordovaBasePath ? options.cordovaBasePath : '.'); @@ -41,7 +54,13 @@ export class CordovaBuildBuilder implements Builder { // by default. Let's keep it around. browserOptions.deleteOutputPath = false; - if (options.cordovaAssets) { + if (options.cordovaMock) { + browserOptions.scripts.push({ + input: getSystemPath(join(normalize(__dirname), normalize('cordova.js'))), + bundleName: 'cordova', + lazy: false, + }); + } else if (options.cordovaAssets) { const platformWWWPath = join(cordovaBasePath, normalize(`platforms/${options.platform}/platform_www`)); // Add Cordova www assets that were generated whenever platform(s) and diff --git a/builders/cordova-build/schema.d.ts b/builders/cordova-build/schema.d.ts index e81b062..8f17bf3 100644 --- a/builders/cordova-build/schema.d.ts +++ b/builders/cordova-build/schema.d.ts @@ -1,7 +1,8 @@ export interface CordovaBuildBuilderSchema { browserTarget: string; - platform: string; + platform?: string; cordovaBasePath?: string; sourceMap?: boolean; cordovaAssets?: boolean; + cordovaMock?: boolean; } diff --git a/builders/cordova-build/schema.json b/builders/cordova-build/schema.json index 83d1e24..7e3583b 100644 --- a/builders/cordova-build/schema.json +++ b/builders/cordova-build/schema.json @@ -23,11 +23,15 @@ "type": "boolean", "description": "Bundle Cordova assets with build", "default": true + }, + "cordovaMock": { + "type": "boolean", + "description": "Bundle empty cordova.js with build", + "default": false } }, "additionalProperties": false, "required": [ - "browserTarget", - "platform" + "browserTarget" ] } diff --git a/builders/cordova-serve/index.ts b/builders/cordova-serve/index.ts index f067353..f555d34 100644 --- a/builders/cordova-serve/index.ts +++ b/builders/cordova-serve/index.ts @@ -36,9 +36,9 @@ export class CordovaServeBuilder implements Builder { } protected _getCordovaBuildConfig(cordovaServeOptions: CordovaServeBuilderSchema): Observable> { - const { platform } = cordovaServeOptions; + const { platform, cordovaAssets, cordovaMock } = cordovaServeOptions; const [ project, target, configuration ] = cordovaServeOptions.cordovaBuildTarget.split(':'); - const cordovaBuildTargetSpec = { project, target, configuration, overrides: { platform } }; + const cordovaBuildTargetSpec = { project, target, configuration, overrides: { platform, cordovaAssets, cordovaMock } }; const cordovaBuildTargetConfig = this.context.architect.getBuilderConfiguration(cordovaBuildTargetSpec); return this.context.architect.getBuilderDescription(cordovaBuildTargetConfig).pipe( @@ -54,6 +54,7 @@ class CordovaDevServerBuilder extends DevServerBuilder { buildWebpackConfig(root: Path, projectRoot: Path, host: virtualFs.Host, browserOptions: NormalizedBrowserBuilderSchema) { const builder = new CordovaBuildBuilder(this.context); + builder.validateBuilderConfig(this.cordovaBuildOptions); builder.prepareBrowserConfig(this.cordovaBuildOptions, browserOptions); return super.buildWebpackConfig(root, projectRoot, host, browserOptions); diff --git a/builders/cordova-serve/schema.d.ts b/builders/cordova-serve/schema.d.ts index 7c2a183..c57680e 100644 --- a/builders/cordova-serve/schema.d.ts +++ b/builders/cordova-serve/schema.d.ts @@ -1,10 +1,12 @@ export interface CordovaServeBuilderSchema { cordovaBuildTarget: string; devServerTarget: string; - platform: string; + platform?: string; port?: number; host?: string; ssl?: boolean; cordovaBasePath?: string; sourceMap?: boolean; + cordovaAssets?: boolean; + cordovaMock?: boolean; } diff --git a/builders/cordova-serve/schema.json b/builders/cordova-serve/schema.json index 76a0958..00c08fc 100644 --- a/builders/cordova-serve/schema.json +++ b/builders/cordova-serve/schema.json @@ -37,12 +37,21 @@ "sourceMap": { "type": "boolean", "description": "Create source-map file" + }, + "cordovaAssets": { + "type": "boolean", + "description": "Bundle Cordova assets with build", + "default": true + }, + "cordovaMock": { + "type": "boolean", + "description": "Bundle empty cordova.js with build", + "default": false } }, "additionalProperties": false, "required": [ "cordovaBuildTarget", - "devServerTarget", - "platform" + "devServerTarget" ] } From bfd07ba2f8377d16e36d7c88f9c06d2cbe669f49 Mon Sep 17 00:00:00 2001 From: Tim Lancina Date: Mon, 28 Jan 2019 15:49:09 -0800 Subject: [PATCH 3/3] fix(build): override .gitignore to add mock cordova.js --- builders/cordova-build/cordova.js | 1 + 1 file changed, 1 insertion(+) create mode 100644 builders/cordova-build/cordova.js diff --git a/builders/cordova-build/cordova.js b/builders/cordova-build/cordova.js new file mode 100644 index 0000000..12ad702 --- /dev/null +++ b/builders/cordova-build/cordova.js @@ -0,0 +1 @@ +// mock cordova.js