ono-cli 0.0.3 → 0.1.0
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/LICENSE +21 -0
- package/README.md +176 -1
- package/bin/commands/config.js +1 -75
- package/bin/commands/create.js +1 -224
- package/bin/commands/update.js +1 -0
- package/bin/constants.js +1 -1
- package/bin/index.js +1 -34
- package/bin/pkg.js +1 -7
- package/bin/utils/getAllConfig.js +1 -0
- package/bin/utils/index.js +1 -0
- package/bin/utils/loading.js +1 -17
- package/bin/utils/processExit.js +1 -0
- package/bin/utils/project.js +1 -75
- package/package.json +47 -37
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ono
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1 +1,176 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ono-cli - 项目脚手架工具
|
|
2
|
+
|
|
3
|
+
一个简单易用的项目脚手架工具,帮助你快速创建项目,支持多种技术栈模板。
|
|
4
|
+
|
|
5
|
+
## 🚀 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g ono-cli
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 💡 快速使用(无需安装)
|
|
12
|
+
|
|
13
|
+
不想全局安装?你可以直接使用 npx 运行 ono-cli:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npx ono-cli create <project-name>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
这种方式无需安装,直接运行最新版本的 ono-cli 来创建项目。
|
|
20
|
+
|
|
21
|
+
## 📖 使用指南
|
|
22
|
+
|
|
23
|
+
### 1. 配置脚手架
|
|
24
|
+
|
|
25
|
+
在使用脚手架前,需要先配置仓库源、组织和访问令牌:
|
|
26
|
+
|
|
27
|
+
**配置仓库源(GitHub 或 Gitee):**
|
|
28
|
+
```bash
|
|
29
|
+
ono-cli config -r
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**配置组织名称:**
|
|
33
|
+
```bash
|
|
34
|
+
ono-cli config -s organization <YOUR ORGANIZATION NAME>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**配置访问令牌:**
|
|
38
|
+
```bash
|
|
39
|
+
ono-cli config -s access_token <YOUR ACCESS TOKEN>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
**选择使用模式:**
|
|
43
|
+
```bash
|
|
44
|
+
ono-cli config -m
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
> **提示:** 一般选择`模板选择模式`,如果选择`依赖性选择模式`,则需要将仓库中的模板名称改成与选项相对应的名称。
|
|
48
|
+
|
|
49
|
+
#### 关于`依赖性选择模式`的说明
|
|
50
|
+
|
|
51
|
+
例如,如果你选择了`react`、`ts`、`zustand`、`unocss`等技术栈,那么你需要在仓库中创建一个名为 `react-ts-zustand-unocss` 的模板。
|
|
52
|
+
|
|
53
|
+
### 2. 创建项目
|
|
54
|
+
|
|
55
|
+
配置完成后,即可使用脚手架创建新项目:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
ono-cli create [YOUR PROJECT NAME]
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### 3. 查看配置
|
|
62
|
+
|
|
63
|
+
如果需要查看当前的配置信息,可以使用以下命令:
|
|
64
|
+
|
|
65
|
+
**查看组织配置:**
|
|
66
|
+
```bash
|
|
67
|
+
ono-cli config -g organization
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
**查看访问令牌:**
|
|
71
|
+
```bash
|
|
72
|
+
ono-cli config -g access_token
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
**查看仓库源:**
|
|
76
|
+
```bash
|
|
77
|
+
ono-cli config -g repo
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
**查看使用模式:**
|
|
81
|
+
```bash
|
|
82
|
+
ono-cli config -g mode
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### 4. 更新脚手架
|
|
86
|
+
|
|
87
|
+
当有新版本时,可以使用以下命令更新:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
ono-cli update [version]
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
> 如果不指定版本号,将自动更新到最新版本。
|
|
94
|
+
|
|
95
|
+
## 🔧 如何创建组织和访问令牌
|
|
96
|
+
|
|
97
|
+
### GitHub
|
|
98
|
+
|
|
99
|
+
#### 创建组织
|
|
100
|
+
|
|
101
|
+
1. 登录 GitHub 账户
|
|
102
|
+
2. 点击右上角的头像,选择 "Your organizations"
|
|
103
|
+
3. 点击 "New organization" 按钮
|
|
104
|
+
4. 选择组织类型(Free 或 Team)
|
|
105
|
+
5. 输入组织名称和联系方式
|
|
106
|
+
6. 点击 "Create an organization" 完成创建
|
|
107
|
+
|
|
108
|
+
#### 创建访问令牌
|
|
109
|
+
|
|
110
|
+
1. 登录 GitHub 账户
|
|
111
|
+
2. 点击右上角的头像,选择 "Settings"
|
|
112
|
+
3. 在左侧边栏中,点击 "Developer settings"
|
|
113
|
+
4. 在 "Developer settings" 页面中,点击 "Personal access tokens" → "Tokens (classic)"
|
|
114
|
+
5. 点击 "Generate new token" 按钮
|
|
115
|
+
6. 输入令牌描述(Note)
|
|
116
|
+
7. 设置过期时间(Expiration)
|
|
117
|
+
8. 为令牌分配权限(Scopes):
|
|
118
|
+
- 对于访问私有仓库,至少需要 [repo](file://d:\GitWarehouse\gitee\ono-cli\src\utils\getAllConfig.ts#L8-L8) 权限
|
|
119
|
+
- 如果要访问组织仓库,还需要 `admin:org` 或 `read:org` 权限
|
|
120
|
+
- 如果访问的是私有仓库,还需要 `read:org` 权限
|
|
121
|
+
9. 点击 "Generate token" 按钮
|
|
122
|
+
10. 复制生成的令牌并妥善保存(一旦离开页面就无法再次查看)
|
|
123
|
+
|
|
124
|
+
### Gitee
|
|
125
|
+
|
|
126
|
+
#### 创建组织
|
|
127
|
+
|
|
128
|
+
1. 登录 Gitee 账户
|
|
129
|
+
2. 点击右上角的头像,选择 "组织"
|
|
130
|
+
3. 点击 "创建组织"
|
|
131
|
+
4. 输入组织名称、组织简介等信息
|
|
132
|
+
5. 选择组织类型(公开或私有)
|
|
133
|
+
6. 点击 "创建组织" 完成创建
|
|
134
|
+
|
|
135
|
+
#### 创建访问令牌
|
|
136
|
+
|
|
137
|
+
1. 登录 Gitee 账户
|
|
138
|
+
2. 点击右上角的头像,选择 "设置"
|
|
139
|
+
3. 在左侧边栏中,点击 "私人令牌"
|
|
140
|
+
4. 点击 "生成新令牌" 按钮
|
|
141
|
+
5. 输入令牌名称和过期时间
|
|
142
|
+
6. 为令牌分配权限:
|
|
143
|
+
- 对于访问仓库,需要选择 `projects` 权限
|
|
144
|
+
- 对于访问组织信息,需要选择 `organizations` 权限
|
|
145
|
+
7. 点击 "生成令牌" 按钮
|
|
146
|
+
8. 复制生成的令牌并妥善保存(一旦离开页面就无法再次查看)
|
|
147
|
+
|
|
148
|
+
## 💡 模式说明
|
|
149
|
+
|
|
150
|
+
### 模板选择模式
|
|
151
|
+
|
|
152
|
+
- 直接从可用的模板列表中选择一个模板
|
|
153
|
+
- 适合对模板有明确选择的场景
|
|
154
|
+
|
|
155
|
+
### 依赖性选择模式
|
|
156
|
+
|
|
157
|
+
- 根据选择的技术栈自动匹配相应的模板
|
|
158
|
+
- 模板命名需要遵循特定规则(如 `react-ts-zustand`)
|
|
159
|
+
- 适合根据技术栈自动选择模板的场景
|
|
160
|
+
|
|
161
|
+
## 🔧 故障排除
|
|
162
|
+
|
|
163
|
+
如果遇到问题,请检查:
|
|
164
|
+
|
|
165
|
+
1. 确保已经正确配置了组织名称和访问令牌
|
|
166
|
+
2. 确保模板仓库名称与配置的组织匹配
|
|
167
|
+
3. 检查网络连接是否正常
|
|
168
|
+
4. 如果使用私有仓库,请确保访问令牌具有相应权限
|
|
169
|
+
|
|
170
|
+
## 🤝 贡献
|
|
171
|
+
|
|
172
|
+
欢迎提交 Issue 和 Pull Request 来帮助改进 ono-cli!
|
|
173
|
+
|
|
174
|
+
## 📄 许可证
|
|
175
|
+
|
|
176
|
+
MIT
|
package/bin/commands/config.js
CHANGED
|
@@ -1,75 +1 @@
|
|
|
1
|
-
var __awaiter = (
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
11
|
-
import { decode, encode } from "ini";
|
|
12
|
-
import inquirer from "inquirer";
|
|
13
|
-
import { configPath } from "../constants.js";
|
|
14
|
-
export default (value, option) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
-
const { exists, config } = getAllConfig();
|
|
16
|
-
const action = Object.keys(option)[0];
|
|
17
|
-
const key = option[action];
|
|
18
|
-
if (action === 'get') {
|
|
19
|
-
console.log(config[key]);
|
|
20
|
-
}
|
|
21
|
-
else if (action === 'set') {
|
|
22
|
-
config[key] = value;
|
|
23
|
-
writeFileSync(configPath, encode(config));
|
|
24
|
-
}
|
|
25
|
-
else if (action === 'delete') {
|
|
26
|
-
delete config[key];
|
|
27
|
-
if (exists)
|
|
28
|
-
writeFileSync(configPath, encode(config));
|
|
29
|
-
}
|
|
30
|
-
else if (action === 'repo') {
|
|
31
|
-
const { repo } = yield inquirer.prompt([
|
|
32
|
-
{
|
|
33
|
-
name: 'repo',
|
|
34
|
-
type: 'list', // list, input, confirm, checkbox, rawlist, expand
|
|
35
|
-
message: '选择仓库',
|
|
36
|
-
choices: [{
|
|
37
|
-
name: 'github',
|
|
38
|
-
value: 'github'
|
|
39
|
-
}, {
|
|
40
|
-
name: 'gitee',
|
|
41
|
-
value: 'gitee'
|
|
42
|
-
}]
|
|
43
|
-
}
|
|
44
|
-
]);
|
|
45
|
-
config.repo = repo;
|
|
46
|
-
writeFileSync(configPath, encode(config));
|
|
47
|
-
}
|
|
48
|
-
else if (action === 'mode') {
|
|
49
|
-
const { mode } = yield inquirer.prompt([
|
|
50
|
-
{
|
|
51
|
-
name: 'mode',
|
|
52
|
-
type: 'list', // list, input, confirm, checkbox, rawlist, expand
|
|
53
|
-
message: '选择模式',
|
|
54
|
-
choices: [{
|
|
55
|
-
name: '模板选择模式',
|
|
56
|
-
value: 'template'
|
|
57
|
-
}, {
|
|
58
|
-
name: '依赖性选择模式',
|
|
59
|
-
value: 'dependencies'
|
|
60
|
-
}]
|
|
61
|
-
}
|
|
62
|
-
]);
|
|
63
|
-
config.mode = mode;
|
|
64
|
-
writeFileSync(configPath, encode(config));
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
export const getAllConfig = () => {
|
|
68
|
-
const config = { organization: '', access_token: '', repo: 'github', mode: 'template' };
|
|
69
|
-
const exists = existsSync(configPath);
|
|
70
|
-
if (exists) {
|
|
71
|
-
const userConfig = decode(readFileSync(configPath, 'utf-8'));
|
|
72
|
-
Object.assign(config, userConfig);
|
|
73
|
-
}
|
|
74
|
-
return { exists, config };
|
|
75
|
-
};
|
|
1
|
+
var __awaiter=this&&this.__awaiter||function(e,i,t,o){return new(t||(t=Promise))(function(n,c){function r(e){try{s(o.next(e))}catch(e){c(e)}}function a(e){try{s(o.throw(e))}catch(e){c(e)}}function s(e){var i;e.done?n(e.value):(i=e.value,i instanceof t?i:new t(function(e){e(i)})).then(r,a)}s((o=o.apply(e,i||[])).next())})};import chalk from"chalk";import{writeFileSync}from"fs";import{encode}from"ini";import inquirer from"inquirer";import{configPath}from"../constants.js";import{getAllConfig,processExit}from"../utils/index.js";export default(e,i)=>__awaiter(void 0,void 0,void 0,function*(){const{exists:t,config:o}=getAllConfig(),n=Object.keys(i)[0],c=i[n];if("get"===n)console.log(o[c]);else if("set"===n)o[c]=e,writeFileSync(configPath,encode(o));else if("delete"===n)delete o[c],t&&writeFileSync(configPath,encode(o));else if("repo"===n)try{const{repo:e}=yield inquirer.prompt([{name:"repo",type:"list",message:"选择仓库",choices:[{name:"github",value:"github"},{name:"gitee",value:"gitee"}]}]);o.repo=e,writeFileSync(configPath,encode(o))}catch(e){processExit(chalk.red("退出选择仓库"))}else if("mode"===n)try{const{mode:e}=yield inquirer.prompt([{name:"mode",type:"list",message:"选择模式",choices:[{name:"模板选择模式",value:"template"},{name:"依赖性选择模式",value:"dependencies"}]}]);o.mode=e,writeFileSync(configPath,encode(o))}catch(e){processExit(chalk.red("退出选择模式"))}});
|
package/bin/commands/create.js
CHANGED
|
@@ -1,224 +1 @@
|
|
|
1
|
-
var __awaiter = (
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import chalk from "chalk";
|
|
11
|
-
import { existsSync } from "fs";
|
|
12
|
-
import inquirer from 'inquirer';
|
|
13
|
-
import path from "path";
|
|
14
|
-
import { cloneCodeDeps, cloneCodeTemplate, getOrganizationProjects } from "../utils/project.js";
|
|
15
|
-
import { getAllConfig } from "./config.js";
|
|
16
|
-
const { mode } = getAllConfig().config;
|
|
17
|
-
export default (name, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
-
try {
|
|
19
|
-
const projectConfig = {
|
|
20
|
-
name: '', // 项目名称
|
|
21
|
-
path: '', // 项目路径
|
|
22
|
-
isOverwrite: false, // 是否覆盖
|
|
23
|
-
};
|
|
24
|
-
if (name)
|
|
25
|
-
projectConfig.name = name.trim();
|
|
26
|
-
else {
|
|
27
|
-
const { projectName } = yield inquirer.prompt([
|
|
28
|
-
{
|
|
29
|
-
name: 'projectName',
|
|
30
|
-
type: 'input', // list, input, confirm, checkbox, rawlist, expand
|
|
31
|
-
default: 'my-project',
|
|
32
|
-
message: '项目名称',
|
|
33
|
-
}
|
|
34
|
-
]);
|
|
35
|
-
projectConfig.name = projectName ? projectName.trim() : 'my-project';
|
|
36
|
-
}
|
|
37
|
-
const cwd = process.cwd();
|
|
38
|
-
const targetDir = path.join(cwd, projectConfig.name);
|
|
39
|
-
if (existsSync(targetDir)) {
|
|
40
|
-
if (options.force) {
|
|
41
|
-
projectConfig.isOverwrite = true;
|
|
42
|
-
projectConfig.path = targetDir;
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
const { action } = yield inquirer.prompt([
|
|
46
|
-
{
|
|
47
|
-
name: 'action',
|
|
48
|
-
type: 'list', // list, input, confirm, checkbox, rawlist, expand
|
|
49
|
-
message: `目录${projectConfig.name}已存在,是否覆盖?`,
|
|
50
|
-
choices: [{
|
|
51
|
-
name: '覆盖',
|
|
52
|
-
value: 'overwrite'
|
|
53
|
-
}, {
|
|
54
|
-
name: '取消',
|
|
55
|
-
value: 'cancel'
|
|
56
|
-
}]
|
|
57
|
-
}
|
|
58
|
-
]);
|
|
59
|
-
switch (action) {
|
|
60
|
-
case 'overwrite':
|
|
61
|
-
projectConfig.isOverwrite = true;
|
|
62
|
-
projectConfig.path = targetDir;
|
|
63
|
-
break;
|
|
64
|
-
case 'cancel':
|
|
65
|
-
return console.log(`取消创建目录${projectConfig.name}`);
|
|
66
|
-
default:
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (mode === 'chootemplate') {
|
|
72
|
-
const projects = yield getOrganizationProjects();
|
|
73
|
-
const { projectName } = yield inquirer.prompt([
|
|
74
|
-
{
|
|
75
|
-
name: 'projectName',
|
|
76
|
-
type: 'list', // list, input, confirm, checkbox, rawlist, expand
|
|
77
|
-
message: '选择模板',
|
|
78
|
-
choices: projects
|
|
79
|
-
}
|
|
80
|
-
]);
|
|
81
|
-
// const tags = await getProjectVersion(projectName)
|
|
82
|
-
// const { tag } = await inquirer.prompt([
|
|
83
|
-
// {
|
|
84
|
-
// name: 'tag',
|
|
85
|
-
// type: 'list', // list, input, confirm, checkbox, rawlist, expand
|
|
86
|
-
// message: '请选择版本',
|
|
87
|
-
// choices: tags
|
|
88
|
-
// }
|
|
89
|
-
// ])
|
|
90
|
-
// console.log(tag);
|
|
91
|
-
cloneCodeTemplate('master', projectName, projectConfig);
|
|
92
|
-
}
|
|
93
|
-
else if (mode === 'dependencies') {
|
|
94
|
-
const framework = yield inquirer.prompt([
|
|
95
|
-
{
|
|
96
|
-
name: 'framework',
|
|
97
|
-
type: 'list',
|
|
98
|
-
message: '选择框架',
|
|
99
|
-
choices: [
|
|
100
|
-
{
|
|
101
|
-
name: chalk.hex('#42b883')('Vue'),
|
|
102
|
-
value: 'vue'
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
name: chalk.hex('#087ea4')('React'),
|
|
106
|
-
value: 'react'
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
name: chalk.hex('#fecf05')('Vanilla'),
|
|
110
|
-
value: 'vanilla'
|
|
111
|
-
}
|
|
112
|
-
]
|
|
113
|
-
}
|
|
114
|
-
]);
|
|
115
|
-
const { language } = yield inquirer.prompt([
|
|
116
|
-
{
|
|
117
|
-
name: 'language',
|
|
118
|
-
type: 'confirm',
|
|
119
|
-
message: '是否使用TypeScript?',
|
|
120
|
-
}
|
|
121
|
-
]);
|
|
122
|
-
const { eslint } = yield inquirer.prompt([
|
|
123
|
-
{
|
|
124
|
-
name: 'eslint',
|
|
125
|
-
type: 'confirm',
|
|
126
|
-
message: '是否使用Eslint?',
|
|
127
|
-
}
|
|
128
|
-
]);
|
|
129
|
-
const router = yield inquirer.prompt([
|
|
130
|
-
{
|
|
131
|
-
name: 'router',
|
|
132
|
-
type: 'list',
|
|
133
|
-
message: '选择路由',
|
|
134
|
-
choices: [
|
|
135
|
-
{
|
|
136
|
-
name: chalk.hex('#3451b2')('React Router'),
|
|
137
|
-
value: 'react-router'
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
name: chalk.hex('#39c05b')('TanStack Router'),
|
|
141
|
-
value: 'tanStack-router'
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
name: 'Vanilla',
|
|
145
|
-
value: ''
|
|
146
|
-
}
|
|
147
|
-
]
|
|
148
|
-
}
|
|
149
|
-
]);
|
|
150
|
-
const store = yield inquirer.prompt([
|
|
151
|
-
{
|
|
152
|
-
name: 'store',
|
|
153
|
-
type: 'list',
|
|
154
|
-
message: '选择状态管理仓库',
|
|
155
|
-
choices: [
|
|
156
|
-
{
|
|
157
|
-
name: chalk.hex('#764abc')('Redux'),
|
|
158
|
-
value: 'redux'
|
|
159
|
-
},
|
|
160
|
-
{
|
|
161
|
-
name: chalk.hex('#1c16df')('Zustand'),
|
|
162
|
-
value: 'zustand'
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
name: 'Vanilla',
|
|
166
|
-
value: ''
|
|
167
|
-
}
|
|
168
|
-
]
|
|
169
|
-
}
|
|
170
|
-
]);
|
|
171
|
-
const atomStyle = yield inquirer.prompt([
|
|
172
|
-
{
|
|
173
|
-
name: 'atomStyle',
|
|
174
|
-
type: 'list',
|
|
175
|
-
message: '选择原子化样式库',
|
|
176
|
-
choices: [
|
|
177
|
-
{
|
|
178
|
-
name: chalk.hex('#38bdf8')('Tailwind CSS'),
|
|
179
|
-
value: 'tailwindcss'
|
|
180
|
-
},
|
|
181
|
-
{
|
|
182
|
-
name: chalk.hex('#4d9375')('Uno CSS'),
|
|
183
|
-
value: 'unocss'
|
|
184
|
-
},
|
|
185
|
-
{
|
|
186
|
-
name: 'Vanilla',
|
|
187
|
-
value: ''
|
|
188
|
-
}
|
|
189
|
-
]
|
|
190
|
-
}
|
|
191
|
-
]);
|
|
192
|
-
const stylePrecompiler = yield inquirer.prompt([
|
|
193
|
-
{
|
|
194
|
-
name: 'stylePrecompiler',
|
|
195
|
-
type: 'list',
|
|
196
|
-
message: '选择预编译器',
|
|
197
|
-
choices: [
|
|
198
|
-
{
|
|
199
|
-
name: chalk.hex('#cc6699')('Sass'),
|
|
200
|
-
value: 'sass'
|
|
201
|
-
},
|
|
202
|
-
{
|
|
203
|
-
name: chalk.hex('#1d365d')('Less'),
|
|
204
|
-
value: 'less'
|
|
205
|
-
},
|
|
206
|
-
{
|
|
207
|
-
name: chalk.hex('#89ba1b')('Stylus'),
|
|
208
|
-
value: 'stylus'
|
|
209
|
-
},
|
|
210
|
-
{
|
|
211
|
-
name: 'Vanilla',
|
|
212
|
-
value: ''
|
|
213
|
-
}
|
|
214
|
-
]
|
|
215
|
-
}
|
|
216
|
-
]);
|
|
217
|
-
Object.assign(projectConfig, framework, { lanuage: language ? 'ts' : 'js' }, router, store, atomStyle, stylePrecompiler, { eslint: eslint ? 'eslint' : '' });
|
|
218
|
-
cloneCodeDeps('master', projectConfig);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
catch (error) {
|
|
222
|
-
return console.log(chalk.red('退出创建项目'));
|
|
223
|
-
}
|
|
224
|
-
});
|
|
1
|
+
var __awaiter=this&&this.__awaiter||function(e,a,n,t){return new(n||(n=Promise))(function(r,i){function o(e){try{s(t.next(e))}catch(e){i(e)}}function c(e){try{s(t.throw(e))}catch(e){i(e)}}function s(e){var a;e.done?r(e.value):(a=e.value,a instanceof n?a:new n(function(e){e(a)})).then(o,c)}s((t=t.apply(e,a||[])).next())})};import chalk from"chalk";import{existsSync}from"fs";import inquirer from"inquirer";import path from"path";import process from"process";import{cloneCodeDeps,cloneCodeTemplate,getAllConfig,getOrganizationProjects,getProjectBranches,getProjectTags,processExit}from"../utils/index.js";const{mode:mode}=getAllConfig().config,frameworkDependenciesConfig={vue:{router:[{name:chalk.hex("#425d11")("Vue Router"),value:"vue-router"},{name:"none",value:""}],store:[{name:chalk.hex("#425d11")("Pinia"),value:"pinia"},{name:chalk.hex("#3eaf7c")("Vuex"),value:"vuex"},{name:"none",value:""}]},react:{router:[{name:chalk.hex("#3451b2")("React Router"),value:"react-router"},{name:chalk.hex("#39c05b")("TanStack Router"),value:"tanStack-router"},{name:"none",value:""}],store:[{name:chalk.hex("#764abc")("Redux"),value:"redux"},{name:chalk.hex("#1c16df")("Zustand"),value:"zustand"},{name:"none",value:""}]}},changeFrameworkDependencies=e=>""===e?[]:[{name:"router",type:"list",message:"选择路由",choices:frameworkDependenciesConfig[e].router},{name:"store",type:"list",message:"选择状态管理仓库",choices:frameworkDependenciesConfig[e].store}];export default(e,a)=>__awaiter(void 0,void 0,void 0,function*(){try{const n={name:"",path:"",isOverwrite:!1};if(e)n.name=e.trim();else{const{projectName:e}=yield inquirer.prompt([{name:"projectName",type:"input",default:"my-project",message:"项目名称"}]);n.name=e?e.trim():"my-project"}const t=process.cwd(),r=path.join(t,n.name);if(existsSync(r))if(a.force)n.isOverwrite=!0,n.path=r;else{const{action:e}=yield inquirer.prompt([{name:"action",type:"list",message:`目录${n.name}已存在,是否覆盖?`,choices:[{name:"覆盖",value:"overwrite"},{name:"取消",value:"cancel"}]}]);switch(e){case"overwrite":n.isOverwrite=!0,n.path=r;break;case"cancel":return console.log(`取消创建目录${n.name}`)}}if("template"===mode){const e=yield getOrganizationProjects(),{projectName:a}=yield inquirer.prompt([{name:"projectName",type:"list",message:"选择模板",choices:e}]),t=yield getProjectBranches(a),{mode:r}=yield inquirer.prompt([{name:"mode",type:"list",message:"请选择branch或tag",choices:[{name:"branch",value:"branch"},{name:"tag",value:"tag"},{name:"none",value:""}]}]),i=e=>cloneCodeTemplate(e,a,n);if("branch"===r)if(t.length>1){const{branch:e}=yield inquirer.prompt([{name:"branch",type:"list",message:"请选择branch",choices:t}]);i(e)}else i(t[0]);else if("tag"===r){const e=yield getProjectTags(a);if(e.length>0){const{tag:a}=yield inquirer.prompt([{name:"tag",type:"list",message:"请选择tag",choices:e}]);i(a)}else i(e[0])}else i(t[0])}else if("dependencies"===mode){const e=yield inquirer.prompt([{name:"framework",type:"list",message:"选择框架",choices:[{name:chalk.hex("#42b883")("Vue"),value:"vue"},{name:chalk.hex("#087ea4")("React"),value:"react"},{name:chalk.hex("#fecf05")("Vanilla"),value:""}]}]),{language:a,eslint:t}=yield inquirer.prompt([{name:"language",type:"confirm",message:"是否使用TypeScript?"},{name:"eslint",type:"confirm",message:"是否使用Eslint?"}]),r=yield inquirer.prompt([...changeFrameworkDependencies(e.framework),{name:"atomStyle",type:"list",message:"选择原子化样式库",choices:[{name:chalk.hex("#38bdf8")("Tailwind CSS"),value:"tailwindcss"},{name:chalk.hex("#4d9375")("Uno CSS"),value:"unocss"},{name:"none",value:""}]},{name:"stylePrecompiler",type:"list",message:"选择预编译器",choices:[{name:chalk.hex("#cc6699")("Sass"),value:"sass"},{name:chalk.hex("#1d365d")("Less"),value:"less"},{name:chalk.hex("#89ba1b")("Stylus"),value:"stylus"},{name:"none",value:""}]}]);Object.assign(n,e,{lanuage:a?"ts":"js"},{eslint:t?"eslint":""},r),cloneCodeDeps(n)}}catch(e){e.config&&e.config.url&&console.log(chalk.red("tags"===e.config.url.split("/").slice(-1)[0]&&"该项目没有tag")),processExit(chalk.red("退出创建项目"))}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var __awaiter=this&&this.__awaiter||function(n,i,t,e){return new(t||(t=Promise))(function(o,a){function r(n){try{s(e.next(n))}catch(n){a(n)}}function c(n){try{s(e.throw(n))}catch(n){a(n)}}function s(n){var i;n.done?o(n.value):(i=n.value,i instanceof t?i:new t(function(n){n(i)})).then(r,c)}s((e=e.apply(n,i||[])).next())})};import chalk from"chalk";import{execPromisified,processExit,wrapLoading}from"../utils/index.js";export default n=>__awaiter(void 0,void 0,void 0,function*(){let i="npm install -g ";return n?n.includes("@")?i+=n:i+=`ono-cli@${n}`:i+="ono-cli@latest",wrapLoading(chalk.green("🚀 更新中..."),()=>__awaiter(void 0,void 0,void 0,function*(){try{yield execPromisified(i),processExit("\n\n📦 更新成功!\n\n")}catch(n){processExit(chalk.red(`\n\n❌ 更新失败: ${n.message}\n\n`))}}))});
|
package/bin/constants.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const configPath
|
|
1
|
+
export const configPath=`${process.env.HOME||process.env.USERPROFILE}/.onoclirc`;
|
package/bin/index.js
CHANGED
|
@@ -1,35 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var __awaiter = (
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
import chalk from 'chalk';
|
|
12
|
-
import { program } from 'commander';
|
|
13
|
-
import pkg from './pkg.js';
|
|
14
|
-
const baseAction = (url, arg) => __awaiter(void 0, void 0, void 0, function* () { return (yield import(url)).default(...arg); });
|
|
15
|
-
// 首行提示
|
|
16
|
-
program.name('ono-cli').usage('<command> [option]');
|
|
17
|
-
// 版本号
|
|
18
|
-
// program.option('-V, --version', '输出版本号');
|
|
19
|
-
program.version(`ono-cli@${pkg.version}`);
|
|
20
|
-
program
|
|
21
|
-
.command('create [project-name]')
|
|
22
|
-
.description('创建新项目')
|
|
23
|
-
.option('-f, --force', '强制创建')
|
|
24
|
-
.action((projectName, options) => baseAction('./commands/create.js', [projectName, options]));
|
|
25
|
-
program
|
|
26
|
-
.command('config [value]')
|
|
27
|
-
.description('inspect config')
|
|
28
|
-
.option('-g, --get <path>', 'get value')
|
|
29
|
-
.option('-s, --set <path> <value>', 'set value')
|
|
30
|
-
.option('-d, --delete <path>', 'delete value')
|
|
31
|
-
.option('-r, --repo', 'choose repo')
|
|
32
|
-
.option('-m, --mode', 'choose mode')
|
|
33
|
-
.action((value, options) => baseAction('./commands/config.js', [value, options]));
|
|
34
|
-
program.addHelpText('after', `Run ${chalk.blueBright('ono-cli <command> --help')} for detailed usage of given command.`);
|
|
35
|
-
program.parse(process.argv);
|
|
2
|
+
var __awaiter=this&&this.__awaiter||function(o,e,a,n){return new(a||(a=Promise))(function(t,r){function i(o){try{m(n.next(o))}catch(o){r(o)}}function c(o){try{m(n.throw(o))}catch(o){r(o)}}function m(o){var e;o.done?t(o.value):(e=o.value,e instanceof a?e:new a(function(o){o(e)})).then(i,c)}m((n=n.apply(o,e||[])).next())})};import chalk from"chalk";import{program}from"commander";import pkg from"./pkg.js";const baseAction=(o,e)=>__awaiter(void 0,void 0,void 0,function*(){return(yield import(o)).default(...e)});program.name("ono-cli").usage("<command> [option]"),program.version(`ono-cli@${pkg.version}`),program.command("create [project-name]").description("创建新项目").option("-f, --force","强制创建").action((o,e)=>baseAction("./commands/create.js",[o,e])),program.command("config [value]").description("配置信息").option("-g, --get <path>","get value").option("-s, --set <path> <value>","set value").option("-d, --delete <path>","delete value").option("-r, --repo","choose repo").option("-m, --mode","choose mode").action((o,e)=>baseAction("./commands/config.js",[o,e])),program.command("update [version]").description("update ono-cli").action((o,e)=>baseAction("./commands/update.js",[o,e])),program.addHelpText("after",`Run ${chalk.blueBright("ono-cli <command> --help")} for detailed usage of given command.`),program.parse(process.argv);
|
package/bin/pkg.js
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { dirname, join } from 'path';
|
|
3
|
-
import { fileURLToPath } from 'url';
|
|
4
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
5
|
-
const require = createRequire(import.meta.url);
|
|
6
|
-
const pkg = require(join(__dirname, '../package.json'));
|
|
7
|
-
export default pkg;
|
|
1
|
+
import{createRequire}from"module";import{dirname,join}from"path";import{fileURLToPath}from"url";const __dirname=dirname(fileURLToPath(import.meta.url)),require=createRequire(import.meta.url),pkg=require(join(__dirname,"../package.json"));export default pkg;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{existsSync,readFileSync}from"fs";import{decode}from"ini";import{configPath}from"../constants.js";export const getAllConfig=()=>{const t={organization:"",access_token:"",repo:"github",mode:"template"},o=existsSync(configPath);if(o){const o=decode(readFileSync(configPath,"utf-8"));Object.assign(t,o)}return{exists:o,config:t}};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"./getAllConfig.js";export*from"./loading.js";export*from"./processExit.js";export*from"./project.js";
|
package/bin/utils/loading.js
CHANGED
|
@@ -1,17 +1 @@
|
|
|
1
|
-
var __awaiter
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import ora from 'ora';
|
|
11
|
-
export const wrapLoading = (message, fn) => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
|
-
const spinner = ora(message);
|
|
13
|
-
spinner.start();
|
|
14
|
-
const res = yield fn();
|
|
15
|
-
spinner.stop();
|
|
16
|
-
return res;
|
|
17
|
-
});
|
|
1
|
+
var __awaiter=this&&this.__awaiter||function(t,n,o,r){return new(o||(o=Promise))(function(a,i){function e(t){try{u(r.next(t))}catch(t){i(t)}}function c(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var n;t.done?a(t.value):(n=t.value,n instanceof o?n:new o(function(t){t(n)})).then(e,c)}u((r=r.apply(t,n||[])).next())})};import ora from"ora";export const wrapLoading=(t,n)=>__awaiter(void 0,void 0,void 0,function*(){const o=ora(t);o.start();const r=yield n();return o.stop(),o.clear(),r});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const processExit=o=>{console.log(o),process.exit()};
|
package/bin/utils/project.js
CHANGED
|
@@ -1,75 +1 @@
|
|
|
1
|
-
var __awaiter = (this &&
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import axios from "axios";
|
|
11
|
-
import chalk from "chalk";
|
|
12
|
-
import { rmSync } from "fs";
|
|
13
|
-
import { rm } from "fs/promises";
|
|
14
|
-
import { getAllConfig } from "../commands/config.js";
|
|
15
|
-
import { wrapLoading } from "./loading.js";
|
|
16
|
-
import { exec } from "child_process";
|
|
17
|
-
import util from "util";
|
|
18
|
-
export const execPromisified = util.promisify(exec);
|
|
19
|
-
const { organization, access_token } = getAllConfig().config;
|
|
20
|
-
export const getOrganizationProjects = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
-
try {
|
|
22
|
-
const res = yield axios.get(`https://gitee.com/api/v5/orgs/${organization}/repos`, {
|
|
23
|
-
headers: {
|
|
24
|
-
Authorization: `Bearer ${access_token}`
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
return res.data.map(item => item.name);
|
|
28
|
-
}
|
|
29
|
-
catch (error) {
|
|
30
|
-
return console.log(chalk.red(`🚀 没有找到组织项目!${chalk.white(`请使用 ${chalk.hex('#89ba1b')("ono-cli config -s")} 设置正确的 ${chalk.hex('#1c16df')('organization')} 和 ${chalk.hex('#1c16df')('access_token')} !`)}`));
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
export const getProjectVersion = (repo) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
-
const res = yield axios.get(`https://gitee.com/api/v5/repos/${organization}/${repo}/tags`, {
|
|
35
|
-
headers: {
|
|
36
|
-
Authorization: `Bearer ${access_token}`
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
return res.data.map(item => item.name);
|
|
40
|
-
});
|
|
41
|
-
export const cloneCodeTemplate = (tag, projectName, projectConfig) => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
-
const cmd = `git clone --branch ${tag} --depth 1 https://gitee.com/${organization}/${projectName}.git ${projectConfig.name}`;
|
|
43
|
-
if (projectConfig.isOverwrite)
|
|
44
|
-
wrapLoading('remove', () => __awaiter(void 0, void 0, void 0, function* () { return rmSync(projectConfig.path, { recursive: true }); }));
|
|
45
|
-
return wrapLoading(chalk.green(`🚀 创建项目 ${projectConfig.name}...`), () => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
-
yield execPromisified(cmd);
|
|
47
|
-
console.log(`\n\n🚀 创建项目成功!\n\n\n 进入项目目录:${chalk.hex('#89ba1b')(`cd .\\${projectConfig.name}`)}\n\n 打开项目:${chalk.hex('#89ba1b')("code .")}\n\n`);
|
|
48
|
-
return rm(`${projectConfig.name}/.git`, { recursive: true });
|
|
49
|
-
}));
|
|
50
|
-
});
|
|
51
|
-
export const cloneCodeDeps = (tag, projectConfig) => __awaiter(void 0, void 0, void 0, function* () {
|
|
52
|
-
const oProjectConfig = Object.assign({}, projectConfig);
|
|
53
|
-
delete projectConfig.name;
|
|
54
|
-
delete projectConfig.path;
|
|
55
|
-
delete projectConfig.isOverwrite;
|
|
56
|
-
const projectConfigValues = Object.values(projectConfig).filter(item => item !== '');
|
|
57
|
-
const projects = yield getOrganizationProjects();
|
|
58
|
-
if (!projects)
|
|
59
|
-
return;
|
|
60
|
-
const templateObj = projects.reduce((acc, item) => {
|
|
61
|
-
acc[item] = 0;
|
|
62
|
-
return acc;
|
|
63
|
-
}, {});
|
|
64
|
-
for (let i = 0; i < projects.length; i++) {
|
|
65
|
-
for (let j = 0; j < projectConfigValues.length; j++) {
|
|
66
|
-
if (projects[i].includes(projectConfigValues[j]))
|
|
67
|
-
templateObj[projects[i]]++;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
const templateObjKeys = Object.keys(templateObj);
|
|
71
|
-
const matchedProject = templateObjKeys.find(template => templateObj[template] === projectConfigValues.length);
|
|
72
|
-
if (!matchedProject)
|
|
73
|
-
return console.log(chalk.red('🚀 没有找到匹配的项目模板!'));
|
|
74
|
-
cloneCodeTemplate(tag, matchedProject, oProjectConfig);
|
|
75
|
-
});
|
|
1
|
+
var __awaiter=this&&this.__awaiter||function(e,t,o,i){return new(o||(o=Promise))(function(r,n){function a(e){try{s(i.next(e))}catch(e){n(e)}}function c(e){try{s(i.throw(e))}catch(e){n(e)}}function s(e){var t;e.done?r(e.value):(t=e.value,t instanceof o?t:new o(function(e){e(t)})).then(a,c)}s((i=i.apply(e,t||[])).next())})},__rest=this&&this.__rest||function(e,t){var o={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(o[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(o[i[r]]=e[i[r]])}return o};import axios from"axios";import chalk from"chalk";import{exec}from"child_process";import{rmSync}from"fs";import util from"util";import{getAllConfig}from"./getAllConfig.js";import{wrapLoading}from"./loading.js";import{processExit}from"./processExit.js";export const execPromisified=util.promisify(exec);const{organization:organization,access_token:access_token,repo:repo}=getAllConfig().config;export const getOrganizationProjects=()=>__awaiter(void 0,void 0,void 0,function*(){try{return(yield axios.get("github"===repo?`https://api.github.com/orgs/${organization}/repos?type=all`:`https://gitee.com/api/v5/orgs/${organization}/repos`,{headers:{Authorization:"github"===repo?`token ${access_token}`:`Bearer ${access_token}`}})).data.map(e=>e.name)}catch(e){processExit(chalk.red(`🔍 没有找到组织项目!${chalk.white(`请使用 ${chalk.hex("#89ba1b")("ono-cli config -s")} 设置正确的 ${chalk.hex("#1c16df")("organization")} 和 ${chalk.hex("#1c16df")("access_token")} !`)}`))}});export const getProjectBranches=e=>__awaiter(void 0,void 0,void 0,function*(){const t=yield axios.get("github"===repo?`https://api.github.com/repos/${organization}/${e}/branches`:`https://gitee.com/api/v5/repos/${organization}/${e}/branches`,{headers:{Authorization:"github"===repo?`token ${access_token}`:`Bearer ${access_token}`}});return t.data.length>0?t.data.map(e=>e.name):[]});export const getProjectTags=e=>__awaiter(void 0,void 0,void 0,function*(){const t=yield axios.get("github"===repo?`https://api.github.com/repos/${organization}/${e}/tags`:`https://gitee.com/api/v5/repos/${organization}/${e}/tags`,{headers:{Authorization:"github"===repo?`token ${access_token}`:`Bearer ${access_token}`}});return t.data.length>0?t.data.map(e=>e.name):[]});export const cloneCodeTemplate=(e,t,o)=>__awaiter(void 0,void 0,void 0,function*(){const i=`git clone --branch ${e} --depth 1 https://${repo}.com/${organization}/${t}.git ${o.name}`;return o.isOverwrite&&wrapLoading(chalk.yellowBright("🚚 删除旧项目..."),()=>__awaiter(void 0,void 0,void 0,function*(){return rmSync(o.path,{recursive:!0})})),wrapLoading(chalk.greenBright(`📦 创建项目 ${o.name}...`),()=>__awaiter(void 0,void 0,void 0,function*(){try{yield execPromisified(i),rmSync(`${o.name}/.git`,{recursive:!0,force:!0}),processExit(`\n\n🚀 创建项目成功!\n ${chalk.greenBright(`cd ${o.name}`)}\n ${chalk.greenBright("code .")}\n ${chalk.greenBright("npm install")}\n`)}catch(e){processExit(chalk.red("\n\n❌ 拉取项目失败!请检查网络连接状态、仓库权限或配置信息!\n"))}}))});export const cloneCodeDeps=e=>__awaiter(void 0,void 0,void 0,function*(){const{name:t,path:o,isOverwrite:i}=e,r=__rest(e,["name","path","isOverwrite"]),n=Object.values(r).filter(e=>""!==e),a=yield getOrganizationProjects();if(!a)return;const c=a.reduce((e,t)=>(e[t]=0,e),{});for(let e=0;e<a.length;e++)for(let t=0;t<n.length;t++)a[e].includes(n[t])&&c[a[e]]++;const s=Object.keys(c).find(e=>c[e]===n.length);s||processExit(chalk.red("❌ 没有找到匹配的项目模板!"));const p=yield getProjectBranches(s);cloneCodeTemplate(p[0],s,e)});
|
package/package.json
CHANGED
|
@@ -1,37 +1,47 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "ono-cli",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "A CLI tool for ono template",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"bin": "./bin/index.js",
|
|
7
|
-
"type": "module",
|
|
8
|
-
"scripts": {
|
|
9
|
-
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
}
|
|
37
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "ono-cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A CLI tool for ono template",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"bin": "./bin/index.js",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "rimraf bin && tsc && node scripts/minify.js",
|
|
10
|
+
"link": "npm link",
|
|
11
|
+
"unlink": "npm unlink ono-cli",
|
|
12
|
+
"publish": "npm publish --access public",
|
|
13
|
+
"commit": "committier commit"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"bin",
|
|
17
|
+
"lib"
|
|
18
|
+
],
|
|
19
|
+
"keywords": [
|
|
20
|
+
"ono",
|
|
21
|
+
"cli",
|
|
22
|
+
"template"
|
|
23
|
+
],
|
|
24
|
+
"author": "ono",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"axios": "^1.7.7",
|
|
28
|
+
"chalk": "^5.3.0",
|
|
29
|
+
"commander": "^12.0.0",
|
|
30
|
+
"figlet": "^1.7.0",
|
|
31
|
+
"fs-extra": "^11.2.0",
|
|
32
|
+
"git-clone": "^0.2.0",
|
|
33
|
+
"ini": "^5.0.0",
|
|
34
|
+
"inquirer": "^11.0.2",
|
|
35
|
+
"ora": "^8.0.1"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/ini": "^4.1.1",
|
|
39
|
+
"@types/node": "^22.7.2",
|
|
40
|
+
"committier": "^0.2.3",
|
|
41
|
+
"glob": "^13.0.0",
|
|
42
|
+
"husky": "^9.1.7",
|
|
43
|
+
"rimraf": "^6.1.2",
|
|
44
|
+
"terser": "^5.44.1",
|
|
45
|
+
"typescript": "^5.0.2"
|
|
46
|
+
}
|
|
47
|
+
}
|