ono-cli 0.1.3 → 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
@@ -14,28 +14,10 @@ npm install -g ono-cli
14
14
 
15
15
  在使用脚手架前,需要先配置仓库源、组织和访问令牌:
16
16
 
17
- **配置仓库源(GitHub 或 Gitee):**
17
+ **交互式设置配置项:**
18
18
 
19
19
  ```bash
20
- ono-cli config -r
21
- ```
22
-
23
- **配置组织名称:**
24
-
25
- ```bash
26
- ono-cli config -s organization <YOUR ORGANIZATION NAME>
27
- ```
28
-
29
- **配置访问令牌:**
30
-
31
- ```bash
32
- ono-cli config -s access_token <YOUR ACCESS TOKEN>
33
- ```
34
-
35
- **选择使用模式:**
36
-
37
- ```bash
38
- ono-cli config -m
20
+ ono-cli config -s
39
21
  ```
40
22
 
41
23
  > **提示:** 一般选择`模板选择模式`,如果选择`依赖性选择模式`,则需要将仓库中的模板名称改成与选项相对应的名称。
@@ -56,30 +38,6 @@ ono-cli create [YOUR PROJECT NAME]
56
38
 
57
39
  如果需要查看当前的配置信息,可以使用以下命令:
58
40
 
59
- **查看组织配置:**
60
-
61
- ```bash
62
- ono-cli config -g organization
63
- ```
64
-
65
- **查看访问令牌:**
66
-
67
- ```bash
68
- ono-cli config -g access_token
69
- ```
70
-
71
- **查看仓库源:**
72
-
73
- ```bash
74
- ono-cli config -g repo
75
- ```
76
-
77
- **查看使用模式:**
78
-
79
- ```bash
80
- ono-cli config -g mode
81
- ```
82
-
83
41
  **交互式查看配置项:**
84
42
 
