Skip to content

Commit 69b683b

Browse files
committed
feat(cli/web): pwa push notifications
1 parent be12d4c commit 69b683b

File tree

11 files changed

+1611
-222
lines changed

11 files changed

+1611
-222
lines changed

cli/package-lock.json

Lines changed: 52 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"main": "./dist/index.js",
1515
"scripts": {
1616
"build": "npm run clean && npm run assets && tsc",
17-
"clean": "rm -rf ./dist",
17+
"clean": "rimraf ./dist",
1818
"deploy": "np",
1919
"lint": "tslint --project tsconfig.json",
2020
"assets": "node scripts/copy-assets.js",
@@ -60,15 +60,18 @@
6060
"@types/fs-extra": "^4.0.5",
6161
"@types/inquirer": "0.0.35",
6262
"@types/jest": "^23.3.9",
63+
"@types/lodash": "^4.14.137",
6364
"@types/mock-fs": "^3.6.30",
6465
"@types/open": "^6.1.0",
6566
"@types/ora": "^1.3.1",
6667
"@types/semver": "^5.4.0",
6768
"@types/which": "^1.0.28",
6869
"@types/xml2js": "^0.4.2",
6970
"jest": "^23.6.0",
71+
"lodash": "^4.17.15",
7072
"mock-fs": "^4.4.2",
7173
"np": "^2.18.2",
74+
"rimraf": "^3.0.0",
7275
"tmp": "0.0.33",
7376
"ts-jest": "^23.10.4",
7477
"tslint": "^5.8.0",

cli/src/config.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { basename, join, resolve } from 'path';
33
import { logFatal, readJSON } from './common';
44
import { CliConfig, ExternalConfig, OS, PackageJson } from './definitions';
55
import { execSync } from 'child_process';
6+
import * as _ from 'lodash';
67

78
let Package: PackageJson;
89
let ExtConfig: ExternalConfig;
@@ -86,6 +87,20 @@ export class Config implements CliConfig {
8687
extConfigFilePath: '',
8788
extConfig: ExtConfig,
8889
bundledWebRuntime: false,
90+
serviceWorker: {
91+
name: 'capacitor-sw.js',
92+
firebaseConfig: {
93+
apiKey: '',
94+
authDomain: '',
95+
databaseURL: '',
96+
projectId: '',
97+
storageBucket: '',
98+
messagingSenderId: '',
99+
appId: '',
100+
vapidKey: ''
101+
},
102+
combineOtherWorker: ''
103+
},
89104
plugins: {},
90105
assets: {
91106
templateName: 'app-template',
@@ -227,7 +242,7 @@ export class Config implements CliConfig {
227242
private mergeConfigData() {
228243
const extConfig: ExternalConfig = this.app.extConfig || {};
229244

230-
Object.assign(this.app, extConfig);
245+
_.merge(this.app, extConfig);
231246

232247
// Build the absolute path to the web directory
233248
this.app.webDirAbs = resolve(this.app.rootDir, this.app.webDir);

cli/src/definitions.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export interface CliConfigApp {
8383
* module imports, set this to "true" and import "capacitor.js" manually.
8484
*/
8585
bundledWebRuntime: boolean;
86+
serviceWorker: CliConfigServiceWorker;
8687
assets: CliConfigPlatformAssets;
8788
}
8889

@@ -100,3 +101,20 @@ export interface CliConfig {
100101
app: CliConfigApp;
101102
plugins: CliConfigPlugins;
102103
}
104+
105+
export interface CliConfigServiceWorker {
106+
name: string;
107+
firebaseConfig: CliConfigFirebase;
108+
combineOtherWorker: string;
109+
}
110+
111+
export interface CliConfigFirebase {
112+
apiKey: string;
113+
authDomain: string;
114+
databaseURL: string;
115+
projectId: string;
116+
storageBucket: string;
117+
messagingSenderId: string;
118+
appId: string;
119+
vapidKey: string;
120+
}

cli/src/tasks/copy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export async function copy(config: Config, platformName: string) {
4141
await copyCapacitorConfig(config, join(config.android.platformDir, 'app/src/main/assets'));
4242
await copyCordovaJSFiles(config, platformName);
4343
} else if (platformName === config.web.name) {
44+
await copyCapacitorConfig(config, config.app.webDirAbs);
4445
await copyWeb(config);
4546
} else if (platformName === config.electron.name) {
4647
await copyElectron(config);

0 commit comments

Comments
 (0)