create-cookbook 1.0.0-beta.18 → 1.0.0-beta.181
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 +138 -176
- package/package.json +1 -1
- package/tsconfig.json +27 -27
package/__VERSION__.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const __VERSION__ = "1.0.0-beta.181";
|
package/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
import { __VERSION__ } from "./__VERSION__.mjs";
|
|
3
4
|
import os from "node:os";
|
|
4
5
|
import { join } from "node:path";
|
|
5
6
|
import { exit } from "node:process";
|
|
@@ -12,11 +13,11 @@ import consola from "consola";
|
|
|
12
13
|
import gradient from "gradient-string";
|
|
13
14
|
import compressing from "compressing";
|
|
14
15
|
|
|
15
|
-
const colorLong = gradient(["cyan", "green"]);
|
|
16
16
|
const color = gradient(["cyan", "#2d9b87"]);
|
|
17
17
|
|
|
18
18
|
(async () => {
|
|
19
19
|
const args = process.argv.slice(2);
|
|
20
|
+
// oxlint-disable-next-line no-unused-vars
|
|
20
21
|
let version = "latest";
|
|
21
22
|
let installPath = undefined;
|
|
22
23
|
for (const arg of args) {
|
|
@@ -27,206 +28,167 @@ const color = gradient(["cyan", "#2d9b87"]);
|
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
const workspace = process.platform === "win32"
|
|
31
|
-
|
|
31
|
+
const workspace = process.platform === "win32"
|
|
32
|
+
? join(process.env.USERPROFILE, ".cookbook")
|
|
33
|
+
: join(process.env.HOME, ".cookbook");
|
|
34
|
+
|
|
35
|
+
const tempspace = join(workspace, ".temp");
|
|
32
36
|
if (!existsSync(workspace)) mkdirSync(workspace);
|
|
33
37
|
if (!existsSync(tempspace)) mkdirSync(tempspace);
|
|
34
38
|
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
let
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
const packageName = `@milkio/cookbook-${process.platform}-${os.arch()}`;
|
|
40
|
+
const selectedVersion = __VERSION__;
|
|
41
|
+
let selectedMirror = "";
|
|
42
|
+
|
|
43
|
+
consola.start(color("Finding the appropriate mirror.."));
|
|
44
|
+
const mirrors = [
|
|
45
|
+
"https://registry.npmjs.org/",
|
|
46
|
+
"https://registry.npmmirror.com/",
|
|
47
|
+
"https://mirrors.cloud.tencent.com/npm/",
|
|
48
|
+
"https://cdn.jsdelivr.net/npm/"
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
for (const mirror of mirrors) {
|
|
41
52
|
try {
|
|
42
|
-
consola.
|
|
53
|
+
consola.info(color(`Trying mirror: ${mirror}`));
|
|
43
54
|
const controller = new AbortController();
|
|
44
|
-
const timeout = setTimeout(() => controller.abort(),
|
|
45
|
-
const response = await fetch(`${mirror}${
|
|
55
|
+
const timeout = setTimeout(() => controller.abort(), 5000);
|
|
56
|
+
const response = await fetch(`${mirror}${packageName}`, {
|
|
46
57
|
signal: controller.signal,
|
|
47
58
|
});
|
|
48
59
|
clearTimeout(timeout);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
60
|
+
|
|
61
|
+
if (!response.ok) continue;
|
|
62
|
+
|
|
63
|
+
const packageInfo = await response.json();
|
|
64
|
+
if (!packageInfo || !packageInfo["dist-tags"] || !packageInfo["dist-tags"].latest) continue;
|
|
65
|
+
|
|
66
|
+
selectedMirror = mirror;
|
|
67
|
+
consola.success(color(`Found version ${selectedVersion} at ${mirror}`));
|
|
56
68
|
break;
|
|
57
69
|
} catch (error) {
|
|
58
|
-
|
|
59
|
-
continue;
|
|
70
|
+
consola.warn(color(`Mirror unavailable: ${error.message}`));
|
|
60
71
|
}
|
|
61
72
|
}
|
|
62
|
-
|
|
63
|
-
|
|
73
|
+
|
|
74
|
+
if (!selectedMirror) {
|
|
75
|
+
consola.error(color("Failed to detect latest version from all mirrors"));
|
|
64
76
|
exit(1);
|
|
65
77
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
} catch (error) {
|
|
84
|
-
// biome-ignore lint/correctness/noUnnecessaryContinue: <explanation>
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
78
|
+
|
|
79
|
+
const downloadUrl = `${selectedMirror}${packageName}/-/${packageName.split('/')[1]}-${selectedVersion}.tgz`;
|
|
80
|
+
consola.start(color(`Downloading package from ${downloadUrl}`));
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
const res = await fetch(downloadUrl);
|
|
84
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
85
|
+
|
|
86
|
+
const destination = join(tempspace, "package.tgz");
|
|
87
|
+
if (existsSync(destination)) await remove(destination);
|
|
88
|
+
|
|
89
|
+
const fileStream = createWriteStream(destination);
|
|
90
|
+
await finished(Readable.fromWeb(res.body).pipe(fileStream));
|
|
91
|
+
consola.success(color("Package downloaded successfully"));
|
|
92
|
+
} catch (error) {
|
|
93
|
+
consola.error(color(`Download failed: ${error.message}`));
|
|
94
|
+
exit(1);
|
|
87
95
|
}
|
|
88
|
-
|
|
89
|
-
|
|
96
|
+
|
|
97
|
+
consola.start(color("Extracting package.."));
|
|
98
|
+
try {
|
|
99
|
+
await compressing.tgz.uncompress(join(tempspace, "package.tgz"), tempspace);
|
|
100
|
+
consola.success(color("Package extracted"));
|
|
101
|
+
} catch (error) {
|
|
102
|
+
consola.error(color(`Extraction failed: ${error.message}`));
|
|
90
103
|
exit(1);
|
|
91
104
|
}
|
|
92
105
|
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
consola.start(color(`[1/2] Downloading Cookbook UI (${uiUrl})..`));
|
|
96
|
-
await utils.downloadFile(uiUrl, tempspace, "ui.tgz");
|
|
97
|
-
consola.success(color("[1/2] Downloaded!"));
|
|
98
|
-
const uiExtractPromise = (async () => {
|
|
99
|
-
if (!existsSync(join(tempspace, "ui"))) mkdirSync(join(tempspace, "ui"));
|
|
100
|
-
await compressing.tgz.uncompress(join(tempspace, "ui.tgz"), join(tempspace, "ui"));
|
|
101
|
-
})();
|
|
102
|
-
|
|
103
|
-
const cookbookUrl = `${cookbookPackageInfo.mirror}${cookbookName}/-/cookbook-${process.platform}-${os.arch()}-${version === "latest" ? cookbookPackageInfo.json["dist-tags"].latest : version}.tgz`;
|
|
104
|
-
consola.start(cookbookUrl);
|
|
105
|
-
consola.start(color(`[2/2] Downloading Cookbook Core (${cookbookUrl})..`));
|
|
106
|
-
await utils.downloadFile(cookbookUrl, tempspace, "cookbook.tgz");
|
|
107
|
-
consola.success(color("[2/2] Downloaded!"));
|
|
108
|
-
const cookbookExtractPromise = (async () => {
|
|
109
|
-
await compressing.tgz.uncompress(join(tempspace, "cookbook.tgz"), tempspace);
|
|
110
|
-
})();
|
|
111
|
-
|
|
112
|
-
consola.start(color("[1/2] Extracting.."));
|
|
113
|
-
await Promise.all([uiExtractPromise, cookbookExtractPromise]);
|
|
114
|
-
consola.success(color("[1/2] Extracted!"));
|
|
115
|
-
|
|
116
|
-
consola.success(color("[2/2] Installing.."));
|
|
117
|
-
await utils.mvToPathAndInstall(installPath, join(tempspace, "package"), process.platform === "win32" ? "co.exe" : "co");
|
|
118
|
-
await utils.mvUIDir(join(tempspace, "ui", "package"));
|
|
119
|
-
await utils.tempspaceClean(tempspace);
|
|
120
|
-
consola.success(color("[2/2] Installed!"));
|
|
106
|
+
const execName = process.platform === "win32" ? "co.exe" : "co";
|
|
107
|
+
const execPath = join(tempspace, "package", execName);
|
|
121
108
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
mvUIDir: async (tempspace) => {
|
|
136
|
-
if (!existsSync(process.env.HOME || process.env.USERPROFILE, ".cookbook")) mkdirSync(join(process.env.HOME || process.env.USERPROFILE, ".cookbook"));
|
|
137
|
-
if (process.platform === "win32") {
|
|
138
|
-
if (existsSync(join(process.env.USERPROFILE, ".cookbook", "ui"))) await utils.executePowershell(`Remove-Item -Recurse -Force "${join(process.env.USERPROFILE, ".cookbook", "ui")}";`);
|
|
139
|
-
await utils.executePowershell(`Move-Item -Path "${join(tempspace)}" -Destination "${join(process.env.USERPROFILE, ".cookbook", "ui")}" -Force;`);
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
if (process.platform === "linux") {
|
|
143
|
-
if (existsSync(join(process.env.HOME, ".cookbook", "ui"))) await utils.executeBash(`rm -rf "${join(process.env.HOME, ".cookbook", "ui")}";`);
|
|
144
|
-
await utils.executeBash(`mv "${join(tempspace)}" "${join(process.env.HOME, ".cookbook", "ui")}"`);
|
|
145
|
-
}
|
|
146
|
-
if (process.platform === "darwin") {
|
|
147
|
-
if (existsSync(join(process.env.HOME, ".cookbook", "ui"))) await utils.executeBash(`rm -rf "${join(process.env.HOME, ".cookbook", "ui")}";`);
|
|
148
|
-
await utils.executeBash(`mv "${join(tempspace)}" "${join(process.env.HOME, ".cookbook", "ui")}"`);
|
|
149
|
-
}
|
|
150
|
-
},
|
|
151
|
-
tempspaceClean: async (tempspace) => {
|
|
152
|
-
if (process.platform === "win32") {
|
|
153
|
-
if (existsSync(join(tempspace))) await utils.executePowershell(`Remove-Item -Recurse -Force "${join(tempspace)}";`);
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
if (process.platform === "linux") {
|
|
157
|
-
if (existsSync(join(tempspace))) await utils.executeBash(`rm -rf "${join(tempspace)}"`);
|
|
158
|
-
}
|
|
159
|
-
if (process.platform === "darwin") {
|
|
160
|
-
if (existsSync(join(tempspace))) await utils.executeBash(`rm -rf "${join(tempspace)}"`);
|
|
161
|
-
}
|
|
162
|
-
},
|
|
163
|
-
mvToPathAndInstall: async (installPath, workspace, filename) => {
|
|
164
|
-
if (installPath) {
|
|
165
|
-
if (!existsSync(installPath)) mkdirSync(installPath, { recursive: true });
|
|
166
|
-
await move(join(workspace, filename), join(installPath, filename), { overwrite: true });
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
109
|
+
if (!existsSync(execPath)) {
|
|
110
|
+
consola.error(color("Executable not found in package"));
|
|
111
|
+
exit(1);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (installPath) {
|
|
115
|
+
consola.start(color(`Installing to custom path: ${installPath}`));
|
|
116
|
+
if (!existsSync(installPath)) mkdirSync(installPath, { recursive: true });
|
|
117
|
+
await move(execPath, join(installPath, execName), { overwrite: true });
|
|
118
|
+
} else {
|
|
119
|
+
consola.start(color("Finding suitable installation location.."));
|
|
120
|
+
|
|
121
|
+
let targetPath = "";
|
|
169
122
|
if (process.platform === "win32") {
|
|
170
|
-
|
|
171
|
-
if (!(
|
|
172
|
-
|
|
123
|
+
targetPath = join(process.env.USERPROFILE, ".cookbook");
|
|
124
|
+
if (!existsSync(targetPath)) mkdirSync(targetPath);
|
|
125
|
+
|
|
126
|
+
consola.info(color(`Installing to ${targetPath}`));
|
|
127
|
+
await move(execPath, join(targetPath, execName), { overwrite: true });
|
|
128
|
+
|
|
129
|
+
try {
|
|
130
|
+
execFileSync("powershell.exe", [
|
|
131
|
+
"-Command",
|
|
132
|
+
`[System.Environment]::SetEnvironmentVariable('PATH', $env:PATH + ';${targetPath}', 'User')`
|
|
133
|
+
]);
|
|
134
|
+
consola.success(color("Added to PATH (requires restart)"));
|
|
135
|
+
} catch {
|
|
136
|
+
consola.warn(color("Manual PATH configuration required"));
|
|
173
137
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
pathChecked = path;
|
|
138
|
+
} else {
|
|
139
|
+
const searchPaths = [
|
|
140
|
+
join(process.env.HOME, "bin"),
|
|
141
|
+
join(process.env.HOME, ".local", "bin"),
|
|
142
|
+
"/usr/local/bin"
|
|
143
|
+
];
|
|
144
|
+
|
|
145
|
+
for (const path of searchPaths) {
|
|
146
|
+
if (existsSync(path)) {
|
|
147
|
+
targetPath = path;
|
|
185
148
|
break;
|
|
186
149
|
}
|
|
187
150
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
if (!existsSync(pathChecked)) mkdirSync(pathChecked);
|
|
193
|
-
if (existsSync(join(pathChecked, filename))) {
|
|
194
|
-
if (pathChecked.startsWith("/home")) await utils.executeBash(`rm -f ${join(pathChecked, filename)}`);
|
|
195
|
-
else await utils.executeBash(`rm -f ${join(pathChecked, filename)}`);
|
|
196
|
-
}
|
|
197
|
-
if (pathChecked.startsWith("/home")) await utils.executeBash(`mv ${join(workspace, filename)} ${pathChecked} && chmod +x ${join(pathChecked, filename)}`);
|
|
198
|
-
else await utils.executeBash(`mv ${join(workspace, filename)} ${pathChecked} && chmod +x ${join(pathChecked, filename)}`);
|
|
199
|
-
}
|
|
200
|
-
if (process.platform === "darwin") {
|
|
201
|
-
const paths = [join(process.env.HOME, "bin"), join(process.env.HOME, ".bin"), join(process.env.HOME, ".local", "bin"), "/usr/local/bin"];
|
|
202
|
-
let pathChecked = "";
|
|
203
|
-
for (const path of paths) {
|
|
204
|
-
if (process.env.PATH.includes(`${path}:`) || process.env.PATH.includes(`:${path}`) || process.env.PATH === `${path}`) {
|
|
205
|
-
pathChecked = path;
|
|
206
|
-
break;
|
|
207
|
-
}
|
|
151
|
+
|
|
152
|
+
if (!targetPath) {
|
|
153
|
+
targetPath = join(process.env.HOME, "bin");
|
|
154
|
+
mkdirSync(targetPath, { recursive: true });
|
|
208
155
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
156
|
+
|
|
157
|
+
consola.info(color(`Installing to ${targetPath}`));
|
|
158
|
+
const targetFile = join(targetPath, "co");
|
|
159
|
+
if (existsSync(targetFile)) rmSync(targetFile);
|
|
160
|
+
|
|
161
|
+
try {
|
|
162
|
+
consola.info(color(`Moving executable to PATH: ${targetPath}`));
|
|
163
|
+
await move(execPath, targetFile, { overwrite: true });
|
|
164
|
+
} catch (error) {
|
|
165
|
+
consola.error(color(`Installation failed: ${error?.message}`));
|
|
166
|
+
exit(1);
|
|
212
167
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
168
|
+
|
|
169
|
+
try {
|
|
170
|
+
execFileSync("chmod", ["+x", targetFile]);
|
|
171
|
+
consola.success(color("Executable permissions set"));
|
|
172
|
+
} catch (error) {
|
|
173
|
+
consola.error(color(`Permission setting failed: ${error?.message}`));
|
|
174
|
+
exit(1);
|
|
217
175
|
}
|
|
218
|
-
if (pathChecked.startsWith("/Users")) await utils.executeBash(`mv ${join(workspace, filename)} ${pathChecked} && chmod +x ${join(pathChecked, filename)}`);
|
|
219
|
-
else await utils.executeBash(`mv ${join(workspace, filename)} ${pathChecked} && chmod +x ${join(pathChecked, filename)}`);
|
|
220
176
|
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
consola.start(color("Cleaning temporary files.."));
|
|
180
|
+
try {
|
|
181
|
+
await remove(tempspace);
|
|
182
|
+
consola.success(color("Installation complete"));
|
|
183
|
+
} catch (error) {
|
|
184
|
+
consola.warn(color(`Cleanup failed: ${error.message}`));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
console.log("");
|
|
188
|
+
consola.success(color("Cookbook installed successfully!"))
|
|
189
|
+
|
|
190
|
+
console.log(color("△ Try running: co --version"));
|
|
191
|
+
if (process.platform === "win32") {
|
|
192
|
+
console.log(color("△ Note: You may need to restart your terminal for PATH changes to take effect"));
|
|
193
|
+
}
|
|
194
|
+
})();
|
package/package.json
CHANGED
package/tsconfig.json
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
// Enable latest features
|
|
4
|
-
"lib": ["ESNext", "DOM"],
|
|
5
|
-
"target": "ESNext",
|
|
6
|
-
"module": "ESNext",
|
|
7
|
-
"moduleDetection": "force",
|
|
8
|
-
"jsx": "react-jsx",
|
|
9
|
-
"allowJs": true,
|
|
10
|
-
|
|
11
|
-
// Bundler mode
|
|
12
|
-
"moduleResolution": "bundler",
|
|
13
|
-
"allowImportingTsExtensions": true,
|
|
14
|
-
"verbatimModuleSyntax": true,
|
|
15
|
-
"noEmit": true,
|
|
16
|
-
|
|
17
|
-
// Best practices
|
|
18
|
-
"strict": true,
|
|
19
|
-
"skipLibCheck": true,
|
|
20
|
-
"noFallthroughCasesInSwitch": true,
|
|
21
|
-
|
|
22
|
-
// Some stricter flags (disabled by default)
|
|
23
|
-
"noUnusedLocals": false,
|
|
24
|
-
"noUnusedParameters": false,
|
|
25
|
-
"noPropertyAccessFromIndexSignature": false
|
|
26
|
-
}
|
|
27
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
// Enable latest features
|
|
4
|
+
"lib": ["ESNext", "DOM"],
|
|
5
|
+
"target": "ESNext",
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"moduleDetection": "force",
|
|
8
|
+
"jsx": "react-jsx",
|
|
9
|
+
"allowJs": true,
|
|
10
|
+
|
|
11
|
+
// Bundler mode
|
|
12
|
+
"moduleResolution": "bundler",
|
|
13
|
+
"allowImportingTsExtensions": true,
|
|
14
|
+
"verbatimModuleSyntax": true,
|
|
15
|
+
"noEmit": true,
|
|
16
|
+
|
|
17
|
+
// Best practices
|
|
18
|
+
"strict": true,
|
|
19
|
+
"skipLibCheck": true,
|
|
20
|
+
"noFallthroughCasesInSwitch": true,
|
|
21
|
+
|
|
22
|
+
// Some stricter flags (disabled by default)
|
|
23
|
+
"noUnusedLocals": false,
|
|
24
|
+
"noUnusedParameters": false,
|
|
25
|
+
"noPropertyAccessFromIndexSignature": false
|
|
26
|
+
}
|
|
27
|
+
}
|