85
43
  ```bash
@@ -156,7 +114,7 @@ ono-cli update [version]
156
114
  5. 点击 "Generate new token" 按钮
157
115
  6. 输入令牌描述(Note)
158
116
  7. 设置过期时间(Expiration)
159
- 8. 为令牌分配权限(Scopes):
117
+ 8. 为令牌分配权限:
160
118
  - 对于访问私有仓库,至少需要 `repo` 权限
161
119
  - 如果要访问组织仓库,还需要 `admin:org` 或 `read:org` 权限
162
120
  - 如果访问的是私有仓库,还需要 `read:org` 权限
@@ -193,6 +151,7 @@ ono-cli update [version]
193
151
 
194
152
  - 直接从可用的模板列表中选择一个模板
195
153
  - 适合对模板有明确选择的场景
154
+ - 可选择分支(branch)或标签(tag)进行克隆
196
155
 
197
156
  ### 依赖性选择模式
198
157
 
@@ -211,4 +170,4 @@ ono-cli update [version]
211
170
 
212
171
  ## 📄 许可证
213
172
 
214
- MIT
173
+ MIT
@@ -1 +1 @@
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{getConfig,processExit}from"../utils/index.js";export default(e,t)=>__awaiter(void 0,void 0,void 0,function*(){const{config:i,configPath:n}=getConfig(),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}});
1
+ var e=this&&this.__awaiter||function(e,t,a,n){return new(a||(a=Promise))(function(o,i){function m(e){try{c(n.next(e))}catch(e){i(e)}}function s(e){try{c(n.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof a?t:new a(function(e){e(t)})).then(m,s)}c((n=n.apply(e,t||[])).next())})};import t from"chalk";import{writeFileSync as a}from"fs";import{encode as n}from"ini";import o from"inquirer";import{repoInfo as i}from"../common/index.js";import{baseConfig as m,getConfig as s,processExit as c}from"../utils/index.js";const r=e=>"repo"===e?{name:"value",type:"list",message:"选择仓库源",choices:Object.keys(i).map(e=>({name:e,value:e}))}:"mode"===e?{name:"value",type:"list",message:"选择模式",choices:[{name:"模板选择模式",value:"template"},{name:"依赖性选择模式",value:"dependencies"}]}:{name:"value",type:"input",default:"",message:"请输入"+("username"===e?"用户名称":"organization"===e?"组织名称":"访问令牌")};export default i=>e(void 0,void 0,void 0,function*(){const{config:e,configPath:l}=s(),u=Object.keys(i)[0],p=(t,o)=>{e[t]=o,a(l,n(e)),c()};try{switch(u){case"get":{const{item:t}=yield o.prompt([{name:"item",type:"list",message:"选择想要查看的配置项",choices:[{name:"组织名称",value:"organization"},{name:"访问令牌",value:"access_token"},{name:"代码托管平台",value:"repo"},{name:"模式",value:"mode"}]}]);return void c(e[t])}case"set":{const{key:e}=yield o.prompt([{name:"key",type:"list",message:"选择想要查看的配置项",choices:[{name:"组织名称",value:"organization"},{name:"访问令牌",value:"access_token"},{name:"代码托管平台",value:"repo"},{name:"模式",value:"mode"}]}]),{value:t}=yield o.prompt([r(e)]);p(e,t)}case"delete":{const{item:e}=yield o.prompt([{name:"item",type:"list",message:"选择想要删除的配置项",choices:[{name:"组织名称",value:"organization"},{name:"访问令牌",value:"access_token"}]}]);return void p(e,"")}case"clear":return a(l,n(m)),void c(t.greenBright("配置文件已清空"))}}catch(e){c()}});
@@ -1 +1 @@
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{getConfig,processExit}from"../utils/index.js";const{mode:mode}=getConfig().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("退出创建项目"))}});
1
+ var e=this&&this.__awaiter||function(e,a,t,n){return new(t||(t=Promise))(function(s,i){function o(e){try{m(n.next(e))}catch(e){i(e)}}function c(e){try{m(n.throw(e))}catch(e){i(e)}}function m(e){var a;e.done?s(e.value):(a=e.value,a instanceof t?a:new t(function(e){e(a)})).then(o,c)}m((n=n.apply(e,a||[])).next())})};import a from"chalk";import{existsSync as t}from"fs";import n from"inquirer";import s from"path";import i from"process";import{cloneCodeDeps as o,cloneCodeTemplate as c,frameworkDependenciesConfig as m,getOrganizationProjects as l,getProjectBranches as r,getProjectTags as p}from"../common/index.js";import{getConfig as u,processExit as h}from"../utils/index.js";const{mode:g}=u().config,f=(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:""}],y=e=>""===e?[]:[{name:"router",type:"list",message:"选择路由",choices:m[e].router},{name:"store",type:"list",message:"选择状态管理仓库",choices:m[e].store}];export default(m,u)=>e(void 0,void 0,void 0,function*(){try{const e={name:"",path:"",isOverwrite:!1};if(m)e.name=m.trim();else{const{projectName:a}=yield n.prompt([{name:"projectName",type:"input",default:"my-project",message:"项目名称"}]);e.name=a?a.trim():"my-project"}const h=i.cwd(),d=s.join(h,e.name);if(t(d))if(u.force)e.isOverwrite=!0,e.path=d;else{const{action:a}=yield n.prompt([{name:"action",type:"list",message:`目录${e.name}已存在,是否覆盖?`,choices:[{name:"覆盖",value:"overwrite"},{name:"取消",value:"cancel"}]}]);switch(a){case"overwrite":e.isOverwrite=!0,e.path=d;break;case"cancel":return console.log(`取消创建目录${e.name}`)}}if("template"===g){const a=a=>c(a,s,e),t=yield l(),{projectName:s}=yield n.prompt([{name:"projectName",type:"list",message:"选择模板",choices:t}]),i=yield r(s),o=yield p(s),m=f(i,o);if(0===m.length)return a(i[0]);const{mode:u}=yield n.prompt([{name:"mode",type:"list",message:"请选择branch或tag",choices:m}]);if("branch"===u)if(i.length>1){const{branch:e}=yield n.prompt([{name:"branch",type:"list",message:"请选择branch",choices:i}]);a(e)}else a(i[0]);else if("tag"===u)if(o.length>0){const{tag:e}=yield n.prompt([{name:"tag",type:"list",message:"请选择tag",choices:o}]);a(e)}else a(o[0]);else a(i[0])}else if("dependencies"===g){const t=yield n.prompt([{name:"framework",type:"list",message:"选择框架",choices:[{name:a.hex("#42b883")("Vue"),value:"vue"},{name:a.hex("#58c4dc")("React"),value:"react"},{name:a.hex("#fecf05")("Vanilla"),value:""}]}]),{language:s,eslint:i}=yield n.prompt([{name:"language",type:"confirm",message:"是否使用TypeScript?"},{name:"eslint",type:"confirm",message:"是否使用Eslint?"}]),c=yield n.prompt([...y(t.framework),{name:"atomStyle",type:"list",message:"选择原子化样式库",choices:[{name:a.hex("#38bdf8")("Tailwind CSS"),value:"tailwindcss"},{name:a.hex("#4d9375")("Uno CSS"),value:"unocss"},{name:"none",value:""}]},{name:"stylePrecompiler",type:"list",message:"选择预编译器",choices:[{name:a.hex("#cc6699")("Sass"),value:"sass"},{name:a.hex("#1d365d")("Less"),value:"less"},{name:a.hex("#89ba1b")("Stylus"),value:"stylus"},{name:"none",value:""}]}]);Object.assign(e,t,{lanuage:s?"ts":"js"},{eslint:i?"eslint":""},c),o(e)}}catch(e){e.config&&e.config.url&&console.log(a.red("tags"===e.config.url.split("/").slice(-1)[0]&&"该项目没有tag")),h()}});
@@ -1 +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`))}}))});
1
+ var n=this&&this.__awaiter||function(n,t,i,o){return new(i||(i=Promise))(function(e,c){function r(n){try{u(o.next(n))}catch(n){c(n)}}function a(n){try{u(o.throw(n))}catch(n){c(n)}}function u(n){var t;n.done?e(n.value):(t=n.value,t instanceof i?t:new i(function(n){n(t)})).then(r,a)}u((o=o.apply(n,t||[])).next())})};import t from"chalk";import{execPromisified as i,processExit as o,wrapLoading as e}from"../utils/index.js";export default c=>n(void 0,void 0,void 0,function*(){let r="npm install -g ";return c?c.includes("@")?r+=c:r+=`ono-cli@${c}`:r+="ono-cli@latest",e(t.green("📦 更新中..."),()=>n(void 0,void 0,void 0,function*(){try{yield i(r),o("\n\n🚀 更新成功!\n\n")}catch(n){o(t.red(`\n\n❌ 更新失败: ${n.message}\n\n`))}}))});
@@ -1 +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:""}]}};
1
+ import e from"chalk";export const repoInfo={github:{personal:{private:"",public:"https://api.github.com/users/{username}/repos?type=all"},organization:"https://api.github.com/orgs/{organization}/repos?type=all",branch:"https://api.github.com/repos/{organization}/{repositories}/branches",tag:"https://api.github.com/repos/{organization}/{repositories}/tags",clone:"git clone --branch {branchOrTag} --depth 1 https://{repo}.com/{organization}/{projectName}.git {name}",authorization:"token {access_token}"},gitee:{personal:{private:"https://gitee.com/api/v5/user/repos?per_page=100",public:"https://gitee.com/api/v5/users/{username}/repos?per_page=100"},organization:"https://gitee.com/api/v5/orgs/{organization}/repos",branch:"https://gitee.com/api/v5/repos/{organization}/{repositories}/branches",tag:"https://gitee.com/api/v5/repos/{organization}/{repositories}/tags",clone:"git clone --branch {branchOrTag} --depth 1 https://{repo}.com/{organization}/{projectName}.git {name}",authorization:"Bearer {access_token}"}};export const frameworkDependenciesConfig={vue:{router:[{name:e.hex("#425d11")("Vue Router"),value:"vue-router"},{name:e.hex("#00bc7d")("TanStack Router"),value:"tanStack-router"},{name:"none",value:""}],store:[{name:e.hex("#425d11")("Pinia"),value:"pinia"},{name:e.hex("#3eaf7c")("Vuex"),value:"vuex"},{name:"none",value:""}]},react:{router:[{name:e.hex("#3451b2")("React Router"),value:"react-router"},{name:e.hex("#00bc7d")("TanStack Router"),value:"tanStack-router"},{name:"none",value:""}],store:[{name:e.hex("#764abc")("Redux"),value:"redux"},{name:e.hex("#1c16df")("Zustand"),value:"zustand"},{name:"none",value:""}]}};
@@ -1 +1 @@
1
- var __awaiter=this&&this.__awaiter||function(e,o,t,r){return new(t||(t=Promise))(function(n,a){function i(e){try{s(r.next(e))}catch(e){a(e)}}function c(e){try{s(r.throw(e))}catch(e){a(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(i,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{rmSync}from"fs";import{execPromisified,getConfig,processExit,wrapLoading}from"../utils/index.js";import{repoInfo}from"./infoConfig.js";const{organization:organization,access_token:access_token,repo:repo}=getConfig().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"]),a=Object.values(n).filter(Boolean),i=yield getOrganizationProjects();if(!i)return;const c=i.reduce((e,o)=>(e[o]=0,e),{});for(let e=0;e<i.length;e++)for(let o=0;o<a.length;o++)i[e].includes(a[o])&&c[i[e]]++;const s=Object.keys(c).find(e=>c[e]===a.length);s||processExit(chalk.red("❌ 没有找到匹配的项目模板!"));const p=yield getProjectBranches(s);cloneCodeTemplate(p[0],s,e)});
1
+ var e=this&&this.__awaiter||function(e,t,n,o){return new(n||(n=Promise))(function(r,i){function a(e){try{l(o.next(e))}catch(e){i(e)}}function c(e){try{l(o.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,c)}l((o=o.apply(e,t||[])).next())})},t=this&&this.__rest||function(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)t.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(n[o[r]]=e[o[r]])}return n};import n from"chalk";import{rmSync as o}from"fs";import r from"ono-fetch";import{execPromisified as i,getConfig as a,processExit as c,wrapLoading as l}from"../utils/index.js";import{repoInfo as s}from"./infoConfig.js";const{organization:d,access_token:p,repo:f}=a().config,g=()=>p?{headers:{Authorization:s[f].authorization.replace("{access_token}",p)}}:{};export const getOrganizationProjects=()=>e(void 0,void 0,void 0,function*(){try{return(yield r.get(s[f].organization.replace("{organization}",d),g())).data.map(e=>e.name)}catch(e){c(n.red(`🔍 没有找到组织项目!${n.white(`请使用 ${n.hex("#89ba1b")("ono-cli config -s")} 设置正确的 ${n.hex("#1c16df")("organization")} 和 ${n.hex("#1c16df")("access_token")} !`)}`))}});export const getProjectBranches=t=>e(void 0,void 0,void 0,function*(){const e=yield r.get(s[f].branch.replace("{organization}",d).replace("{repositories}",t),g());return e.data.length>0?e.data.map(e=>e.name):[]});export const getProjectTags=t=>e(void 0,void 0,void 0,function*(){const e=yield r.get(s[f].tag.replace("{organization}",d).replace("{repositories}",t),g());return e.data.length>0?e.data.map(e=>e.name):[]});export const cloneCodeTemplate=(t,r,a)=>e(void 0,void 0,void 0,function*(){return a.isOverwrite&&l(n.yellowBright("🚚 删除旧项目..."),()=>e(void 0,void 0,void 0,function*(){return o(a.path,{recursive:!0})})),l(n.greenBright(`📦 创建项目 ${a.name}...`),()=>e(void 0,void 0,void 0,function*(){try{yield i(s[f].clone.replace("{branchOrTag}",t).replace("{repo}",f).replace("{organization}",d).replace("{projectName}",r).replace("{name}",a.name)),o(`${a.name}/.git`,{recursive:!0,force:!0}),c(`\n\n🚀 创建项目成功!\n ${n.greenBright(`cd ${a.name}`)}\n ${n.greenBright("code .")}\n ${n.greenBright("npm install")}\n`)}catch(e){c(n.red("\n\n❌ 拉取项目失败!请检查网络连接状态、仓库权限或配置信息!\n"))}}))});export const cloneCodeDeps=o=>e(void 0,void 0,void 0,function*(){const{name:e,path:r,isOverwrite:i}=o,a=t(o,["name","path","isOverwrite"]),l=Object.values(a).filter(Boolean),s=yield getOrganizationProjects();if(!s)return;const d=s.reduce((e,t)=>(e[t]=0,e),{});for(let e=0;e<s.length;e++)for(let t=0;t<l.length;t++)s[e].includes(l[t])&&d[s[e]]++;const p=Object.keys(d).find(e=>d[e]===l.length);p||c(n.red("❌ 没有找到匹配的项目模板!"));const f=yield getProjectBranches(p);cloneCodeTemplate(f[0],p,o)});
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,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);
2
+ var o=this&&this.__awaiter||function(o,e,n,t){return new(n||(n=Promise))(function(a,i){function c(o){try{m(t.next(o))}catch(o){i(o)}}function r(o){try{m(t.throw(o))}catch(o){i(o)}}function m(o){var e;o.done?a(o.value):(e=o.value,e instanceof n?e:new n(function(o){o(e)})).then(c,r)}m((t=t.apply(o,e||[])).next())})};import e from"chalk";import{program as n}from"commander";import t from"./pkg.js";const a=(e,n)=>o(void 0,void 0,void 0,function*(){return(yield import(e)).default(...n)});n.name("ono-cli").usage("<command> [option]"),n.version(t.version),n.command("create [project-name]").description("创建新项目").option("-f, --force","强制创建").action((o,e)=>a("./commands/create.js",[o,e])),n.command("config [value]").description("配置信息").option("-g, --get","get value").option("-s, --set","set value").option("-d, --delete","delete value").option("-c, --clear","clear value").action((o,e)=>a("./commands/config.js",[e])),n.command("update [version]").description("update ono-cli").action((o,e)=>a("./commands/update.js",[o,e])),n.addHelpText("after",`Run ${e.blueBright("ono-cli <command> --help")} for detailed usage of given command.`),n.parse(process.argv);
package/bin/pkg.js CHANGED
@@ -1 +1 @@
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);export default require(join(__dirname,"../package.json"));
1
+ import{createRequire as o}from"module";import{dirname as r,join as m}from"path";import{fileURLToPath as t}from"url";const p=r(t(import.meta.url)),a=o(import.meta.url);export default a(m(p,"../package.json"));
@@ -1 +1 @@
1
- import{exec}from"child_process";import util from"util";export const execPromisified=util.promisify(exec);
1
+ import{exec as i}from"child_process";import o from"util";export const execPromisified=o.promisify(i);
@@ -1 +1 @@
1
- import{existsSync,readFileSync,writeFileSync}from"fs";import{decode,encode}from"ini";import{configPath}from"../common/index.js";export const getConfig=()=>{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}};
1
+ import{existsSync as o,readFileSync as t,writeFileSync as e}from"fs";import{decode as n,encode as i}from"ini";import{configPath as s}from"../common/index.js";export const baseConfig={username:"",organization:"",access_token:"",repo:"github",mode:"template"};export const getConfig=()=>{const r=Object.assign({},baseConfig);if(o(s)){const o=n(t(s,"utf-8"));Object.assign(r,o)}else e(s,i(r));return{config:r,configPath:s}};
@@ -1 +1 @@
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});
1
+ var t=this&&this.__awaiter||function(t,n,o,i){return new(o||(o=Promise))(function(r,c){function e(t){try{u(i.next(t))}catch(t){c(t)}}function a(t){try{u(i.throw(t))}catch(t){c(t)}}function u(t){var n;t.done?r(t.value):(n=t.value,n instanceof o?n:new o(function(t){t(n)})).then(e,a)}u((i=i.apply(t,n||[])).next())})};import n from"ora";export const wrapLoading=(o,i)=>t(void 0,void 0,void 0,function*(){const t=n(o);t.start();const r=yield i();return t.stop(),t.clear(),r});
@@ -1 +1 @@
1
- export const processExit=o=>{o&&console.log(o),process.exit()};
1
+ export const processExit=o=>{o&&console.log(o),process.exit(0)};
package/package.json CHANGED
@@ -1,49 +1,49 @@
1
- {
2
- "name": "ono-cli",
3
- "version": "0.1.3",
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
- "commit": "committier commit"
13
- },
14
- "files": [
15
- "bin",
16
- "lib"
17
- ],
18
- "keywords": [
19
- "ono",
20
- "cli",
21
- "template"
22
- ],
23
- "dependencies": {
24
- "axios": "^1.7.7",
25
- "chalk": "^5.3.0",
26
- "commander": "^12.0.0",
27
- "figlet": "^1.7.0",
28
- "fs-extra": "^11.2.0",
29
- "git-clone": "^0.2.0",
30
- "ini": "^5.0.0",
31
- "inquirer": "^11.0.2",
32
- "ora": "^8.0.1"
33
- },
34
- "devDependencies": {
35
- "@types/ini": "^4.1.1",
36
- "@types/node": "^22.7.2",
37
- "committier": "^0.2.3",
38
- "glob": "^13.0.0",
39
- "husky": "^9.1.7",
40
- "rimraf": "^6.1.2",
41
- "terser": "^5.44.1",
42
- "typescript": "^5.0.2"
43
- },
44
- "author": "ono",
45
- "license": "MIT",
46
- "publishConfig": {
47
- "access": "public"
48
- }
49
- }
1
+ {
2
+ "name": "ono-cli",
3
+ "version": "0.1.4",
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
+ "commit": "committier commit"
13
+ },
14
+ "files": [
15
+ "bin",
16
+ "lib"
17
+ ],
18
+ "keywords": [
19
+ "ono",
20
+ "cli",
21
+ "template"
22
+ ],
23
+ "dependencies": {
24
+ "chalk": "^5.3.0",
25
+ "commander": "^12.0.0",
26
+ "figlet": "^1.7.0",
27
+ "fs-extra": "^11.2.0",
28
+ "git-clone": "^0.2.0",
29
+ "ini": "^5.0.0",
30
+ "inquirer": "^11.0.2",
31
+ "ono-fetch": "^0.1.1",
32
+ "ora": "^8.0.1"
33
+ },
34
+ "devDependencies": {
35
+ "@types/ini": "^4.1.1",
36
+ "@types/node": "^22.7.2",
37
+ "committier": "^0.2.3",
38
+ "glob": "^13.0.0",
39
+ "husky": "^9.1.7",
40
+ "rimraf": "^6.1.2",
41
+ "terser": "^5.44.1",
42
+ "typescript": "^5.0.2"
43
+ },
44
+ "author": "ono",
45
+ "license": "MIT",
46
+ "publishConfig": {
47
+ "access": "public"
48
+ }
49
+ }