ono-cli 0.1.4 → 0.1.5
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 +0 -18
- package/bin/commands/config.js +1 -1
- package/bin/commands/create.js +1 -1
- package/bin/common/project.js +1 -1
- package/bin/utils/getConfig.js +1 -1
- package/package.json +2 -4
package/README.md
CHANGED
|
@@ -48,24 +48,6 @@ ono-cli config -g
|
|
|
48
48
|
|
|
49
49
|
如果需要删除某个配置项,可以使用以下命令:
|
|
50
50
|
|
|
51
|
-
**删除组织配置:**
|
|
52
|
-
|
|
53
|
-
```bash
|
|
54
|
-
ono-cli config -d organization
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
**删除访问令牌:**
|
|
58
|
-
|
|
59
|
-
```bash
|
|
60
|
-
ono-cli config -d access_token
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
**删除指定配置项:**
|
|
64
|
-
|
|
65
|
-
```bash
|
|
66
|
-
ono-cli config -d [CONFIG_KEY]
|
|
67
|
-
```
|
|
68
|
-
|
|
69
51
|
**交互式删除配置项:**
|
|
70
52
|
|
|
71
53
|
```bash
|
package/bin/commands/config.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=this&&this.__awaiter||function(e,
|
|
1
|
+
var e=this&&this.__awaiter||function(e,a,n,t){return new(n||(n=Promise))(function(o,i){function m(e){try{c(t.next(e))}catch(e){i(e)}}function s(e){try{c(t.throw(e))}catch(e){i(e)}}function c(e){var a;e.done?o(e.value):(a=e.value,a instanceof n?a:new n(function(e){e(a)})).then(m,s)}c((t=t.apply(e,a||[])).next())})};import a from"chalk";import{writeFileSync as n}from"fs";import{encode as t}from"ini";import o from"inquirer";import{repoInfo as i}from"../common/index.js";import{baseConfig as m,getCachedConfig 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:u}=s(),l=Object.keys(i)[0],p=(a,o)=>{e[a]=o,n(u,t(e)),c()};try{switch(l){case"get":{const{item:a}=yield o.prompt([{name:"item",type:"list",message:"选择想要查看的配置项",choices:[{name:"用户名称",value:"username"},{name:"组织名称",value:"organization"},{name:"访问令牌",value:"access_token"},{name:"代码托管平台",value:"repo"},{name:"模式",value:"mode"}]}]);return void c(e[a])}case"set":{const{key:e}=yield o.prompt([{name:"key",type:"list",message:"选择想要查看的配置项",choices:[{name:"用户名称",value:"username"},{name:"组织名称",value:"organization"},{name:"访问令牌",value:"access_token"},{name:"代码托管平台",value:"repo"},{name:"模式",value:"mode"}]}]),{value:a}=yield o.prompt([r(e)]);p(e,a)}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 n(u,t(m)),void c(a.greenBright("配置文件已清空"))}}catch(e){c()}});
|
package/bin/commands/create.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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{
|
|
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{getCachedConfig as u,processExit as h}from"../utils/index.js";const g=(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:""}],f=e=>""===e?[]:[{name:"router",type:"list",message:"选择路由",choices:m[e].router},{name:"store",type:"list",message:"选择状态管理仓库",choices:m[e].store}];export default(m,y)=>e(void 0,void 0,void 0,function*(){const{mode:e}=u().config;try{const u={name:"",path:"",isOverwrite:!1};if(m)u.name=m.trim();else{const{projectName:e}=yield n.prompt([{name:"projectName",type:"input",default:"my-project",message:"项目名称"}]);u.name=e?e.trim():"my-project"}const h=i.cwd(),d=s.join(h,u.name);if(t(d))if(y.force)u.isOverwrite=!0,u.path=d;else{const{action:e}=yield n.prompt([{name:"action",type:"list",message:`目录${u.name}已存在,是否覆盖?`,choices:[{name:"覆盖",value:"overwrite"},{name:"取消",value:"cancel"}]}]);switch(e){case"overwrite":u.isOverwrite=!0,u.path=d;break;case"cancel":return console.log(`取消创建目录${u.name}`)}}if("template"===e){const e=e=>c(e,t,u),a=yield l(),{projectName:t}=yield n.prompt([{name:"projectName",type:"list",message:"选择模板",choices:a}]),s=yield r(t),i=yield p(t),o=g(s,i);if(0===o.length)return e(s[0]);const{mode:m}=yield n.prompt([{name:"mode",type:"list",message:"请选择branch或tag",choices:o}]);if("branch"===m)if(s.length>1){const{branch:a}=yield n.prompt([{name:"branch",type:"list",message:"请选择branch",choices:s}]);e(a)}else e(s[0]);else if("tag"===m)if(i.length>0){const{tag:a}=yield n.prompt([{name:"tag",type:"list",message:"请选择tag",choices:i}]);e(a)}else e(i[0]);else e(s[0])}else if("dependencies"===e){const e=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:t,eslint:s}=yield n.prompt([{name:"language",type:"confirm",message:"是否使用TypeScript?"},{name:"eslint",type:"confirm",message:"是否使用Eslint?"}]),i=yield n.prompt([...f(e.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(u,e,{lanuage:t?"ts":"js"},{eslint:s?"eslint":""},i),o(u)}}catch(e){e.config&&e.config.url&&console.log(a.red("tags"===e.config.url.split("/").slice(-1)[0]&&"该项目没有tag")),h()}});
|
package/bin/common/project.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=this&&this.__awaiter||function(e,t,n
|
|
1
|
+
var e=this&&this.__awaiter||function(e,o,t,n){return new(t||(t=Promise))(function(r,i){function a(e){try{s(n.next(e))}catch(e){i(e)}}function c(e){try{s(n.throw(e))}catch(e){i(e)}}function s(e){var o;e.done?r(e.value):(o=e.value,o instanceof t?o:new t(function(e){e(o)})).then(a,c)}s((n=n.apply(e,o||[])).next())})},o=this&&this.__rest||function(e,o){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&o.indexOf(n)<0&&(t[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(n=Object.getOwnPropertySymbols(e);r<n.length;r++)o.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(e,n[r])&&(t[n[r]]=e[n[r]])}return t};import t from"chalk";import{rmSync as n}from"fs";import r from"ono-fetch";import{execPromisified as i,getCachedConfig as a,processExit as c,wrapLoading as s}from"../utils/index.js";import{repoInfo as l}from"./infoConfig.js";const p=e=>{const{access_token:o,repo:t}=e;return o?{headers:{Authorization:l[t].authorization.replace("{access_token}",o)}}:{}};export const getOrganizationProjects=()=>e(void 0,void 0,void 0,function*(){try{const{config:e}=a(),{organization:o,repo:t}=e;return(yield r.get(l[t].organization.replace("{organization}",o),p(e))).data.map(e=>e.name)}catch(e){c(t.red(`🔍 没有找到组织项目!${t.white(`请使用 ${t.hex("#89ba1b")("ono-cli config -s")} 设置正确的 ${t.hex("#1c16df")("organization")} 和 ${t.hex("#1c16df")("access_token")} !`)}`))}});export const getProjectBranches=o=>e(void 0,void 0,void 0,function*(){const{config:e}=a(),{organization:t,repo:n}=e,i=yield r.get(l[n].branch.replace("{organization}",t).replace("{repositories}",o),p(e));return i.data.length>0?i.data.map(e=>e.name):[]});export const getProjectTags=o=>e(void 0,void 0,void 0,function*(){const{config:e}=a(),{organization:t,repo:n}=e,i=yield r.get(l[n].tag.replace("{organization}",t).replace("{repositories}",o),p(e));return i.data.length>0?i.data.map(e=>e.name):[]});export const cloneCodeTemplate=(o,r,p)=>e(void 0,void 0,void 0,function*(){const{organization:d,repo:g}=a().config;p.isOverwrite&&(yield s(t.yellowBright("🚚 删除旧项目..."),()=>e(void 0,void 0,void 0,function*(){return n(p.path,{recursive:!0})}))),s(t.greenBright(`📦 创建项目 ${p.name}...`),()=>e(void 0,void 0,void 0,function*(){try{yield i(l[g].clone.replace("{branchOrTag}",o).replace("{repo}",g).replace("{organization}",d).replace("{projectName}",r).replace("{name}",p.name)),n(`${p.name}/.git`,{recursive:!0,force:!0}),c(`\n\n🚀 创建项目成功!\n ${t.greenBright(`cd ${p.name}`)}\n ${t.greenBright("code .")}\n ${t.greenBright("npm install")}\n`)}catch(e){c(t.red("\n\n❌ 拉取项目失败!请检查网络连接状态、仓库权限或配置信息!\n"))}}))});export const cloneCodeDeps=n=>e(void 0,void 0,void 0,function*(){const{name:e,path:r,isOverwrite:i}=n,a=o(n,["name","path","isOverwrite"]),s=Object.values(a).filter(Boolean),l=yield getOrganizationProjects();if(!l)return;const p=l.reduce((e,o)=>(e[o]=0,e),{});for(let e=0;e<l.length;e++)for(let o=0;o<s.length;o++)l[e].includes(s[o])&&p[l[e]]++;const d=Object.keys(p).find(e=>p[e]===s.length);d||c(t.red("❌ 没有找到匹配的项目模板!"));const g=yield getProjectBranches(d);cloneCodeTemplate(g[0],d,n)});
|
package/bin/utils/getConfig.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as o,readFileSync as
|
|
1
|
+
import{existsSync as o,readFileSync as n,writeFileSync as t}from"fs";import{decode as e,encode as i}from"ini";import{configPath as s}from"../common/index.js";export const baseConfig={username:"",organization:"",access_token:"",repo:"github",mode:"template"};const c=()=>{const c=Object.assign({},baseConfig);if(o(s)){const o=e(n(s,"utf-8"));Object.assign(c,o)}else t(s,i(c));return{config:c,configPath:s}};let r=null;export const getCachedConfig=()=>(r||(r=c().config),r);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ono-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "A CLI tool for ono template",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": "./bin/index.js",
|
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "rimraf bin && tsc && node scripts/minify.js",
|
|
10
10
|
"link": "npm link",
|
|
11
|
-
"unlink": "npm unlink ono-cli"
|
|
12
|
-
"commit": "committier commit"
|
|
11
|
+
"unlink": "npm unlink ono-cli"
|
|
13
12
|
},
|
|
14
13
|
"files": [
|
|
15
14
|
"bin",
|
|
@@ -34,7 +33,6 @@
|
|
|
34
33
|
"devDependencies": {
|
|
35
34
|
"@types/ini": "^4.1.1",
|
|
36
35
|
"@types/node": "^22.7.2",
|
|
37
|
-
"committier": "^0.2.3",
|
|
38
36
|
"glob": "^13.0.0",
|
|
39
37
|
"husky": "^9.1.7",
|
|
40
38
|
"rimraf": "^6.1.2",
|