create-cookbook 1.0.0-beta.17 → 1.0.0-beta.171

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.
@@ -0,0 +1 @@
1
+ export const __VERSION__ = "1.0.0-beta.171";
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" ? join(process.env.USERPROFILE, ".cookbook") : join(process.env.HOME, ".cookbook");
31
- const tempspace = process.platform === "win32" ? join(process.env.USERPROFILE, ".cookbook", ".temp") : join(process.env.HOME, ".cookbook", ".temp");
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 uiName = "@milkio/cookbook-ui";
36
- const cookbookName = `@milkio/cookbook-${process.platform}-${os.arch()}`;
37
- let uiPackageInfo;
38
- let cookbookPackageInfo;
39
- console.log("");
40
- for (const mirror of ["https://registry.npmjs.org/", "https://registry.npmmirror.com/", "https://mirrors.cloud.tencent.com/npm/", "https://cdn.jsdelivr.net/npm/"]) {
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.start(color(`[1/2] Checking (${mirror}${uiName})..`));
53
+ consola.info(color(`Trying mirror: ${mirror}`));
43
54
  const controller = new AbortController();
44
- const timeout = setTimeout(() => controller.abort(), 8000);
45
- const response = await fetch(`${mirror}${uiName}`, {
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
- if (response.status !== 200) continue;
50
- const json = await response.json();
51
- if (json.name !== uiName) continue;
52
- uiPackageInfo = {
53
- mirror,
54
- json,
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
- // biome-ignore lint/correctness/noUnnecessaryContinue: <explanation>
59
- continue;
70
+ consola.warn(color(`Mirror unavailable: ${error.message}`));
60
71
  }
61
72
  }
62
- if (!uiPackageInfo) {
63
- consola.error(color("Network connection failed!"));
73
+
74
+ if (!selectedMirror) {
75
+ consola.error(color("Failed to detect latest version from all mirrors"));
64
76
  exit(1);
65
77
  }
66
- for (const mirror of ["https://registry.npmjs.org/", "https://registry.npmmirror.com/", "https://mirrors.cloud.tencent.com/npm/", "https://cdn.jsdelivr.net/npm/"]) {
67
- try {
68
- consola.start(color(`[2/2] Checking (${mirror}${cookbookName})..`));
69
- const controller = new AbortController();
70
- const timeout = setTimeout(() => controller.abort(), 8000);
71
- const response = await fetch(`${mirror}${cookbookName}`, {
72
- signal: controller.signal,
73
- });
74
- clearTimeout(timeout);
75
- if (response.status !== 200) continue;
76
- const json = await response.json();
77
- if (json.name !== cookbookName) continue;
78
- cookbookPackageInfo = {
79
- mirror,
80
- json,
81
- };
82
- break;
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
- if (!cookbookPackageInfo) {
89
- consola.error(color("Network connection failed!"));
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 uiUrl = `${cookbookPackageInfo.mirror}${uiName}/-/cookbook-ui-${version === "latest" ? uiPackageInfo.json["dist-tags"].latest : version}.tgz`;
94
- consola.start(uiUrl);
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
- console.log("");
123
- consola.info(color("Try run: co version"));
124
- consola.info(colorLong("* If you find that the co command does not exist, try restarting your Terminal or System"));
125
- })();
126
-
127
- const utils = {
128
- downloadFile: async (url, workspace, filename) => {
129
- const res = await fetch(url);
130
- if (existsSync(join(workspace, filename))) await remove(join(workspace, filename));
131
- const destination = join(workspace, filename);
132
- const fileStream = createWriteStream(destination, { flags: "wx" });
133
- await finished(Readable.fromWeb(res.body).pipe(fileStream));
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
- await new Promise((resolve) => setTimeout(resolve, 500));
171
- if (!(process.env.PATH.includes(`${join(process.env.USERPROFILE, ".cookbook")};`) || process.env.PATH.includes(`;${join(process.env.USERPROFILE, ".cookbook")}`) || process.env.PATH === `${join(process.env.USERPROFILE, ".cookbook")}`)) {
172
- await utils.executePowershell(`[System.Environment]::SetEnvironmentVariable("PATH", [System.Environment]::GetEnvironmentVariable("PATH", "User") + ";${join(process.env.USERPROFILE, ".cookbook")}", "User");`);
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
- if (!existsSync(process.env.USERPROFILE, ".cookbook")) mkdirSync(process.env.USERPROFILE, ".cookbook");
175
- if (existsSync(join(process.env.USERPROFILE, ".cookbook", filename))) rmSync(join(process.env.USERPROFILE, ".cookbook", filename));
176
- await utils.executePowershell(`Move-Item -Path "${join(workspace, filename)}" -Destination "${join(process.env.USERPROFILE, ".cookbook")}";`);
177
- return;
178
- }
179
- if (process.platform === "linux") {
180
- const paths = [join(process.env.HOME, ".bin"), "/usr/bin/", "/usr/sbin"];
181
- let pathChecked = "";
182
- for (const path of paths) {
183
- if (process.env.PATH.includes(`${path}:`) || process.env.PATH.includes(`:${path}`) || process.env.PATH === `${path}`) {
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
- if (!pathChecked) {
189
- consola.error(color("No path found!"));
190
- exit(0);
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
- if (!pathChecked) {
210
- consola.error(color("No path found!"));
211
- exit(0);
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
- if (!existsSync(pathChecked)) mkdirSync(pathChecked);
214
- if (existsSync(join(pathChecked, filename))) {
215
- if (pathChecked.startsWith("/Users")) await utils.executeBash(`rm -f ${join(pathChecked, filename)}`);
216
- else await utils.executeBash(`rm -f ${join(pathChecked, filename)}`);
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
- executePowershell: async (script) => {
223
- return execFileSync("powershell.exe", ["-c", script], {
224
- stdio: "inherit",
225
- });
226
- },
227
- executeBash: (script) => {
228
- return execFileSync("bash", ["-c", `if command -v sudo &>/dev/null; then sudo ${script}; else ${script}; fi`], {
229
- stdio: "inherit",
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-cookbook",
3
- "version": "1.0.0-beta.17",
3
+ "version": "1.0.0-beta.171",
4
4
  "main": "index.mjs",
5
5
  "bin": {
6
6
  "create-cookbook": "./index.mjs"
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
+ }