create-next-imagicma 0.0.3 → 0.0.5

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
@@ -20,6 +20,7 @@ node ./create-next-imagicma/bin/create-next-imagicma.mjs demo-5001 --port 5001
20
20
 
21
21
  - `--port <number>`:设置新项目 `dev/start` 的默认端口(写入 `next ... -p <port>`)。
22
22
  - `--theme <name>`:设置新项目默认主题(可选:`quadratic`、`nomad`、`honey`、`zen-garden`、`highlighter`)。
23
+ - `-v, --version`:显示当前脚手架版本号。
23
24
  - 运行时仍可覆盖,例如:`pnpm dev -- -p 6001` 或 `PORT=6001 pnpm start`
24
25
 
25
26
  ## 依赖安装策略
@@ -16,6 +16,14 @@ const THEME_STYLES = [
16
16
  "highlighter",
17
17
  ];
18
18
 
19
+ const PACKAGE_JSON_PATH = path.resolve(__dirname, "..", "package.json");
20
+
21
+ async function getVersion() {
22
+ const raw = await fs.readFile(PACKAGE_JSON_PATH, "utf8");
23
+ const pkg = JSON.parse(raw);
24
+ return pkg.version ?? "0.0.0";
25
+ }
26
+
19
27
  function printHelp() {
20
28
  console.log(`create-next-imagicma <project-dir> [--port <1-65535>] [--theme <name>]
21
29
 
@@ -23,6 +31,7 @@ function printHelp() {
23
31
  --port <number> 设置新项目 dev/start 的默认端口(next ... -p)
24
32
  --theme <name> 设置默认主题(可选:${THEME_STYLES.join(", ")})
25
33
  -h, --help 显示帮助
34
+ -v, --version 显示版本号
26
35
  `);
27
36
  }
28
37
 
@@ -75,6 +84,10 @@ function parseArgs(argv) {
75
84
  return { help: true };
76
85
  }
77
86
 
87
+ if (arg === "-v" || arg === "--version") {
88
+ return { version: true };
89
+ }
90
+
78
91
  if (arg === "--port") {
79
92
  const value = argv[i + 1];
80
93
  if (!value) {
@@ -121,7 +134,7 @@ function parseArgs(argv) {
121
134
  throw new Error("缺少 <project-dir>:请指定要创建的项目目录名/路径");
122
135
  }
123
136
 
124
- return { projectDir, port, theme, help: false };
137
+ return { projectDir, port, theme, help: false, version: false };
125
138
  }
126
139
 
127
140
  async function ensureTargetDirReady(targetDir) {
@@ -286,6 +299,11 @@ async function main() {
286
299
  printHelp();
287
300
  return;
288
301
  }
302
+ if (parsed.version) {
303
+ const version = await getVersion();
304
+ console.log(version);
305
+ return;
306
+ }
289
307
 
290
308
  const { projectDir, port, theme } = parsed;
291
309
  const targetDir = path.resolve(process.cwd(), projectDir);
@@ -297,6 +315,14 @@ async function main() {
297
315
  force: true,
298
316
  errorOnExist: false,
299
317
  });
318
+ // npm publish 会默认排除 .gitignore,模板中以 gitignore 发布,此处还原为 .gitignore
319
+ const gitignoreSrc = path.join(targetDir, "gitignore");
320
+ try {
321
+ await fs.access(gitignoreSrc);
322
+ await fs.rename(gitignoreSrc, path.join(targetDir, ".gitignore"));
323
+ } catch {
324
+ // 无 gitignore 则跳过(如本地开发时仍保留 .gitignore 的情况)
325
+ }
300
326
  await updatePackageName(targetDir, port);
301
327
  await updateProcessComposePort(targetDir, port);
302
328
  await updateDefaultTheme(targetDir, theme);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-next-imagicma",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "create-next-imagicma": "./bin/create-next-imagicma.mjs"
@@ -0,0 +1,46 @@
1
+ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2
+
3
+ # dependencies
4
+ /node_modules
5
+ /.pnp
6
+ .pnp.*
7
+ .yarn/*
8
+ !.yarn/patches
9
+ !.yarn/plugins
10
+ !.yarn/releases
11
+ !.yarn/versions
12
+
13
+ # testing
14
+ /coverage
15
+
16
+ # next.js
17
+ /.next/
18
+ /out/
19
+
20
+ # production
21
+ /build
22
+
23
+ # misc
24
+ .DS_Store
25
+ *.pem
26
+
27
+ # debug
28
+ npm-debug.log*
29
+ yarn-debug.log*
30
+ yarn-error.log*
31
+ .pnpm-debug.log*
32
+
33
+ # npm
34
+ .npmrc
35
+ .npm-cache/
36
+
37
+ # env files (can opt-in for committing if needed)
38
+ .env*
39
+ !.env.example
40
+
41
+ # vercel
42
+ .vercel
43
+
44
+ # typescript
45
+ *.tsbuildinfo
46
+ next-env.d.ts