@capgo/capacitor-pretty-toast 8.1.10 → 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.10",
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,71 +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 rootPackageJsonPath = resolve(repoRoot, 'package.json');
12
- const examplePackageJsonPath = resolve(appDir, 'package.json');
13
- const rootPackageJson = JSON.parse(readFileSync(rootPackageJsonPath, 'utf8'));
14
- const examplePackageJson = JSON.parse(readFileSync(examplePackageJsonPath, '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
+ );
15
18
 
16
- const toTitleCase = (value) =>
17
- value
18
- .split('-')
19
- .filter(Boolean)
20
- .map((part) => `${part.charAt(0).toUpperCase()}${part.slice(1)}`)
21
- .join(' ');
19
+ function readConfigString(key, fallback) {
20
+ const match = configText.match(new RegExp(`['"]?${key}['"]?\\s*[:=]\\s*['"]([^'"]+)['"]`));
21
+ return match?.[1] ?? fallback;
22
+ }
22
23
 
23
- const packageBaseName = rootPackageJson.name.split('/').pop() ?? examplePackageJson.name;
24
- const exampleName = `${toTitleCase(packageBaseName.replace(/^capacitor-/, ''))} example`;
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
+ }
25
40
 
26
- const appId = process.env.CAPGO_APP_ID;
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);
27
45
  const channel = process.env.CAPGO_CHANNEL || process.argv[2] || 'production';
28
46
  const bundle = process.env.CAPGO_BUNDLE || rootPackageJson.version || examplePackageJson.version;
29
47
  const comment =
30
48
  process.env.CAPGO_COMMENT ||
31
49
  (process.env.GITHUB_RUN_NUMBER
32
- ? `${exampleName} run ${process.env.GITHUB_RUN_NUMBER}`
33
- : `${exampleName} ${bundle}`);
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
+ }
34
58
 
35
59
  if (!existsSync(distDir)) {
36
- 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.`);
37
61
  process.exit(1);
38
62
  }
39
63
 
40
- const args = [
41
- '@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([
42
77
  'bundle',
43
78
  'upload',
44
- ...(appId ? [appId] : []),
79
+ appId,
45
80
  '--bundle',
46
81
  bundle,
47
82
  '--path',
48
- 'dist',
83
+ distDir,
49
84
  '--channel',
50
85
  channel,
51
86
  '--package-json',
52
- 'package.json,../package.json',
87
+ 'example-app/package.json,package.json',
53
88
  '--node-modules',
54
- '../node_modules,node_modules',
89
+ 'node_modules,example-app/node_modules',
55
90
  '--delta',
56
91
  '--no-key',
57
92
  '--ignore-checksum-check',
58
93
  '--version-exists-ok',
59
94
  '--comment',
60
95
  comment,
61
- ];
62
-
63
- console.log(`Deploying ${appId ?? exampleName} to Capgo channel "${channel}"`);
64
-
65
- const result = spawnSync('bunx', args, {
66
- cwd: appDir,
67
- stdio: 'inherit',
68
- env: process.env,
69
- });
70
-
71
- process.exit(result.status ?? 1);
96
+ ]);