Skip to content

Commit 2e8741b

Browse files
author
perlinson
committed
Move CLI to packages directory and update publishing workflow
📦 Package Architecture: - Move modernx-cli from root/ to packages/modernx-cli - Update CLI version to 1.0.2 for consistency - Add CLI to automated publishing workflow 🚀 Publishing Updates: - Add modernx-cli to npm-publish.yml workflow - Update verification step to include CLI package - Update GitHub Release notes to include all 5 packages 📋 Final Package Structure: packages/ ├── modernx-core/ # Core Redux + Redux-Saga ├── modernx/ # React integration ├── modernx-immer/ # Immer plugin ├── modernx-loading/ # Loading plugin └── modernx-cli/ # CLI tool ✅ Benefits: - Unified package management - Consistent versioning - Complete monorepo structure - Automated publishing for all packages
1 parent 83dd558 commit 2e8741b

30 files changed

Lines changed: 212 additions & 3 deletions

.github/workflows/npm-publish.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ jobs:
6060
npm publish --access public
6161
cd ../..
6262
63+
echo "Publishing modernx..."
64+
cd packages/modernx
65+
npm publish --access public
66+
cd ../..
67+
6368
echo "Publishing modernx-immer..."
6469
cd packages/modernx-immer
6570
npm publish --access public
@@ -70,8 +75,8 @@ jobs:
7075
npm publish --access public
7176
cd ../..
7277
73-
echo "Publishing modernx..."
74-
cd packages/modernx
78+
echo "Publishing modernx-cli..."
79+
cd packages/modernx-cli
7580
npm publish --access public
7681
cd ../..
7782
env:
@@ -84,6 +89,7 @@ jobs:
8489
npm view modernx-core@$(node -p "require('./packages/modernx-core/package.json').version")
8590
npm view modernx-immer@$(node -p "require('./packages/modernx-immer/package.json').version")
8691
npm view modernx-loading@$(node -p "require('./packages/modernx-loading/package.json').version")
92+
npm view modernx-cli@$(node -p "require('./packages/modernx-cli/package.json').version")
8793
8894
- name: Create GitHub Release
8995
uses: actions/create-release@v1
@@ -100,6 +106,7 @@ jobs:
100106
- modernx-core@$(node -p "require('./packages/modernx-core/package.json').version")
101107
- modernx-immer@$(node -p "require('./packages/modernx-immer/package.json').version")
102108
- modernx-loading@$(node -p "require('./packages/modernx-loading/package.json').version")
109+
- modernx-cli@$(node -p "require('./packages/modernx-cli/package.json').version")
103110
104111
### 📋 Changes
105112
See [CHANGELOG.md](https://github.com/perlinson/modernx/blob/main/CHANGELOG.md) for detailed changes.

cli/package.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/FIRST_TIME_PUBLISHING.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# 首次发布到 NPM 指南
2+
3+
## 🚨 当前问题
4+
5+
发布失败,错误信息:
6+
```
7+
npm notice Access token expired or revoked. Please try logging in again.
8+
npm error code E404
9+
npm error 404 Not Found - PUT https://registry.npmjs.org/modernx-core - Not found
10+
```
11+
12+
## 🔍 问题分析
13+
14+
1. **404 Not Found**: 包名在 NPM 上不存在(首次发布)
15+
2. **Token 过期**: Access Token 可能已过期或被撤销
16+
3. **权限问题**: Token 可能没有发布权限
17+
18+
## 🔧 解决步骤
19+
20+
### 步骤 1: 重新生成 NPM Access Token
21+
22+
1. 登录 [NPM](https://www.npmjs.com)
23+
2. 点击右上角头像 → **Account Settings**
24+
3. 左侧菜单点击 **Access Tokens**
25+
4. **删除所有旧 Token**(如果有的话)
26+
5. 点击 **Generate New Token**
27+
6. 选择 **Automation** 类型
28+
7. 输入 Token 名称:`modernx-github-actions`
29+
8. 点击 **Generate Token**
30+
9. **立即复制新 Token**
31+
32+
### 步骤 2: 更新 GitHub Secret
33+
34+
1. 访问 https://github.com/perlinson/modernx/settings/secrets/actions
35+
2. 找到 `NPM_TOKEN` secret
36+
3. 点击 **Update**
37+
4. 粘贴新的 Token
38+
5. 点击 **Save**
39+
40+
### 步骤 3: 手动首次发布(推荐)
41+
42+
由于是首次发布,建议手动发布一次:
43+
44+
```bash
45+
# 登录 NPM
46+
npm login
47+
48+
# 发布 modernx-core
49+
cd packages/modernx-core
50+
npm publish --access public
51+
52+
# 发布 modernx-immer
53+
cd ../modernx-immer
54+
npm publish --access public
55+
56+
# 发布 modernx-loading
57+
cd ../modernx-loading
58+
npm publish --access public
59+
60+
# 发布 modernx
61+
cd ../modernx
62+
npm publish --access public
63+
```
64+
65+
### 步骤 4: 验证发布
66+
67+
```bash
68+
# 检查包是否存在
69+
npm view modernx-core
70+
npm view modernx-immer
71+
npm view modernx-loading
72+
npm view modernx
73+
```
74+
75+
### 步骤 5: 测试自动发布
76+
77+
手动发布成功后,测试自动发布:
78+
79+
```bash
80+
# 删除测试标签
81+
git tag -d v1.0.3-test
82+
git push origin :v1.0.3-test
83+
84+
# 创建新标签
85+
git tag v1.0.3-test
86+
git push origin v1.0.3-test
87+
```
88+
89+
## 📋 首次发布注意事项
90+
91+
### 包名检查
92+
确保包名在 NPM 上是唯一的:
93+
- modernx
94+
- modernx-core
95+
- modernx-immer
96+
- modernx-loading
97+
98+
### 权限检查
99+
确认你有以下权限:
100+
- 发布新包的权限
101+
- 更新现有包的权限
102+
103+
### 版本检查
104+
确认版本号正确:
105+
- 首次发布必须是有效版本号(如 1.0.2)
106+
- 不能是 0.0.0 或无效版本
107+
108+
## 🚀 发布成功后
109+
110+
首次发布成功后:
111+
112+
1. **自动发布生效**: 后续版本可以自动发布
113+
2. **GitHub Actions**: 不再需要手动干预
114+
3. **版本管理**: 可以使用 `npm run release:patch`
115+
116+
## 🆘 故障排除
117+
118+
### Token 仍然无效
119+
- 检查 Token 类型是否为 Automation
120+
- 确认 Token 没有过期
121+
- 重新生成新的 Token
122+
123+
### 包名冲突
124+
- 访问 https://www.npmjs.com/search?q=modernx-core
125+
- 如果包名被占用,需要更改包名
126+
127+
### 权限不足
128+
- 联系 NPM 支持团队
129+
- 检查账号状态
130+
131+
---
132+
133+
完成首次发布后,自动发布就会正常工作了!🎉
File renamed without changes.

packages/modernx-cli/package.json

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"name": "modernx-cli",
3+
"version": "1.0.2",
4+
"description": "The modernx command line utility.",
5+
"repository": {
6+
"type": "git",
7+
"url": "https://github.com/perlinson/modernx.git"
8+
},
9+
"homepage": "https://github.com/perlinson/modernx#readme",
10+
"author": "perlinson <perlinson2024@gmail.com>",
11+
"license": "MIT",
12+
"bin": {
13+
"modernx": "./bin/modernx"
14+
},
15+
"scripts": {
16+
"build": "rm -rf lib && babel src --out-dir lib",
17+
"dev": "babel src --out-dir lib --watch",
18+
"test": "node test/cli.test.js"
19+
},
20+
"dependencies": {
21+
"chalk": "^4.1.2",
22+
"commander": "^9.4.1",
23+
"fs-extra": "^11.1.1",
24+
"inquirer": "^9.1.4",
25+
"path-exists": "^5.0.0",
26+
"through2": "^4.0.2",
27+
"update-notifier": "^6.0.2",
28+
"vinyl-fs": "^3.0.3",
29+
"which": "^3.0.1",
30+
"ora": "^6.3.1",
31+
"semver": "^7.5.4",
32+
"handlebars": "^4.7.8"
33+
},
34+
"devDependencies": {
35+
"@babel/cli": "^7.22.15",
36+
"@babel/core": "^7.22.17",
37+
"@babel/preset-env": "^7.22.15",
38+
"babel-plugin-add-module-exports": "^1.0.4"
39+
},
40+
"babel": {
41+
"presets": [
42+
[
43+
"@babel/preset-env",
44+
{
45+
"targets": {
46+
"node": "14"
47+
}
48+
}
49+
]
50+
],
51+
"plugins": [
52+
"add-module-exports"
53+
]
54+
},
55+
"files": [
56+
"lib",
57+
"src",
58+
"templates",
59+
"bin"
60+
],
61+
"keywords": [
62+
"modernx",
63+
"react",
64+
"react18",
65+
"cli",
66+
"generator",
67+
"scaffold",
68+
"state-management"
69+
]
70+
}

0 commit comments

Comments
 (0)