@jackie_qian/create-vue-app 1.0.0 → 1.0.2

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/cli.js CHANGED
@@ -22,6 +22,7 @@ import {
22
22
  installCommand,
23
23
  pathExists,
24
24
  run,
25
+ runCreateVue,
25
26
  writeFileEnsureDir,
26
27
  } from "./utils/util.js";
27
28
  import {
@@ -164,7 +165,7 @@ export async function main() {
164
165
  if (features.has("router")) flags.push("--router");
165
166
  if (features.has("pinia")) flags.push("--pinia");
166
167
  if (flags.length === 2) flags.push("--default");
167
- run("pnpm", ["dlx", "create-vue@latest", ...flags, projectName], cwd);
168
+ runCreateVue([...flags, projectName], cwd);
168
169
  s.stop("基础项目已生成");
169
170
  } catch (e) {
170
171
  s.stop("生成失败");
@@ -1,9 +1,9 @@
1
1
  export const FEATURES_OPTIONS = [
2
2
  { value: "router", label: "Router (SPA 开发)" },
3
3
  { value: "pinia", label: "Pinia (状态管理)" },
4
- { value: "piniaPersist", label: "Pinia 状态持久化" },
4
+ { value: "piniaPersist", label: "Pinia-plugin-persistedstate (状态持久化)" },
5
5
  { value: "sassEmbedded", label: "SassEmbedded" },
6
- { value: "eslintAntfu", label: "ESLint (Antfu 风格)" },
6
+ { value: "eslintAntfu", label: "ESLint (Antfu风格)" },
7
7
  { value: "stylelint", label: "Stylelint" },
8
8
  { value: "gitHooks", label: "GitHooks (simple-git-hooks + lint-staged)" },
9
9
  ];
@@ -1,14 +1,34 @@
1
1
  import { spawnSync } from "node:child_process";
2
2
  import { promises as fs } from "node:fs";
3
3
  import path from "node:path";
4
+ function spawnSyncCrossPlatform(cmd, args, options) {
5
+ let result = spawnSync(cmd, args, options);
6
+ if (process.platform !== "win32") return result;
7
+ const code = result.error?.code;
8
+ if (code !== "ENOENT") return result;
9
+ const base = path.basename(cmd);
10
+ const hasPathSeparators = cmd.includes("/") || cmd.includes("\\");
11
+ const hasExtension = /\.[a-z0-9]+$/i.test(base);
12
+ if (hasPathSeparators || hasExtension) return result;
13
+ result = spawnSync(`${cmd}.cmd`, args, options);
14
+ if (result.error?.code === "ENOENT")
15
+ result = spawnSync(`${cmd}.exe`, args, options);
16
+ return result;
17
+ }
4
18
  export function runCapture(cmd, args, cwd) {
5
- const result = spawnSync(cmd, args, { cwd, encoding: "utf8" });
6
- if (result.status !== 0) throw new Error(`${cmd} ${args.join(" ")} 执行失败`);
19
+ const result = spawnSyncCrossPlatform(cmd, args, { cwd, encoding: "utf8" });
20
+ if (result.status !== 0) {
21
+ const detail = result.error ? `: ${result.error.message}` : "";
22
+ throw new Error(`${cmd} ${args.join(" ")} 执行失败${detail}`);
23
+ }
7
24
  return `${result.stdout ?? ""}`.trim();
8
25
  }
9
26
  export function run(cmd, args, cwd) {
10
- const result = spawnSync(cmd, args, { cwd, stdio: "inherit" });
11
- if (result.status !== 0) throw new Error(`${cmd} ${args.join(" ")} 执行失败`);
27
+ const result = spawnSyncCrossPlatform(cmd, args, { cwd, stdio: "inherit" });
28
+ if (result.status !== 0) {
29
+ const detail = result.error ? `: ${result.error.message}` : "";
30
+ throw new Error(`${cmd} ${args.join(" ")} 执行失败${detail}`);
31
+ }
12
32
  }
13
33
  export function installCommand(pm) {
14
34
  if (pm === "pnpm") return { cmd: "pnpm", args: ["install"] };
@@ -166,3 +186,14 @@ export async function applyLatestStableRanges(pkg, cwd) {
166
186
  }
167
187
  }
168
188
  }
189
+ export function runCreateVue(flags, cwd) {
190
+ try {
191
+ run("pnpm", ["dlx", "create-vue@latest", ...flags], cwd);
192
+ return;
193
+ } catch {}
194
+ try {
195
+ run("npm", ["create", "vue@latest", ...flags], cwd);
196
+ return;
197
+ } catch {}
198
+ run("npx", ["--yes", "create-vue@latest", ...flags], cwd);
199
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jackie_qian/create-vue-app",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "dist/index.js",