@michaeltangseng/schemaai 0.0.1

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,148 @@
1
+ ## schemaAI 发布到 npm 的步骤
2
+
3
+ 本指南用于在本地构建完成后,将 `schemaAI` 包发布到 npm Registry。
4
+ 假设包名为:`@michaeltangseng/schemaai`。
5
+
6
+ > ⚠️ 建议在发布前先确认:包名未被他人占用、版本号符合预期、`dist/` 已成功生成。
7
+
8
+ ---
9
+
10
+ ## 1. 发布前检查清单
11
+
12
+ 在目录 `Others/utils-lib/npm-package` 下:
13
+
14
+ - **确认构建成功**
15
+ ```bash
16
+ pnpm run build # 或 npm run build
17
+ ```
18
+ - 预期:无 TypeScript 报错,生成 `dist/` 目录。
19
+
20
+ - **检查关键文件**
21
+ - `package.json`:
22
+ - `name`: `@michaeltangseng/schemaai`
23
+ - `version`: `0.0.1`(首次发布建议用 0.x,后续升级按 semver 调整)
24
+ - `main`, `module`, `types` 指向 `dist` 下文件。
25
+ - `author`, `license`, `description`, `keywords` 确认无误。
26
+ - `dist/`:
27
+ - 至少包含构建出的入口文件和类型声明(如 `index.js` / `index.d.ts` 等)。
28
+
29
+ - **确认忽略配置**
30
+ - 如果后续添加了 `.npmignore` 或通过 `package.json.files` 控制发布内容,需确保:
31
+ - `dist/` 被包含;
32
+ - 不必要的测试/配置文件可以排除。
33
+
34
+ ---
35
+
36
+ ## 2. npm 账号与登录
37
+
38
+ 在终端任意位置执行:
39
+
40
+ ```bash
41
+ npm login
42
+ ```
43
+
44
+ 按提示输入:
45
+
46
+ - npm 用户名
47
+ - 密码
48
+ - 邮箱验证码(如开启了 2FA,则按 npm 的 2FA 方式完成验证)
49
+
50
+ > 只需登录一次,后续在本机同一用户下发布同一 scope 的包时可复用登录状态。
51
+
52
+ ---
53
+
54
+ ## 3. 确认包名是否已被占用(可选但推荐)
55
+
56
+ 在浏览器或终端中检查:
57
+
58
+ - 浏览器访问:`https://www.npmjs.com/package/@michaeltangseng/schemaai`
59
+ - 如果返回 404,说明还未被占用,可以发布。
60
+
61
+ ---
62
+
63
+ ## 4. 实际发布命令
64
+
65
+ 在 `Others/utils-lib/npm-package` 目录下执行:
66
+
67
+ ```bash
68
+ npm publish --access public
69
+ ```
70
+
71
+ 说明:
72
+
73
+ - 若 `name` 使用了 scope(如 `@michaeltangseng/schemaai`),首次发布时必须显式加上 `--access public`。
74
+ - 发布过程会自动触发:
75
+ - `prepare` 脚本(`npm run build`),确保发布的是最新构建产物。
76
+
77
+ > 若发布过程中出现「2FA 相关提示」,按 npm 帐号配置完成额外验证码输入即可。
78
+
79
+ ---
80
+
81
+ ## 5. 发布成功后的验证
82
+
83
+ ### 5.1 在 npm 官网确认
84
+
85
+ - 打开浏览器访问:
86
+ `https://www.npmjs.com/package/@michaeltangseng/schemaai`
87
+ - 检查:
88
+ - README/描述是否正确(后续可在包根目录添加 `README.md` 并重新发布版本)。
89
+ - 版本号是否为刚发布的版本。
90
+
91
+ ### 5.2 在独立项目中安装验证
92
+
93
+ 新建或在已有前端项目中(不在当前 monorepo 内)执行:
94
+
95
+ ```bash
96
+ npm install @michaeltangseng/schemaai
97
+ # 或
98
+ pnpm add @michaeltangseng/schemaai
99
+ ```
100
+
101
+ 然后在代码中使用:
102
+
103
+ ```ts
104
+ import { schemaAIRenderer as SchemaAIRenderer } from '@michaeltangseng/schemaai';
105
+
106
+ const demoSchema = {
107
+ id: 'root',
108
+ type: 'Container',
109
+ props: { title: 'Hello schemaAI from npm' },
110
+ style: { padding: '16px' },
111
+ children: []
112
+ };
113
+
114
+ export function App() {
115
+ return <SchemaAIRenderer schema={demoSchema} />;
116
+ }
117
+ ```
118
+
119
+ 如果页面能正常渲染出容器和标题,说明 npm 包发布与使用流程已经闭环。
120
+
121
+ ---
122
+
123
+ ## 6. 版本升级与变更建议
124
+
125
+ - **版本号策略**:
126
+ - 早期快速迭代阶段使用 `0.x.y`,不保证完全稳定。
127
+ - 当 Public API(见 `docs/public-api.md`)相对稳定后,再发布 `1.0.0`。
128
+ - **每次发版前**:
129
+ 1. 更新 `package.json` 中的 `version`,遵循 semver(`patch`/`minor`/`major`)。
130
+ 2. 更新相关文档(如 `CHANGELOG`、`public-api.md`、`migrate-plan.md` 若涉及重大变更)。
131
+ 3. `pnpm run build` 确认通过。
132
+ 4. 执行 `npm publish --access public`。
133
+
134
+ ---
135
+
136
+ ## 7. 常见问题(简要)
137
+
138
+ - **Q:本地能 build,通过 `npm link` 也正常,为什么发布后安装报错?**
139
+ A:通常与发布内容不一致有关(如 `dist/` 未包含在 npm 包中,或入口字段 `main/module/types` 指向了不存在的文件)。
140
+ 建议发布前使用 `npm pack` 检查打包结果:
141
+ ```bash
142
+ npm pack
143
+ ```
144
+ 解压生成的 `.tgz`,检查其中包含的文件结构。
145
+
146
+ - **Q:想废弃某个版本怎么办?**
147
+ A:可以在 npm 官网将该版本标记为 deprecated,并在说明中提示用户升级到新的版本。
148
+
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@michaeltangseng/schemaai",
3
+ "version": "0.0.1",
4
+ "description": "schemaAI - React schema-driven low-code engine core (extracted from react-low-code-engine).",
5
+ "private": false,
6
+ "main": "dist/index.cjs",
7
+ "module": "dist/index.esm.js",
8
+ "types": "dist/index.d.ts",
9
+ "sideEffects": false,
10
+ "scripts": {
11
+ "build": "tsc -p tsconfig.build.json",
12
+ "clean": "rm -rf dist",
13
+ "prepare": "npm run build"
14
+ },
15
+ "peerDependencies": {
16
+ "react": "^18.0.0",
17
+ "react-dom": "^18.0.0"
18
+ },
19
+ "devDependencies": {
20
+ "typescript": "^5.6.3",
21
+ "@types/react": "^18.3.3",
22
+ "@types/react-dom": "^18.3.0"
23
+ },
24
+ "keywords": [
25
+ "schemaai",
26
+ "low-code",
27
+ "react",
28
+ "schema",
29
+ "renderer"
30
+ ],
31
+ "author": "michaeltangseng",
32
+ "license": "MIT"
33
+ }
34
+