ono-cli 0.1.2 → 0.1.3

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 CHANGED
@@ -1,21 +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
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
21
  SOFTWARE.
package/README.md CHANGED
@@ -157,7 +157,7 @@ ono-cli update [version]
157
157
  6. 输入令牌描述(Note)
158
158
  7. 设置过期时间(Expiration)
159
159
  8. 为令牌分配权限(Scopes):
160
- - 对于访问私有仓库,至少需要 [repo](file://d:\GitWarehouse\gitee\ono-cli\src\utils\getAllConfig.ts#L8-L8) 权限
160
+ - 对于访问私有仓库,至少需要 `repo` 权限
161
161
  - 如果要访问组织仓库,还需要 `admin:org` 或 `read:org` 权限
162
162
  - 如果访问的是私有仓库,还需要 `read:org` 权限
163
163
  9. 点击 "Generate token" 按钮
@@ -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{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}});
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 +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{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("退出创建项目"))}});
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 +1 @@
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`))}}))});
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 +1 @@
1
- export*from"./infoConfig.js";export*from"./project.js";
1
+ export*from"./constants.js";export*from"./infoConfig.js";export*from"./project.js";
@@ -1 +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)});
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)});
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),pkg=require(join(__dirname,"../package.json"));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);export default require(join(__dirname,"../package.json"));
@@ -0,0 +1 @@
1
+ import{exec}from"child_process";import util from"util";export const execPromisified=util.promisify(exec);
@@ -1 +1 @@
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}};
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 +1 @@
1
- export*from"./getAllConfig.js";export*from"./loading.js";export*from"./processExit.js";
1
+ export*from"./execPromisified.js";export*from"./getConfig.js";export*from"./loading.js";export*from"./processExit.js";
package/package.json CHANGED
@@ -1,49 +1,49 @@
1
- {
2
- "name": "ono-cli",
3
- "version": "0.1.2",
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.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
+ }
File without changes