create-secra 0.1.3 → 0.1.4

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/README.md CHANGED
@@ -27,6 +27,7 @@ npm create secra@latest my-app
27
27
  - `dist`
28
28
  - `.turbo`
29
29
  - `.git`
30
+ - The generated project's root `package.json` `name` is automatically updated from your target directory name.
30
31
  - After scaffolding, dependencies are installed automatically with your detected package manager (`pnpm`/`yarn`/`bun`/`npm`).
31
32
 
32
33
  ## Override Template Source
package/README.zh-CN.md CHANGED
@@ -27,6 +27,7 @@ npm create secra@latest my-app
27
27
  - `dist`
28
28
  - `.turbo`
29
29
  - `.git`
30
+ - 创建项目时会根据目标目录名自动更新根目录 `package.json` 的 `name` 字段。
30
31
  - 脚手架复制完成后,会自动根据当前环境识别包管理器并安装依赖(`pnpm`/`yarn`/`bun`/`npm`)。
31
32
 
32
33
  ## 临时覆盖模板目录
package/bin/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { spawn } from "node:child_process";
4
- import { cpSync, existsSync, readdirSync } from "node:fs";
4
+ import { cpSync, existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import path from "node:path";
7
7
  import process from "node:process";
@@ -18,6 +18,30 @@ function fail(message) {
18
18
  process.exit(1);
19
19
  }
20
20
 
21
+ function toPackageName(input) {
22
+ const normalized = input
23
+ .toLowerCase()
24
+ .replace(/[^a-z0-9-]+/g, "-")
25
+ .replace(/-+/g, "-")
26
+ .replace(/^-|-$/g, "");
27
+
28
+ return normalized || "secra-app";
29
+ }
30
+
31
+ function updatePackageName(cwd, name) {
32
+ const packageJsonPath = path.join(cwd, "package.json");
33
+ if (!existsSync(packageJsonPath)) return;
34
+
35
+ try {
36
+ const content = readFileSync(packageJsonPath, "utf8");
37
+ const json = JSON.parse(content);
38
+ json.name = toPackageName(name);
39
+ writeFileSync(packageJsonPath, `${JSON.stringify(json, null, 2)}\n`, "utf8");
40
+ } catch (error) {
41
+ fail(`Failed to update package name. ${error instanceof Error ? error.message : String(error)}`);
42
+ }
43
+ }
44
+
21
45
  function detectPackageManager() {
22
46
  const userAgent = process.env.npm_config_user_agent || "";
23
47
  if (userAgent.startsWith("pnpm")) return "pnpm";
@@ -76,6 +100,8 @@ async function main() {
76
100
  fail(`Failed to copy template. ${error instanceof Error ? error.message : String(error)}`);
77
101
  }
78
102
 
103
+ updatePackageName(targetPath, path.basename(targetPath));
104
+
79
105
  console.log(`[create-secra] Installing dependencies with ${manager} ...`);
80
106
  try {
81
107
  await runInstall(targetPath, manager);
@@ -85,7 +111,9 @@ async function main() {
85
111
 
86
112
  console.log(`[create-secra] Done. Next steps:`);
87
113
  console.log(` cd ${targetDir}`);
88
- console.log(` ${manager === "npm" ? "npm run dev" : `${manager} dev`}`);
114
+ console.log(` pnpm install`);
115
+ console.log(` pnpm -r --filter "./packages/*" build`);
116
+ console.log(` pnpm dev`);
89
117
  }
90
118
 
91
119
  main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-secra",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Create a Secra project from the official template.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -72,6 +72,7 @@ const Home = () => {
72
72
  }}
73
73
  >
74
74
  {`pnpm install
75
+ pnpm -r --filter "./packages/*" build
75
76
  pnpm dev`}
76
77
  </pre>
77
78
  </section>