ono-cli 0.1.0 → 0.1.2
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 +53 -15
- package/bin/commands/config.js +1 -1
- package/bin/commands/create.js +1 -1
- package/bin/commands/update.js +1 -1
- package/bin/common/index.js +1 -0
- package/bin/common/infoConfig.js +1 -0
- package/bin/common/project.js +1 -0
- package/bin/index.js +1 -1
- package/bin/utils/getAllConfig.js +1 -1
- package/bin/utils/index.js +1 -1
- package/bin/utils/processExit.js +1 -1
- package/package.json +6 -4
- package/bin/utils/project.js +0 -1
package/README.md
CHANGED
|
@@ -8,16 +8,6 @@
|
|
|
8
8
|
npm install -g ono-cli
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
## 💡 快速使用(无需安装)
|
|
12
|
-
|
|
13
|
-
不想全局安装?你可以直接使用 npx 运行 ono-cli:
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
npx ono-cli create <project-name>
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
这种方式无需安装,直接运行最新版本的 ono-cli 来创建项目。
|
|
20
|
-
|
|
21
11
|
## 📖 使用指南
|
|
22
12
|
|
|
23
13
|
### 1. 配置脚手架
|
|
@@ -25,21 +15,25 @@ npx ono-cli create <project-name>
|
|
|
25
15
|
在使用脚手架前,需要先配置仓库源、组织和访问令牌:
|
|
26
16
|
|
|
27
17
|
**配置仓库源(GitHub 或 Gitee):**
|
|
18
|
+
|
|
28
19
|
```bash
|
|
29
20
|
ono-cli config -r
|
|
30
21
|
```
|
|
31
22
|
|
|
32
23
|
**配置组织名称:**
|
|
24
|
+
|
|
33
25
|
```bash
|
|
34
26
|
ono-cli config -s organization <YOUR ORGANIZATION NAME>
|
|
35
27
|
```
|
|
36
28
|
|
|
37
29
|
**配置访问令牌:**
|
|
30
|
+
|
|
38
31
|
```bash
|
|
39
32
|
ono-cli config -s access_token <YOUR ACCESS TOKEN>
|
|
40
33
|
```
|
|
41
34
|
|
|
42
35
|
**选择使用模式:**
|
|
36
|
+
|
|
43
37
|
```bash
|
|
44
38
|
ono-cli config -m
|
|
45
39
|
```
|
|
@@ -63,26 +57,74 @@ ono-cli create [YOUR PROJECT NAME]
|
|
|
63
57
|
如果需要查看当前的配置信息,可以使用以下命令:
|
|
64
58
|
|
|
65
59
|
**查看组织配置:**
|
|
60
|
+
|
|
66
61
|
```bash
|
|
67
62
|
ono-cli config -g organization
|
|
68
63
|
```
|
|
69
64
|
|
|
70
65
|
**查看访问令牌:**
|
|
66
|
+
|
|
71
67
|
```bash
|
|
72
68
|
ono-cli config -g access_token
|
|
73
69
|
```
|
|
74
70
|
|
|
75
71
|
**查看仓库源:**
|
|
72
|
+
|
|
76
73
|
```bash
|
|
77
74
|
ono-cli config -g repo
|
|
78
75
|
```
|
|
79
76
|
|
|
80
77
|
**查看使用模式:**
|
|
78
|
+
|
|
81
79
|
```bash
|
|
82
80
|
ono-cli config -g mode
|
|
83
81
|
```
|
|
84
82
|
|
|
85
|
-
|
|
83
|
+
**交互式查看配置项:**
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
ono-cli config -g
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 4. 删除配置项
|
|
90
|
+
|
|
91
|
+
如果需要删除某个配置项,可以使用以下命令:
|
|
92
|
+
|
|
93
|
+
**删除组织配置:**
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
ono-cli config -d organization
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**删除访问令牌:**
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
ono-cli config -d access_token
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**删除指定配置项:**
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
ono-cli config -d [CONFIG_KEY]
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**交互式删除配置项:**
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
ono-cli config -d
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### 5. 清空配置
|
|
118
|
+
|
|
119
|
+
如果需要清空所有配置,恢复到初始状态,可以使用以下命令:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
ono-cli config -c
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
此命令将清空组织名称、访问令牌等所有配置项,使配置文件恢复到默认状态。
|
|
126
|
+
|
|
127
|
+
### 6. 更新脚手架
|
|
86
128
|
|
|
87
129
|
当有新版本时,可以使用以下命令更新:
|
|
88
130
|
|
|
@@ -167,10 +209,6 @@ ono-cli update [version]
|
|
|
167
209
|
3. 检查网络连接是否正常
|
|
168
210
|
4. 如果使用私有仓库,请确保访问令牌具有相应权限
|
|
169
211
|
|
|
170
|
-
## 🤝 贡献
|
|
171
|
-
|
|
172
|
-
欢迎提交 Issue 和 Pull Request 来帮助改进 ono-cli!
|
|
173
|
-
|
|
174
212
|
## 📄 许可证
|
|
175
213
|
|
|
176
214
|
MIT
|
package/bin/commands/config.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var __awaiter=this&&this.__awaiter||function(e,i,
|
|
1
|
+
var __awaiter=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))(function(r,o){function c(e){try{s(n.next(e))}catch(e){o(e)}}function a(e){try{s(n.throw(e))}catch(e){o(e)}}function s(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(c,a)}s((n=n.apply(e,t||[])).next())})};import chalk from"chalk";import{writeFileSync}from"fs";import{encode}from"ini";import inquirer from"inquirer";import{repoInfo}from"../common/index.js";import{getAllConfig,processExit}from"../utils/index.js";export default(e,t)=>__awaiter(void 0,void 0,void 0,function*(){const{config:i,configPath:n}=getAllConfig(),r=Object.keys(t)[0],o=t[r];switch(r){case"get":if("string"==typeof o)processExit(i[o]);else try{const{item:e}=yield inquirer.prompt([{name:"item",type:"list",message:"选择想要查看的配置项",choices:[{name:"组织名称",value:"organization"},{name:"访问令牌",value:"access_token"},{name:"代码托管平台",value:"repo"},{name:"模式",value:"mode"}]}]);processExit(i[e])}catch(e){processExit()}return;case"set":return i[o]=e,writeFileSync(n,encode(i));case"delete":if("string"==typeof o)delete i[o],writeFileSync(n,encode(i));else try{const{item:e}=yield inquirer.prompt([{name:"item",type:"list",message:"选择想要删除的配置项",choices:[{name:"组织名称",value:"organization"},{name:"访问令牌",value:"access_token"}]}]);delete i[e],writeFileSync(n,encode(i))}catch(e){processExit()}return;case"clear":return writeFileSync(n,encode({organization:"",access_token:"",repo:"github",mode:"template"})),processExit(chalk.greenBright("配置文件已清空"));case"repo":try{const{repo:e}=yield inquirer.prompt([{name:"repo",type:"list",message:"选择仓库",choices:Object.keys(repoInfo).map(e=>({name:e,value:e}))}]);i.repo=e,writeFileSync(n,encode(i))}catch(e){processExit(chalk.red("退出选择仓库"))}return;case"mode":try{const{mode:e}=yield inquirer.prompt([{name:"mode",type:"list",message:"选择模式",choices:[{name:"模板选择模式",value:"template"},{name:"依赖性选择模式",value:"dependencies"}]}]);i.mode=e,writeFileSync(n,encode(i))}catch(e){processExit(chalk.red("退出选择模式"))}return}});
|
package/bin/commands/create.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var __awaiter=this&&this.__awaiter||function(e,a,n,t){return new(n||(n=Promise))(function(
|
|
1
|
+
var __awaiter=this&&this.__awaiter||function(e,a,n,t){return new(n||(n=Promise))(function(i,o){function s(e){try{c(t.next(e))}catch(e){o(e)}}function r(e){try{c(t.throw(e))}catch(e){o(e)}}function c(e){var a;e.done?i(e.value):(a=e.value,a instanceof n?a:new n(function(e){e(a)})).then(s,r)}c((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,frameworkDependenciesConfig,getOrganizationProjects,getProjectBranches,getProjectTags}from"../common/index.js";import{getAllConfig,processExit}from"../utils/index.js";const{mode:mode}=getAllConfig().config,changeMode=(e,a)=>e.length<=1?a.length>0?[{name:"tag",value:"tag"},{name:"none",value:""}]:[]:a.length<0?[{name:"branch",value:"branch"},{name:"none",value:""}]:[{name:"branch",value:"branch"},{name:"tag",value:"tag"},{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(),i=path.join(t,n.name);if(existsSync(i))if(a.force)n.isOverwrite=!0,n.path=i;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=i;break;case"cancel":return console.log(`取消创建目录${n.name}`)}}if("template"===mode){const e=e=>cloneCodeTemplate(e,t,n),a=yield getOrganizationProjects(),{projectName:t}=yield inquirer.prompt([{name:"projectName",type:"list",message:"选择模板",choices:a}]),i=yield getProjectBranches(t),o=yield getProjectTags(t),s=changeMode(i,o);if(0===s.length)return e(i[0]);const{mode:r}=yield inquirer.prompt([{name:"mode",type:"list",message:"请选择branch或tag",choices:s}]);if("branch"===r)if(i.length>1){const{branch:a}=yield inquirer.prompt([{name:"branch",type:"list",message:"请选择branch",choices:i}]);e(a)}else e(i[0]);else if("tag"===r)if(o.length>0){const{tag:a}=yield inquirer.prompt([{name:"tag",type:"list",message:"请选择tag",choices:o}]);e(a)}else e(o[0]);else e(i[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("#58c4dc")("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?"}]),i=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":""},i),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("退出创建项目"))}});
|
package/bin/commands/update.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var __awaiter=this&&this.__awaiter||function(n,i,t,e){return new(t||(t=Promise))(function(o,
|
|
1
|
+
var __awaiter=this&&this.__awaiter||function(n,i,t,e){return new(t||(t=Promise))(function(o,r){function a(n){try{s(e.next(n))}catch(n){r(n)}}function c(n){try{s(e.throw(n))}catch(n){r(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(a,c)}s((e=e.apply(n,i||[])).next())})};import chalk from"chalk";import{execPromisified}from"../common/index.js";import{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`))}}))});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"./infoConfig.js";export*from"./project.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import chalk from"chalk";export const repoInfo={github:{organization:{url:"https://api.github.com/orgs/{organization}/repos?type=all",authorization:"token {access_token}"},branch:{url:"https://api.github.com/repos/{organization}/{repositories}/branches",authorization:"token {access_token}"},tag:{url:"https://api.github.com/repos/{organization}/{repositories}/tags",authorization:"token {access_token}"},clone:"git clone --branch {branchOrTag} --depth 1 https://{repo}.com/{organization}/{projectName}.git {name}"},gitee:{organization:{url:"https://gitee.com/api/v5/orgs/{organization}/repos",authorization:"Bearer {access_token}"},branch:{url:"https://gitee.com/api/v5/repos/{organization}/{repositories}/branches",authorization:"Bearer {access_token}"},tag:{url:"https://gitee.com/api/v5/repos/{organization}/{repositories}/tags",authorization:"Bearer {access_token}"},clone:"git clone --branch {branchOrTag} --depth 1 https://{repo}.com/{organization}/{projectName}.git {name}"}};export const frameworkDependenciesConfig={vue:{router:[{name:chalk.hex("#425d11")("Vue Router"),value:"vue-router"},{name:chalk.hex("#00bc7d")("TanStack Router"),value:"tanStack-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("#00bc7d")("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:""}]}};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var __awaiter=this&&this.__awaiter||function(e,o,t,r){return new(t||(t=Promise))(function(n,i){function a(e){try{s(r.next(e))}catch(e){i(e)}}function c(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){var o;e.done?n(e.value):(o=e.value,o instanceof t?o:new t(function(e){e(o)})).then(a,c)}s((r=r.apply(e,o||[])).next())})},__rest=this&&this.__rest||function(e,o){var t={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&o.indexOf(r)<0&&(t[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(r=Object.getOwnPropertySymbols(e);n<r.length;n++)o.indexOf(r[n])<0&&Object.prototype.propertyIsEnumerable.call(e,r[n])&&(t[r[n]]=e[r[n]])}return t};import axios from"axios";import chalk from"chalk";import{exec}from"child_process";import{rmSync}from"fs";import util from"util";import{getAllConfig}from"../utils/getAllConfig.js";import{wrapLoading}from"../utils/loading.js";import{processExit}from"../utils/processExit.js";import{repoInfo}from"./infoConfig.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(repoInfo[repo].organization.url.replace("{organization}",organization),access_token?{headers:{Authorization:repoInfo[repo].organization.authorization.replace("{access_token}",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 o=yield axios.get(repoInfo[repo].branch.url.replace("{organization}",organization).replace("{repositories}",e),access_token?{headers:{Authorization:repoInfo[repo].branch.authorization.replace("{access_token}",access_token)}}:{});return o.data.length>0?o.data.map(e=>e.name):[]});export const getProjectTags=e=>__awaiter(void 0,void 0,void 0,function*(){const o=yield axios.get(repoInfo[repo].tag.url.replace("{organization}",organization).replace("{repositories}",e),access_token?{headers:{Authorization:repoInfo[repo].tag.authorization.replace("{access_token}",access_token)}}:{});return o.data.length>0?o.data.map(e=>e.name):[]});export const cloneCodeTemplate=(e,o,t)=>__awaiter(void 0,void 0,void 0,function*(){return t.isOverwrite&&wrapLoading(chalk.yellowBright("🚚 删除旧项目..."),()=>__awaiter(void 0,void 0,void 0,function*(){return rmSync(t.path,{recursive:!0})})),wrapLoading(chalk.greenBright(`📦 创建项目 ${t.name}...`),()=>__awaiter(void 0,void 0,void 0,function*(){try{yield execPromisified(repoInfo[repo].clone.replace("{branchOrTag}",e).replace("{repo}",repo).replace("{organization}",organization).replace("{projectName}",o).replace("{name}",t.name)),rmSync(`${t.name}/.git`,{recursive:!0,force:!0}),processExit(`\n\n🚀 创建项目成功!\n ${chalk.greenBright(`cd ${t.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:o,path:t,isOverwrite:r}=e,n=__rest(e,["name","path","isOverwrite"]),i=Object.values(n).filter(Boolean),a=yield getOrganizationProjects();if(!a)return;const c=a.reduce((e,o)=>(e[o]=0,e),{});for(let e=0;e<a.length;e++)for(let o=0;o<i.length;o++)a[e].includes(i[o])&&c[a[e]]++;const s=Object.keys(c).find(e=>c[e]===i.length);s||processExit(chalk.red("❌ 没有找到匹配的项目模板!"));const l=yield getProjectBranches(s);cloneCodeTemplate(l[0],s,e)});
|
package/bin/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var __awaiter=this&&this.__awaiter||function(o,e,a,
|
|
2
|
+
var __awaiter=this&&this.__awaiter||function(o,e,a,t){return new(a||(a=Promise))(function(n,r){function i(o){try{m(t.next(o))}catch(o){r(o)}}function c(o){try{m(t.throw(o))}catch(o){r(o)}}function m(o){var e;o.done?n(o.value):(e=o.value,e instanceof a?e:new a(function(o){o(e)})).then(i,c)}m((t=t.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(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("-c, --clear","clear 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);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync,readFileSync}from"fs";import{decode}from"ini";import{configPath}from"../constants.js";export const getAllConfig=()=>{const
|
|
1
|
+
import{existsSync,readFileSync,writeFileSync}from"fs";import{decode,encode}from"ini";import{configPath}from"../constants.js";export const getAllConfig=()=>{const e={organization:"",access_token:"",repo:"github",mode:"template"};if(existsSync(configPath)){const o=decode(readFileSync(configPath,"utf-8"));Object.assign(e,o)}else writeFileSync(configPath,encode(e));return{config:e,configPath:configPath}};
|
package/bin/utils/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./getAllConfig.js";export*from"./loading.js";export*from"./processExit.js";
|
|
1
|
+
export*from"./getAllConfig.js";export*from"./loading.js";export*from"./processExit.js";
|
package/bin/utils/processExit.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const processExit=o=>{console.log(o),process.exit()};
|
|
1
|
+
export const processExit=o=>{o&&console.log(o),process.exit()};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ono-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "A CLI tool for ono template",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": "./bin/index.js",
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
"build": "rimraf bin && tsc && node scripts/minify.js",
|
|
10
10
|
"link": "npm link",
|
|
11
11
|
"unlink": "npm unlink ono-cli",
|
|
12
|
-
"publish": "npm publish --access public",
|
|
13
12
|
"commit": "committier commit"
|
|
14
13
|
},
|
|
15
14
|
"files": [
|
|
@@ -21,8 +20,6 @@
|
|
|
21
20
|
"cli",
|
|
22
21
|
"template"
|
|
23
22
|
],
|
|
24
|
-
"author": "ono",
|
|
25
|
-
"license": "MIT",
|
|
26
23
|
"dependencies": {
|
|
27
24
|
"axios": "^1.7.7",
|
|
28
25
|
"chalk": "^5.3.0",
|
|
@@ -43,5 +40,10 @@
|
|
|
43
40
|
"rimraf": "^6.1.2",
|
|
44
41
|
"terser": "^5.44.1",
|
|
45
42
|
"typescript": "^5.0.2"
|
|
43
|
+
},
|
|
44
|
+
"author": "ono",
|
|
45
|
+
"license": "MIT",
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public"
|
|
46
48
|
}
|
|
47
49
|
}
|
package/bin/utils/project.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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)});
|