@flowdevcli/flowdev 1.0.3 → 1.0.4
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 +1 -1
- package/src/commands/system/update.js +26 -13
- package/src/core/cli.js +6 -0
package/package.json
CHANGED
|
@@ -2,34 +2,47 @@ import chalk from "chalk";
|
|
|
2
2
|
import { execSync } from "child_process";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { fileURLToPath } from "url";
|
|
5
|
+
import fs from "fs-extra";
|
|
6
|
+
import ora from "ora";
|
|
5
7
|
|
|
6
8
|
const __filename = fileURLToPath(import.meta.url);
|
|
7
9
|
const __dirname = path.dirname(__filename);
|
|
8
10
|
|
|
9
11
|
export async function updateCommand() {
|
|
10
|
-
const spinner = ora(chalk.cyan('Checking for
|
|
12
|
+
const spinner = ora(chalk.cyan('Checking for updates...')).start();
|
|
11
13
|
|
|
12
14
|
try {
|
|
15
|
+
|
|
13
16
|
const packageJsonPath = path.resolve(__dirname, '../../../package.json');
|
|
14
|
-
const pkg = await
|
|
17
|
+
const pkg = await fs.readJson(packageJsonPath);
|
|
15
18
|
|
|
16
19
|
const currentVersion = pkg.version;
|
|
17
20
|
const packageName = pkg.name;
|
|
21
|
+
|
|
18
22
|
let latestVersion;
|
|
19
23
|
try {
|
|
20
|
-
latestVersion = execSync(`npm
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
latestVersion = execSync(`npm view ${packageName} version`, { encoding: 'utf-8' }).trim();
|
|
25
|
+
} catch (e) {
|
|
26
|
+
spinner.warn(chalk.yellow('Could not reach the npm registry.'));
|
|
27
|
+
return;
|
|
24
28
|
}
|
|
25
29
|
|
|
26
|
-
if (latestVersion
|
|
27
|
-
|
|
30
|
+
if (latestVersion === currentVersion) {
|
|
31
|
+
spinner.succeed(chalk.green(`FlowDev is up to date! (v${currentVersion})`));
|
|
32
|
+
} else {
|
|
33
|
+
spinner.info(chalk.yellow(`A new version is available: ${latestVersion} (Current: ${currentVersion})`));
|
|
34
|
+
|
|
35
|
+
const updateSpinner = ora(chalk.magenta('Updating FlowDev...')).start();
|
|
36
|
+
try {
|
|
37
|
+
|
|
38
|
+
execSync(`npm install -g ${packageName}@latest`, { stdio: 'ignore' });
|
|
39
|
+
updateSpinner.succeed(chalk.green(`FlowDev has been updated to v${latestVersion}! ✨`));
|
|
40
|
+
} catch (err) {
|
|
41
|
+
updateSpinner.fail(chalk.red('Update failed. Try running with sudo: sudo npm install -g @flowdevcli/flowdev'));
|
|
42
|
+
}
|
|
28
43
|
}
|
|
44
|
+
} catch (error) {
|
|
45
|
+
spinner.fail(chalk.red('An error occurred while checking for updates.'));
|
|
46
|
+
console.error(error);
|
|
29
47
|
}
|
|
30
|
-
|
|
31
|
-
catch(error){
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
48
|
}
|
package/src/core/cli.js
CHANGED
|
@@ -12,6 +12,7 @@ import { kubeCommand } from '../commands/devops/kube.js';
|
|
|
12
12
|
import { generateCommand } from '../commands/scaffold/generate.js';
|
|
13
13
|
import { auditCommand } from '../commands/ai/audit.js';
|
|
14
14
|
import { testCommand } from '../commands/ai/test.js';
|
|
15
|
+
import { updateCommand } from '../commands/system/update.js';
|
|
15
16
|
|
|
16
17
|
|
|
17
18
|
const require = createRequire(import.meta.url);
|
|
@@ -109,5 +110,10 @@ export function setupCLI() {
|
|
|
109
110
|
await testCommand(file);
|
|
110
111
|
});
|
|
111
112
|
|
|
113
|
+
program
|
|
114
|
+
.command('update')
|
|
115
|
+
.description('Update FlowDev to the latest version')
|
|
116
|
+
.action(updateCommand);
|
|
117
|
+
|
|
112
118
|
return program;
|
|
113
119
|
}
|