create-kecare 1.0.0-beta.1 → 1.0.0-beta.10
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/__VERSION__.mjs +1 -0
- package/index.mjs +30 -27
- package/package.json +1 -1
package/__VERSION__.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const __VERSION__ = '1.0.0-beta.10';
|
package/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
2
3
|
import { __VERSION__ } from './__VERSION__.mjs';
|
|
3
4
|
|
|
4
5
|
// Node.js
|
|
@@ -21,6 +22,7 @@ const color = gradient(['cyan', '#2d9b87']);
|
|
|
21
22
|
(async () => {
|
|
22
23
|
const args = process.argv.slice(2);
|
|
23
24
|
|
|
25
|
+
// oxlint-disable-next-line no-unused-vars
|
|
24
26
|
let version = 'latest';
|
|
25
27
|
let installPath = undefined;
|
|
26
28
|
|
|
@@ -40,7 +42,7 @@ const color = gradient(['cyan', '#2d9b87']);
|
|
|
40
42
|
const packageName = `kecare-${process.platform}-${os.arch()}`;
|
|
41
43
|
const selectedVersion = __VERSION__;
|
|
42
44
|
|
|
43
|
-
let
|
|
45
|
+
let selectedMirror = '';
|
|
44
46
|
consola.start(color('Finding the appropriate mirror..'));
|
|
45
47
|
|
|
46
48
|
const mirrors = [
|
|
@@ -61,25 +63,26 @@ const color = gradient(['cyan', '#2d9b87']);
|
|
|
61
63
|
if (!response.ok) continue;
|
|
62
64
|
const packageInfo = await response.json();
|
|
63
65
|
if (!packageInfo || !packageInfo['dist-tags'] || !packageInfo['dist-tags'].latest) continue;
|
|
64
|
-
|
|
66
|
+
selectedMirror = mirror;
|
|
65
67
|
consola.success(color(`Found version ${selectedVersion} at ${mirror}`));
|
|
66
68
|
break;
|
|
67
69
|
} catch (error) {
|
|
68
70
|
consola.warn(color(`Mirror unavailable: ${error.message}`));
|
|
69
71
|
}
|
|
70
72
|
}
|
|
71
|
-
if (!
|
|
73
|
+
if (!selectedMirror) {
|
|
72
74
|
consola.error(color('Failed to detect latest version from all mirrors'));
|
|
73
75
|
exit(1);
|
|
74
76
|
}
|
|
75
|
-
|
|
76
|
-
const downloadUrl = `${selectMirror}${packageName}/-/${packageName.split('/')[1]}-${selectedVersion}.tgz`;
|
|
77
|
+
const downloadUrl = `${selectedMirror}${packageName}/-/${packageName.split('/')[0]}-${selectedVersion}.tgz`;
|
|
77
78
|
consola.start(color(`Downloading package from ${downloadUrl}`));
|
|
78
79
|
try {
|
|
79
80
|
const res = await fetch(downloadUrl);
|
|
80
81
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
82
|
+
|
|
81
83
|
const destination = join(tempspace, `package.tgz`);
|
|
82
84
|
if (existsSync(destination)) await remove(destination);
|
|
85
|
+
|
|
83
86
|
const fileStream = createWriteStream(destination);
|
|
84
87
|
await finished(Readable.fromWeb(res.body).pipe(fileStream));
|
|
85
88
|
consola.success(color(`Package downloaded successfully`));
|
|
@@ -131,27 +134,27 @@ const color = gradient(['cyan', '#2d9b87']);
|
|
|
131
134
|
break;
|
|
132
135
|
}
|
|
133
136
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
137
|
+
if (!targetPath) {
|
|
138
|
+
targetPath = join(process.env.HOME, 'bin');
|
|
139
|
+
mkdirSync(targetPath, { recursive: true });
|
|
140
|
+
}
|
|
141
|
+
consola.info(`Installing to ${targetPath}`);
|
|
142
|
+
const targetFile = join(targetPath, 'kecare');
|
|
143
|
+
if (existsSync(targetFile)) rmSync(targetFile);
|
|
144
|
+
try {
|
|
145
|
+
consola.info(color(`Moving executable to PATH: ${targetPath}`));
|
|
146
|
+
await move(execPath, targetFile, { overwrite: true });
|
|
147
|
+
} catch (error) {
|
|
148
|
+
consola.error(color(`Installation failed: ${error?.message}`));
|
|
149
|
+
exit(1);
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
execFileSync('chmod', ['+x', targetFile]);
|
|
153
|
+
consola.success(color('Executable permissions set'));
|
|
154
|
+
} catch (error) {
|
|
155
|
+
consola.error(color(`Permission setting failed: ${error?.message}`));
|
|
156
|
+
exit(1);
|
|
157
|
+
}
|
|
155
158
|
}
|
|
156
159
|
}
|
|
157
160
|
consola.start(color('cleaning temporary files ...'));
|