@capawesome/cli 3.7.0-dev.24727dc.1764842591 → 3.7.0-dev.445ea3a.1764843317

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.
@@ -6,6 +6,7 @@ import { findCapacitorConfigPath, readCapacitorConfig } from '../../../utils/cap
6
6
  import { copyToClipboard } from '../../../utils/clipboard.js';
7
7
  import { fileExistsAtPath } from '../../../utils/file.js';
8
8
  import { checkOpensslInstalled, generateKeyPair, readPublicKey } from '../../../utils/openssl.js';
9
+ import { findPackageJsonPath, getCapacitorMajorVersion, isPackageInstalled } from '../../../utils/package-json.js';
9
10
  import { installPackage } from '../../../utils/package-manager.js';
10
11
  import { prompt } from '../../../utils/prompt.js';
11
12
  import { defineCommand, defineOptions } from '@robingenz/zli';
@@ -39,7 +40,7 @@ export default defineCommand({
39
40
  // Try to get from config first
40
41
  if (!appId && config?.plugins?.LiveUpdate?.appId) {
41
42
  appId = config.plugins.LiveUpdate.appId;
42
- consola.success(`Using existing app ID from Capacitor configuration: ${appId}`);
43
+ consola.info(`Found existing Capawesome Cloud app ID in Capacitor configuration: ${appId}`);
43
44
  }
44
45
  // Prompt if still not found
45
46
  if (!appId) {
@@ -85,33 +86,54 @@ export default defineCommand({
85
86
  process.exit(1);
86
87
  }
87
88
  }
88
- // Update config with app ID
89
- await updateCapacitorConfig(capacitorConfigPath, {
90
- plugins: {
91
- LiveUpdate: {
92
- appId,
89
+ if (!config?.plugins?.LiveUpdate?.appId) {
90
+ // Update config with app ID
91
+ await updateCapacitorConfig(capacitorConfigPath, {
92
+ plugins: {
93
+ LiveUpdate: {
94
+ appId,
95
+ },
93
96
  },
94
- },
95
- });
96
- consola.success(`Updated Capacitor configuration with app ID: ${appId}`);
97
+ });
98
+ consola.success(`Updated Capacitor configuration with Capawesome Cloud app ID: ${appId}`);
99
+ }
97
100
  // Step 4: Install SDK (Optional)
98
- // @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
99
- const shouldInstall = await prompt('Do you want to install the Live Update SDK?', {
100
- type: 'confirm',
101
- initial: true,
102
- });
103
- if (shouldInstall) {
101
+ const packageJsonPath = await findPackageJsonPath();
102
+ let sdkInstalled = false;
103
+ if (packageJsonPath) {
104
+ sdkInstalled = await isPackageInstalled(packageJsonPath, '@capawesome/capacitor-live-update');
105
+ if (sdkInstalled) {
106
+ consola.info('Live Update SDK is already installed.');
107
+ }
108
+ }
109
+ if (!sdkInstalled) {
104
110
  // @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
105
- const packageManager = await prompt('Select your package manager:', {
106
- type: 'select',
107
- options: [
108
- { label: 'npm', value: 'npm' },
109
- { label: 'yarn', value: 'yarn' },
110
- { label: 'pnpm', value: 'pnpm' },
111
- ],
111
+ const shouldInstall = await prompt('Do you want to install the Live Update SDK?', {
112
+ type: 'confirm',
113
+ initial: true,
112
114
  });
113
- await installPackage('@capawesome/capacitor-live-update', packageManager);
114
- consola.success('Live Update SDK installed successfully.');
115
+ if (shouldInstall) {
116
+ // Get Capacitor version to install matching plugin version
117
+ let packageName = '@capawesome/capacitor-live-update';
118
+ if (packageJsonPath) {
119
+ const capacitorMajorVersion = await getCapacitorMajorVersion(packageJsonPath);
120
+ if (capacitorMajorVersion) {
121
+ packageName = `@capawesome/capacitor-live-update@^${capacitorMajorVersion}.0.0`;
122
+ consola.info(`Installing plugin version ${capacitorMajorVersion} to match Capacitor ${capacitorMajorVersion}`);
123
+ }
124
+ }
125
+ // @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
126
+ const packageManager = await prompt('Select your package manager:', {
127
+ type: 'select',
128
+ options: [
129
+ { label: 'npm', value: 'npm' },
130
+ { label: 'yarn', value: 'yarn' },
131
+ { label: 'pnpm', value: 'pnpm' },
132
+ ],
133
+ });
134
+ await installPackage(packageName, packageManager);
135
+ consola.success('Live Update SDK installed successfully.');
136
+ }
115
137
  }
116
138
  // Step 5: Set Up Code Signing (Optional)
117
139
  // Reload config to get latest updates
@@ -56,3 +56,40 @@ export const getBuildScript = async (packageJsonPath) => {
56
56
  }
57
57
  return undefined;
58
58
  };
59
+ /**
60
+ * Check if a package is installed.
61
+ * Checks both dependencies and devDependencies.
62
+ *
63
+ * @param packageJsonPath The path to the package.json file.
64
+ * @param packageName The name of the package to check.
65
+ * @returns True if the package is installed, false otherwise.
66
+ */
67
+ export const isPackageInstalled = async (packageJsonPath, packageName) => {
68
+ const packageJson = await readPackageJson(packageJsonPath);
69
+ if (!packageJson) {
70
+ return false;
71
+ }
72
+ return !!(packageJson.dependencies?.[packageName] || packageJson.devDependencies?.[packageName]);
73
+ };
74
+ /**
75
+ * Get the Capacitor CLI version from package.json.
76
+ *
77
+ * @param packageJsonPath The path to the package.json file.
78
+ * @returns The Capacitor major version number, or undefined if not found.
79
+ */
80
+ export const getCapacitorMajorVersion = async (packageJsonPath) => {
81
+ const packageJson = await readPackageJson(packageJsonPath);
82
+ if (!packageJson) {
83
+ return undefined;
84
+ }
85
+ const capacitorVersion = packageJson.dependencies?.['@capacitor/core'] || packageJson.devDependencies?.['@capacitor/core'];
86
+ if (!capacitorVersion) {
87
+ return undefined;
88
+ }
89
+ // Extract major version from version string (e.g., "^5.0.0" -> 5, "~6.1.0" -> 6)
90
+ const match = capacitorVersion.match(/(\d+)/);
91
+ if (match && match[1]) {
92
+ return parseInt(match[1], 10);
93
+ }
94
+ return undefined;
95
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capawesome/cli",
3
- "version": "3.7.0-dev.24727dc.1764842591",
3
+ "version": "3.7.0-dev.445ea3a.1764843317",
4
4
  "description": "The Capawesome Cloud Command Line Interface (CLI) to manage Live Updates and more.",
5
5
  "type": "module",
6
6
  "scripts": {