@capgo/capacitor-pretty-toast 8.1.9 → 8.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-pretty-toast",
3
- "version": "8.1.9",
3
+ "version": "8.1.11",
4
4
  "description": "Native-first pretty toast notifications for Capacitor and the web",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -1,56 +1,96 @@
1
- #!/usr/bin/env bun
2
- import { spawnSync } from 'node:child_process';
1
+ #!/usr/bin/env node
3
2
  import { existsSync, readFileSync } from 'node:fs';
4
3
  import { dirname, resolve } from 'node:path';
5
4
  import { fileURLToPath } from 'node:url';
5
+ import { spawnSync } from 'node:child_process';
6
6
 
7
- const scriptDir = dirname(fileURLToPath(import.meta.url));
8
- const repoRoot = resolve(scriptDir, '..');
7
+ const __dirname = dirname(fileURLToPath(import.meta.url));
8
+ const repoRoot = resolve(__dirname, '..');
9
9
  const appDir = resolve(repoRoot, 'example-app');
10
- const distDir = resolve(appDir, 'dist');
11
- const packageJsonPath = resolve(appDir, 'package.json');
12
- const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
10
+ const rootPackageJson = JSON.parse(readFileSync(resolve(repoRoot, 'package.json'), 'utf8'));
11
+ const examplePackageJson = JSON.parse(readFileSync(resolve(appDir, 'package.json'), 'utf8'));
12
+ const configText = readFileSync(
13
+ existsSync(resolve(appDir, 'capacitor.config.ts'))
14
+ ? resolve(appDir, 'capacitor.config.ts')
15
+ : resolve(appDir, 'capacitor.config.json'),
16
+ 'utf8',
17
+ );
13
18
 
14
- const appId = process.env.CAPGO_APP_ID;
19
+ function readConfigString(key, fallback) {
20
+ const match = configText.match(new RegExp(`['"]?${key}['"]?\\s*[:=]\\s*['"]([^'"]+)['"]`));
21
+ return match?.[1] ?? fallback;
22
+ }
23
+
24
+ function runCapgo(args, allowFailure = false) {
25
+ const token = process.env.CAPGO_TOKEN;
26
+ const fullArgs = ['@capgo/cli@latest', ...args];
27
+ if (token) {
28
+ fullArgs.push('--apikey', token);
29
+ }
30
+ const result = spawnSync('bunx', fullArgs, {
31
+ cwd: repoRoot,
32
+ stdio: 'inherit',
33
+ env: process.env,
34
+ });
35
+ if (!allowFailure && result.status !== 0) {
36
+ process.exit(result.status ?? 1);
37
+ }
38
+ return result.status ?? 1;
39
+ }
40
+
41
+ const appId = process.env.CAPGO_APP_ID || readConfigString('appId');
42
+ const appName = process.env.CAPGO_APP_NAME || readConfigString('appName', rootPackageJson.name);
43
+ const webDir = process.env.CAPGO_WEB_DIR || readConfigString('webDir', 'dist');
44
+ const distDir = resolve(appDir, webDir);
15
45
  const channel = process.env.CAPGO_CHANNEL || process.argv[2] || 'production';
46
+ const bundle = process.env.CAPGO_BUNDLE || rootPackageJson.version || examplePackageJson.version;
16
47
  const comment =
17
48
  process.env.CAPGO_COMMENT ||
18
49
  (process.env.GITHUB_RUN_NUMBER
19
- ? `Pretty Toast example run ${process.env.GITHUB_RUN_NUMBER}`
20
- : `Pretty Toast example ${packageJson.version}`);
50
+ ? `${appName} run ${process.env.GITHUB_RUN_NUMBER}`
51
+ : `${appName} ${bundle}`);
52
+ const iconPath = process.env.CAPGO_ICON || resolve(appDir, 'assets', 'capgo-icon.png');
53
+
54
+ if (!appId) {
55
+ console.error('Missing Capgo app id. Set CAPGO_APP_ID or example-app/capacitor.config.* appId.');
56
+ process.exit(1);
57
+ }
21
58
 
22
59
  if (!existsSync(distDir)) {
23
- console.error('Missing example-app/dist. Run bun run --cwd example-app build first.');
60
+ console.error(`Missing example app bundle at ${distDir}. Run bun run example:build first.`);
24
61
  process.exit(1);
25
62
  }
26
63
 
27
- const args = [
28
- '@capgo/cli@latest',
64
+ const appArgs = [appId, '--name', appName];
65
+ if (existsSync(iconPath)) {
66
+ appArgs.push('--icon', iconPath);
67
+ }
68
+
69
+ const setStatus = runCapgo(['app', 'set', ...appArgs], true);
70
+ if (setStatus !== 0) {
71
+ runCapgo(['app', 'add', ...appArgs]);
72
+ }
73
+
74
+ console.log(`Deploying ${appId} to Capgo channel "${channel}"`);
75
+
76
+ runCapgo([
29
77
  'bundle',
30
78
  'upload',
31
- ...(appId ? [appId] : []),
79
+ appId,
80
+ '--bundle',
81
+ bundle,
32
82
  '--path',
33
- 'dist',
83
+ distDir,
34
84
  '--channel',
35
85
  channel,
36
86
  '--package-json',
37
- 'package.json,../package.json',
87
+ 'example-app/package.json,package.json',
38
88
  '--node-modules',
39
- '../node_modules,node_modules',
89
+ 'node_modules,example-app/node_modules',
40
90
  '--delta',
41
91
  '--no-key',
42
92
  '--ignore-checksum-check',
43
93
  '--version-exists-ok',
44
94
  '--comment',
45
95
  comment,
46
- ];
47
-
48
- console.log(`Deploying ${appId ?? 'Pretty Toast example'} to Capgo channel "${channel}"`);
49
-
50
- const result = spawnSync('bunx', args, {
51
- cwd: appDir,
52
- stdio: 'inherit',
53
- env: process.env,
54
- });
55
-
56
- process.exit(result.status ?? 1);
96
+ ]);