create-secra 0.1.2 → 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
@@ -1,6 +1,12 @@
1
1
  # create-secra
2
2
 
3
- Use this package to bootstrap a Secra frontend project:
3
+ Bootstrap a Secra frontend project from a built-in local template.
4
+
5
+ [中文文档](./README.zh-CN.md)
6
+
7
+ ## Usage
8
+
9
+ Create a project:
4
10
 
5
11
  ```bash
6
12
  pnpm create secra my-app
@@ -12,10 +18,36 @@ or
12
18
  npm create secra@latest my-app
13
19
  ```
14
20
 
15
- By default it uses the local `template` directory in this package.
21
+ ## Template Behavior
22
+
23
+ - Default template source: local `template/` directory in this package.
24
+ - No git clone / degit is used.
25
+ - Template copy excludes these directories:
26
+ - `node_modules`
27
+ - `dist`
28
+ - `.turbo`
29
+ - `.git`
30
+ - The generated project's root `package.json` `name` is automatically updated from your target directory name.
31
+ - After scaffolding, dependencies are installed automatically with your detected package manager (`pnpm`/`yarn`/`bun`/`npm`).
32
+
33
+ ## Override Template Source
16
34
 
17
- You can override the template directory temporarily:
35
+ You can temporarily point to another local template path:
18
36
 
19
37
  ```bash
20
38
  SECRA_TEMPLATE=/absolute/path/to/template pnpm create secra my-app
21
39
  ```
40
+
41
+ ## Maintain the Built-in Template
42
+
43
+ If you want to refresh `template/` from another project (for example `secra-front`), copy files with excludes:
44
+
45
+ ```bash
46
+ rsync -a --delete \
47
+ --exclude node_modules \
48
+ --exclude dist \
49
+ --exclude .turbo \
50
+ --exclude .git \
51
+ /path/to/source-project/ \
52
+ ./template/
53
+ ```
@@ -0,0 +1,53 @@
1
+ # create-secra
2
+
3
+ 基于内置本地模板快速创建 Secra 前端项目。
4
+
5
+ [English README](./README.md)
6
+
7
+ ## 使用方式
8
+
9
+ 创建项目:
10
+
11
+ ```bash
12
+ pnpm create secra my-app
13
+ ```
14
+
15
+
16
+
17
+ ```bash
18
+ npm create secra@latest my-app
19
+ ```
20
+
21
+ ## Template 功能说明
22
+
23
+ - 默认模板来源:当前包内的 `template/` 目录。
24
+ - 不使用 git clone / degit 拉取远程仓库。
25
+ - 复制模板时会自动排除以下目录:
26
+ - `node_modules`
27
+ - `dist`
28
+ - `.turbo`
29
+ - `.git`
30
+ - 创建项目时会根据目标目录名自动更新根目录 `package.json` 的 `name` 字段。
31
+ - 脚手架复制完成后,会自动根据当前环境识别包管理器并安装依赖(`pnpm`/`yarn`/`bun`/`npm`)。
32
+
33
+ ## 临时覆盖模板目录
34
+
35
+ 如需临时指定其他本地模板目录,可通过环境变量:
36
+
37
+ ```bash
38
+ SECRA_TEMPLATE=/absolute/path/to/template pnpm create secra my-app
39
+ ```
40
+
41
+ ## 维护内置模板
42
+
43
+ 如果你想从其他项目(例如 `secra-front`)更新 `template/`,可执行:
44
+
45
+ ```bash
46
+ rsync -a --delete \
47
+ --exclude node_modules \
48
+ --exclude dist \
49
+ --exclude .turbo \
50
+ --exclude .git \
51
+ /path/to/source-project/ \
52
+ ./template/
53
+ ```
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.2",
3
+ "version": "0.1.4",
4
4
  "description": "Create a Secra project from the official template.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,4 +1,84 @@
1
+ import type { CSSProperties } from "react";
2
+ import reactLogo from "../assets/react.svg";
3
+
4
+ const cardStyle: CSSProperties = {
5
+ border: "1px solid #e5e7eb",
6
+ borderRadius: 12,
7
+ padding: 16,
8
+ background: "#ffffff",
9
+ boxShadow: "0 6px 24px rgba(15, 23, 42, 0.06)",
10
+ };
11
+
1
12
  const Home = () => {
2
- return (<div>首页</div>);
13
+ return (
14
+ <main
15
+ style={{
16
+ minHeight: "100vh",
17
+ padding: "48px 20px",
18
+ background: "linear-gradient(180deg, #f8fafc 0%, #ffffff 100%)",
19
+ color: "#0f172a",
20
+ }}
21
+ >
22
+ <section style={{ maxWidth: 920, margin: "0 auto" }}>
23
+ <header style={{ display: "flex", alignItems: "center", gap: 16, marginBottom: 24 }}>
24
+ <img src={reactLogo} alt="React Logo" width={48} height={48} />
25
+ <div>
26
+ <h1 style={{ fontSize: 34, lineHeight: 1.2, margin: 0 }}>
27
+ React + Vite + Secra
28
+ </h1>
29
+ <p style={{ margin: "8px 0 0", color: "#475569" }}>
30
+ A fast starter template for modern frontend projects.
31
+ </p>
32
+ </div>
33
+ </header>
34
+
35
+ <div
36
+ style={{
37
+ display: "grid",
38
+ gridTemplateColumns: "repeat(auto-fit, minmax(220px, 1fr))",
39
+ gap: 14,
40
+ }}
41
+ >
42
+ <article style={cardStyle}>
43
+ <h3 style={{ marginTop: 0 }}>React</h3>
44
+ <p style={{ margin: 0, color: "#475569" }}>
45
+ Build component-based UI with a clean and maintainable structure.
46
+ </p>
47
+ </article>
48
+ <article style={cardStyle}>
49
+ <h3 style={{ marginTop: 0 }}>Vite</h3>
50
+ <p style={{ margin: 0, color: "#475569" }}>
51
+ Enjoy instant startup and fast HMR for daily development.
52
+ </p>
53
+ </article>
54
+ <article style={cardStyle}>
55
+ <h3 style={{ marginTop: 0 }}>Secra</h3>
56
+ <p style={{ margin: 0, color: "#475569" }}>
57
+ Structured app bootstrap, routing and engineering defaults out of the box.
58
+ </p>
59
+ </article>
60
+ </div>
61
+
62
+ <section style={{ ...cardStyle, marginTop: 18 }}>
63
+ <h2 style={{ marginTop: 0, fontSize: 20 }}>Quick Start</h2>
64
+ <pre
65
+ style={{
66
+ margin: 0,
67
+ padding: 14,
68
+ borderRadius: 8,
69
+ background: "#0f172a",
70
+ color: "#e2e8f0",
71
+ overflowX: "auto",
72
+ }}
73
+ >
74
+ {`pnpm install
75
+ pnpm -r --filter "./packages/*" build
76
+ pnpm dev`}
77
+ </pre>
78
+ </section>
79
+ </section>
80
+ </main>
81
+ );
3
82
  };
83
+
4
84
  export default Home;