runcloud 0.1.95 → 0.1.97
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/dist/commands/update.js +66 -0
- package/dist/index.js +4 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { promisify } from 'node:util';
|
|
3
|
+
import { CLI_VERSION } from '../version.js';
|
|
4
|
+
export const PACKAGE_NAME = '@newly/cli';
|
|
5
|
+
export const UPDATE_COMMAND = `npm install -g ${PACKAGE_NAME}@latest`;
|
|
6
|
+
const defaultExec = async (file, args) => {
|
|
7
|
+
const { stdout } = await promisify(execFile)(file, args, { encoding: 'utf8' });
|
|
8
|
+
return { stdout };
|
|
9
|
+
};
|
|
10
|
+
function errorText(error) {
|
|
11
|
+
if (error && typeof error === 'object') {
|
|
12
|
+
const stderr = error.stderr;
|
|
13
|
+
if (typeof stderr === 'string' && stderr.trim())
|
|
14
|
+
return stderr.trim();
|
|
15
|
+
}
|
|
16
|
+
return error instanceof Error ? error.message : String(error);
|
|
17
|
+
}
|
|
18
|
+
export async function latestPublishedVersion(exec) {
|
|
19
|
+
const { stdout } = await exec('npm', ['view', `${PACKAGE_NAME}@latest`, 'version']);
|
|
20
|
+
return stdout.trim();
|
|
21
|
+
}
|
|
22
|
+
export async function updateCli(deps = {}) {
|
|
23
|
+
const exec = deps.exec ?? defaultExec;
|
|
24
|
+
const log = deps.log ?? ((message) => console.log(message));
|
|
25
|
+
const current = deps.currentVersion ?? CLI_VERSION;
|
|
26
|
+
let latest;
|
|
27
|
+
try {
|
|
28
|
+
latest = await latestPublishedVersion(exec);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
throw new Error(`Could not reach the npm registry to check for updates: ${errorText(error)}\n` +
|
|
32
|
+
`Run \`${UPDATE_COMMAND}\` to update by hand.`);
|
|
33
|
+
}
|
|
34
|
+
if (!latest) {
|
|
35
|
+
throw new Error(`The npm registry did not report a version for ${PACKAGE_NAME}.\n` +
|
|
36
|
+
`Run \`${UPDATE_COMMAND}\` to update by hand.`);
|
|
37
|
+
}
|
|
38
|
+
if (latest === current) {
|
|
39
|
+
log(`Already on the latest version (${current}).`);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
log(`Updating ${PACKAGE_NAME} ${current} → ${latest}…`);
|
|
43
|
+
try {
|
|
44
|
+
await exec('npm', ['install', '-g', `${PACKAGE_NAME}@latest`]);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
throw new Error(`Update failed: ${errorText(error)}\n` + `Run \`${UPDATE_COMMAND}\` to update by hand.`);
|
|
48
|
+
}
|
|
49
|
+
log(`Updated to ${latest}.`);
|
|
50
|
+
}
|
|
51
|
+
export function registerUpdate(program) {
|
|
52
|
+
program.option('-u, --update', 'update this CLI to the latest published version');
|
|
53
|
+
program.action(async () => {
|
|
54
|
+
if (program.opts().update !== true) {
|
|
55
|
+
program.help();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
await updateCli();
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
63
|
+
process.exitCode = 1;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -19,9 +19,11 @@ import { registerDiagnose } from './diagnose.js';
|
|
|
19
19
|
import { registerDesktop } from './commands/desktop.js';
|
|
20
20
|
import { registerEnvironment } from './commands/environment.js';
|
|
21
21
|
import { registerAppStore } from './commands/appStore.js';
|
|
22
|
+
import { registerUpdate } from './commands/update.js';
|
|
23
|
+
import { CLI_VERSION } from './version.js';
|
|
22
24
|
const program = new Command('newly')
|
|
23
25
|
.description('Develop, provision, and deploy Newly backends')
|
|
24
|
-
.version(
|
|
26
|
+
.version(CLI_VERSION);
|
|
25
27
|
registerLogin(program);
|
|
26
28
|
registerStatus(program);
|
|
27
29
|
registerLink(program);
|
|
@@ -41,4 +43,5 @@ registerDiagnose(program);
|
|
|
41
43
|
registerDesktop(program);
|
|
42
44
|
registerEnvironment(program);
|
|
43
45
|
registerAppStore(program);
|
|
46
|
+
registerUpdate(program);
|
|
44
47
|
await program.parseAsync(process.argv);
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLI_VERSION = '0.1.
|
|
1
|
+
export const CLI_VERSION = '0.1.97';
|