ccommand 1.0.12 → 1.0.14

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
@@ -16,6 +16,7 @@ npm install -g ccommand # 安装ccommand
16
16
  ccommand -v # 查看版本
17
17
  ccommand find # 查找workspace
18
18
  ccommand # 执行当前script
19
+ ccommand -help # 查看帮助
19
20
  ```
20
21
 
21
22
  ## 使用 | Usage
@@ -23,7 +24,7 @@ ccommand # 执行当前script
23
24
  - ccommand playground 选取当前目录下的playground文件夹下的package.json文件中的scripts中的命令
24
25
  - ccommand playground -silent 支持额外的参数传参
25
26
 
26
- https://user-images.githubusercontent.com/57086651/198815869-ae9cb88c-3ebd-4193-94ff-bed0c974269c.mov
27
+ https://user-images.githubusercontent.com/57086651/198977837-1b2339dc-38d7-4565-b0b6-ea20ce7b5165.mov
27
28
 
28
29
 
29
30
  <a href="https://github.com/Simon-He95/sponsor" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" style="height: 51px !important;width: 217px !important;" ></a>
package/dist/index.js CHANGED
@@ -1,4 +1,12 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var N=require("module"),P=require("child_process"),x=require("fs"),D=require("path"),l=require("simon-js-tool"),O=require("fast-glob");function f(t){return t&&typeof t=="object"&&"default"in t?t:{default:t}}var u=f(P),y=f(x),w=f(D),L=f(O),R=require;const F=R("yamljs");let d=[],c=null;async function k(){const{status:t}=u.default.spawnSync("gum -v",{shell:!0,encoding:"utf-8"});if(t!==0){console.log("install gum...");const{status:s}=u.default.spawnSync("brew install gum",{shell:!0});if(s!==0){const{status:o}=u.default.spawnSync(`sudo mkdir -p /etc/apt/keyrings
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var A=require("module"),F=require("child_process"),x=require("fs"),O=require("path"),f=require("simon-js-tool"),B=require("fast-glob"),C=require("chalk"),I=require("terminal-link");function p(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var d=p(F),v=p(x),_=p(O),R=p(B),r=p(C),k=p(I),N=require;const T=N("yamljs");let h=[],o=null;async function b(){const e=console.log,s="__ccommand__split",{status:l}=d.default.spawnSync("gum -v",{shell:!0,encoding:"utf-8"});if(l!==0){e(r.default.blue("install gum..."));const{status:t}=d.default.spawnSync("brew install gum",{shell:!0});if(t!==0){const{status:a}=d.default.spawnSync(`sudo mkdir -p /etc/apt/keyrings
2
2
  curl -fsSL https://repo.charm.sh/apt/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/charm.gpg
3
3
  echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" | sudo tee /etc/apt/sources.list.d/charm.list
4
- sudo apt update && sudo apt install gum`,{shell:!0});if(o!==0)return console.log("gum install error")}console.log("gum install successfully")}const a=process.argv.slice(2);if(a[0]==="-v"){const{version:s}=await l.getPkg();console.log(`ccommand Version: ${s}`);return}const[i,n]=I(a);let e=i;const r=l.getPkgTool();if(a[0]==="find")if(r==="yarn")await v(),e=u.default.spawnSync(`echo ${d.join(",")} | sed "s/,/\\n/g" | gum filter`,{shell:!0,stdio:["inherit","pipe","inherit"],encoding:"utf8"}).output[1].trim();else if(r==="pnpm")await $(),e=u.default.spawnSync(`echo ${d.join(",")} | sed "s/,/\\n/g" | gum filter`,{shell:!0,stdio:["inherit","pipe","inherit"],encoding:"utf8"}).output[1].trim();else return console.log("find command only support yarn or pnpm");const p=await q();if(!p)return console.log("No scripts found");const m=[],_=Object.keys(p).reduce((s,o)=>{const g=p[o];return m.push(o),s+=`"${o}: ${g}",`,s},""),h=u.default.spawnSync(`echo ${_} | sed "s/,/\\n/g" | gum filter | cut -d' ' -f1`,{shell:!0,stdio:["inherit","pipe","inherit"],encoding:"utf8"}).output[1];if(!h)return console.log("\u5DF2\u53D6\u6D88"),process.exit();u.default.spawnSync(b(),{shell:!0,stdio:"inherit"});function S(s){return m.find(o=>s.startsWith(o))}function b(){let s="",o="";const g=r!=="yarn";return r==="npm"?(o=n?` -- ${n}`:"",s=e?` --prefix ${e} `:" "):r==="pnpm"?(o=n?` ${n}`:"",s=e?` --filter ${e.slice(e.lastIndexOf("/")+1)} `:" "):r==="yarn"?(o=n?` ${n}`:"",s=e?` workspace ${e.slice(e.lastIndexOf("/")+1)} `:" "):r==="bun"&&(o=n?` ${n}`:"",s=""),`${r}${g?" run":" "}${s}${S(h)}${o}`}async function q(){try{if(!e||r==="bun"||r==="npm")return(await l.getPkg("./package.json"))?.scripts;if(r==="pnpm")return(await $())[e]||(await l.getPkg(`${e}/package.json`))?.scripts;if(r==="yarn")return(await v())[e]||(await l.getPkg(`${e}/package.json`))?.scripts}catch{console.log("The package.json is not found in workspace or current directory, please check"),process.exit()}}}async function $(){if(c)return c;const t=await y.default.readFileSync(w.default.resolve(process.cwd(),"pnpm-workspace.yaml"),"utf-8"),a=F.parse(t)?.packages||[];return c=await j(a)||{},d=Object.keys(c),c}async function v(){if(c)return c;const t=await y.default.readFileSync(w.default.resolve(process.cwd(),"package.json"),"utf-8"),a=JSON.parse(t)?.workspaces||[];return c=await j(a)||{},d=Object.keys(c),c}function I(t){const a=t[0];return a?a.startsWith("--")?[".",t.join(" ")]:[a,t.slice(1).join(" ")]:["",""]}async function j(t){if(!t.length)return;const a=await L.default(t.map(i=>`${i}/package.json`),{dot:!0,ignore:["**/node_modules/**"]});return Promise.all(a.map(async i=>{const n=await l.getPkg(i);if(!n)return;const{name:e,scripts:r}=n;return{name:e,scripts:r}})).then(i=>i.reduce((n,e)=>{const{name:r,scripts:p}=e;return n[r]=p,n},{}))}k(),exports.ccommand=k;
4
+ sudo apt update && sudo apt install gum`,{shell:!0});if(a!==0){const g=k.default("the official website of gum","https://github.com/charmbracelet/gum#installation");return e(r.default.red("gum install error, you can install it yourself through ",r.default.yellow.bold(g)))}}e(r.default.green("gum install successfully"))}const c=process.argv.slice(2);if(c[0]==="-v"){const{version:t}=await f.getPkg();return e(r.default.green(`ccommand Version: ${t}`))}if(c[0]==="-help"){const t=k.default("open an issue","https://github.com/Simon-He95/ccommand/issues"),a=k.default("\u2728star it","https://github.com/Simon-He95/ccommand");return e(r.default.white(`
5
+ ${r.default.bgBlueBright.bold("Common Command:")}
6
+ ${r.default.cyanBright(`- ccommand -v \u67E5\u770B\u5F53\u524D\u7248\u672C
7
+ - ccommand -help \u67E5\u770B\u5E2E\u52A9
8
+ - ccommand \u6267\u884C\u5F53\u524Dpackage.json
9
+ - ccommand find \u67E5\u627E\u5F53\u524Dworkspace\u7684\u6240\u6709\u76EE\u5F55
10
+ `)}
11
+ If you encounter any problems, you can ${r.default.magentaBright(t)}.
12
+ If you like it, please ${r.default.cyan.bold(a)}`))}const[m,u]=U(c);let n=m;const i=f.getPkgTool();if(c[0]==="find")if(i==="yarn")await S(),n=d.default.spawnSync(`echo ${h.join(",")} | sed "s/,/\\n/g" | gum filter`,{shell:!0,stdio:["inherit","pipe","inherit"],encoding:"utf8"}).output[1].trim();else if(i==="pnpm")await j(),n=d.default.spawnSync(`echo ${h.join(",")} | sed "s/,/\\n/g" | gum filter`,{shell:!0,stdio:["inherit","pipe","inherit"],encoding:"utf8"}).output[1].trim();else return e(r.default.red("find command only support yarn or pnpm"));const y=await E();if(!y)return e(r.default.red("No scripts found"));const w=[],D=Object.keys(y).reduce((t,a)=>{const g=y[a];return w.push(a),t+=`"${a}: ${g}"${s}`,t},""),$=d.default.spawnSync(`echo ${D} | sed "s/${s}/\\n/g" | gum filter | cut -d' ' -f1`,{shell:!0,stdio:["inherit","pipe","inherit"],encoding:"utf8"}).output[1];if(!$)return e(r.default.yellow("\u5DF2\u53D6\u6D88")),process.exit();d.default.spawnSync(L(),{shell:!0,stdio:"inherit"});function P(t){return w.find(a=>t.startsWith(a))}function L(){let t="",a="";const g=i!=="yarn";return i==="npm"?(a=u?` -- ${u}`:"",t=n?` --prefix ${n} `:" "):i==="pnpm"?(a=u?` ${u}`:"",t=n?` --filter ${n.slice(n.lastIndexOf("/")+1)} `:" "):i==="yarn"?(a=u?` ${u}`:"",t=n?` workspace ${n.slice(n.lastIndexOf("/")+1)} `:" "):i==="bun"&&(a=u?` ${u}`:"",t=""),`${i}${g?" run":" "}${t}${P($)}${a}`}async function E(){try{if(!n||i==="bun"||i==="npm")return(await f.getPkg("./package.json"))?.scripts;if(i==="pnpm")return(await j())[n]||(await f.getPkg(`${n}/package.json`))?.scripts;if(i==="yarn")return(await S())[n]||(await f.getPkg(`${n}/package.json`))?.scripts}catch{e(r.default.red("The package.json is not found in workspace or current directory, please check")),process.exit()}}}async function j(){if(o)return o;const e=await v.default.readFileSync(_.default.resolve(process.cwd(),"pnpm-workspace.yaml"),"utf-8"),s=T.parse(e)?.packages||[];return o=await q(s)||{},h=Object.keys(o),o}async function S(){if(o)return o;const e=await v.default.readFileSync(_.default.resolve(process.cwd(),"package.json"),"utf-8"),s=JSON.parse(e)?.workspaces||[];return o=await q(s)||{},h=Object.keys(o),o}function U(e){const s=e[0];return s?s.startsWith("--")?[".",e.join(" ")]:[s,e.slice(1).join(" ")]:["",""]}async function q(e){if(!e.length)return;const s=await R.default(e.map(l=>`${l}/package.json`),{dot:!0,ignore:["**/node_modules/**"]});return Promise.all(s.map(async l=>{const c=await f.getPkg(l);if(!c)return;const{name:m,scripts:u}=c;return{name:m,scripts:u}})).then(l=>l.reduce((c,m)=>{const{name:u,scripts:n}=m;return c[u]=n,c},{}))}b(),exports.ccommand=b;
package/dist/index.mjs CHANGED
@@ -1,5 +1,13 @@
1
1
  #!/usr/bin/env node
2
- import{createRequire as D}from"module";import p from"child_process";import h from"fs";import w from"path";import{getPkg as l,getPkgTool as O}from"simon-js-tool";import P from"fast-glob";var q=D(import.meta.url);const F=q("yamljs");let f=[],a=null;async function y(){const{status:i}=p.spawnSync("gum -v",{shell:!0,encoding:"utf-8"});if(i!==0){console.log("install gum...");const{status:e}=p.spawnSync("brew install gum",{shell:!0});if(e!==0){const{status:o}=p.spawnSync(`sudo mkdir -p /etc/apt/keyrings
2
+ import{createRequire as O}from"module";import l from"child_process";import $ from"fs";import b from"path";import{getPkg as g,getPkgTool as _}from"simon-js-tool";import C from"fast-glob";import r from"chalk";import y from"terminal-link";var L=O(import.meta.url);const P=L("yamljs");let d=[],u=null;async function S(){const t=console.log,o="__ccommand__split",{status:p}=l.spawnSync("gum -v",{shell:!0,encoding:"utf-8"});if(p!==0){t(r.blue("install gum..."));const{status:e}=l.spawnSync("brew install gum",{shell:!0});if(e!==0){const{status:s}=l.spawnSync(`sudo mkdir -p /etc/apt/keyrings
3
3
  curl -fsSL https://repo.charm.sh/apt/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/charm.gpg
4
4
  echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" | sudo tee /etc/apt/sources.list.d/charm.list
5
- sudo apt update && sudo apt install gum`,{shell:!0});if(o!==0)return console.log("gum install error")}console.log("gum install successfully")}const r=process.argv.slice(2);if(r[0]==="-v"){const{version:e}=await l();console.log(`ccommand Version: ${e}`);return}const[c,n]=N(r);let t=c;const s=O();if(r[0]==="find")if(s==="yarn")await $(),t=p.spawnSync(`echo ${f.join(",")} | sed "s/,/\\n/g" | gum filter`,{shell:!0,stdio:["inherit","pipe","inherit"],encoding:"utf8"}).output[1].trim();else if(s==="pnpm")await k(),t=p.spawnSync(`echo ${f.join(",")} | sed "s/,/\\n/g" | gum filter`,{shell:!0,stdio:["inherit","pipe","inherit"],encoding:"utf8"}).output[1].trim();else return console.log("find command only support yarn or pnpm");const u=await x();if(!u)return console.log("No scripts found");const g=[],S=Object.keys(u).reduce((e,o)=>{const m=u[o];return g.push(o),e+=`"${o}: ${m}",`,e},""),d=p.spawnSync(`echo ${S} | sed "s/,/\\n/g" | gum filter | cut -d' ' -f1`,{shell:!0,stdio:["inherit","pipe","inherit"],encoding:"utf8"}).output[1];if(!d)return console.log("\u5DF2\u53D6\u6D88"),process.exit();p.spawnSync(b(),{shell:!0,stdio:"inherit"});function v(e){return g.find(o=>e.startsWith(o))}function b(){let e="",o="";const m=s!=="yarn";return s==="npm"?(o=n?` -- ${n}`:"",e=t?` --prefix ${t} `:" "):s==="pnpm"?(o=n?` ${n}`:"",e=t?` --filter ${t.slice(t.lastIndexOf("/")+1)} `:" "):s==="yarn"?(o=n?` ${n}`:"",e=t?` workspace ${t.slice(t.lastIndexOf("/")+1)} `:" "):s==="bun"&&(o=n?` ${n}`:"",e=""),`${s}${m?" run":" "}${e}${v(d)}${o}`}async function x(){try{if(!t||s==="bun"||s==="npm")return(await l("./package.json"))?.scripts;if(s==="pnpm")return(await k())[t]||(await l(`${t}/package.json`))?.scripts;if(s==="yarn")return(await $())[t]||(await l(`${t}/package.json`))?.scripts}catch{console.log("The package.json is not found in workspace or current directory, please check"),process.exit()}}}async function k(){if(a)return a;const i=await h.readFileSync(w.resolve(process.cwd(),"pnpm-workspace.yaml"),"utf-8"),r=F.parse(i)?.packages||[];return a=await j(r)||{},f=Object.keys(a),a}async function $(){if(a)return a;const i=await h.readFileSync(w.resolve(process.cwd(),"package.json"),"utf-8"),r=JSON.parse(i)?.workspaces||[];return a=await j(r)||{},f=Object.keys(a),a}function N(i){const r=i[0];return r?r.startsWith("--")?[".",i.join(" ")]:[r,i.slice(1).join(" ")]:["",""]}async function j(i){if(!i.length)return;const r=await P(i.map(c=>`${c}/package.json`),{dot:!0,ignore:["**/node_modules/**"]});return Promise.all(r.map(async c=>{const n=await l(c);if(!n)return;const{name:t,scripts:s}=n;return{name:t,scripts:s}})).then(c=>c.reduce((n,t)=>{const{name:s,scripts:u}=t;return n[s]=u,n},{}))}y();export{y as ccommand};
5
+ sudo apt update && sudo apt install gum`,{shell:!0});if(s!==0){const f=y("the official website of gum","https://github.com/charmbracelet/gum#installation");return t(r.red("gum install error, you can install it yourself through ",r.yellow.bold(f)))}}t(r.green("gum install successfully"))}const c=process.argv.slice(2);if(c[0]==="-v"){const{version:e}=await g();return t(r.green(`ccommand Version: ${e}`))}if(c[0]==="-help"){const e=y("open an issue","https://github.com/Simon-He95/ccommand/issues"),s=y("\u2728star it","https://github.com/Simon-He95/ccommand");return t(r.white(`
6
+ ${r.bgBlueBright.bold("Common Command:")}
7
+ ${r.cyanBright(`- ccommand -v \u67E5\u770B\u5F53\u524D\u7248\u672C
8
+ - ccommand -help \u67E5\u770B\u5E2E\u52A9
9
+ - ccommand \u6267\u884C\u5F53\u524Dpackage.json
10
+ - ccommand find \u67E5\u627E\u5F53\u524Dworkspace\u7684\u6240\u6709\u76EE\u5F55
11
+ `)}
12
+ If you encounter any problems, you can ${r.magentaBright(e)}.
13
+ If you like it, please ${r.cyan.bold(s)}`))}const[m,i]=I(c);let n=m;const a=_();if(c[0]==="find")if(a==="yarn")await v(),n=l.spawnSync(`echo ${d.join(",")} | sed "s/,/\\n/g" | gum filter`,{shell:!0,stdio:["inherit","pipe","inherit"],encoding:"utf8"}).output[1].trim();else if(a==="pnpm")await j(),n=l.spawnSync(`echo ${d.join(",")} | sed "s/,/\\n/g" | gum filter`,{shell:!0,stdio:["inherit","pipe","inherit"],encoding:"utf8"}).output[1].trim();else return t(r.red("find command only support yarn or pnpm"));const h=await B();if(!h)return t(r.red("No scripts found"));const w=[],E=Object.keys(h).reduce((e,s)=>{const f=h[s];return w.push(s),e+=`"${s}: ${f}"${o}`,e},""),k=l.spawnSync(`echo ${E} | sed "s/${o}/\\n/g" | gum filter | cut -d' ' -f1`,{shell:!0,stdio:["inherit","pipe","inherit"],encoding:"utf8"}).output[1];if(!k)return t(r.yellow("\u5DF2\u53D6\u6D88")),process.exit();l.spawnSync(x(),{shell:!0,stdio:"inherit"});function F(e){return w.find(s=>e.startsWith(s))}function x(){let e="",s="";const f=a!=="yarn";return a==="npm"?(s=i?` -- ${i}`:"",e=n?` --prefix ${n} `:" "):a==="pnpm"?(s=i?` ${i}`:"",e=n?` --filter ${n.slice(n.lastIndexOf("/")+1)} `:" "):a==="yarn"?(s=i?` ${i}`:"",e=n?` workspace ${n.slice(n.lastIndexOf("/")+1)} `:" "):a==="bun"&&(s=i?` ${i}`:"",e=""),`${a}${f?" run":" "}${e}${F(k)}${s}`}async function B(){try{if(!n||a==="bun"||a==="npm")return(await g("./package.json"))?.scripts;if(a==="pnpm")return(await j())[n]||(await g(`${n}/package.json`))?.scripts;if(a==="yarn")return(await v())[n]||(await g(`${n}/package.json`))?.scripts}catch{t(r.red("The package.json is not found in workspace or current directory, please check")),process.exit()}}}async function j(){if(u)return u;const t=await $.readFileSync(b.resolve(process.cwd(),"pnpm-workspace.yaml"),"utf-8"),o=P.parse(t)?.packages||[];return u=await D(o)||{},d=Object.keys(u),u}async function v(){if(u)return u;const t=await $.readFileSync(b.resolve(process.cwd(),"package.json"),"utf-8"),o=JSON.parse(t)?.workspaces||[];return u=await D(o)||{},d=Object.keys(u),u}function I(t){const o=t[0];return o?o.startsWith("--")?[".",t.join(" ")]:[o,t.slice(1).join(" ")]:["",""]}async function D(t){if(!t.length)return;const o=await C(t.map(p=>`${p}/package.json`),{dot:!0,ignore:["**/node_modules/**"]});return Promise.all(o.map(async p=>{const c=await g(p);if(!c)return;const{name:m,scripts:i}=c;return{name:m,scripts:i}})).then(p=>p.reduce((c,m)=>{const{name:i,scripts:n}=m;return c[i]=n,c},{}))}S();export{S as ccommand};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccommand",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "packageManager": "pnpm@6.32.3",
5
5
  "description": "ccommand",
6
6
  "author": "Simon He",
@@ -49,8 +49,10 @@
49
49
  },
50
50
  "dependencies": {
51
51
  "@vueuse/core": "^8.1.1",
52
+ "chalk": "^5.1.2",
52
53
  "fast-glob": "^3.2.12",
53
54
  "simon-js-tool": "^4.1.13",
55
+ "terminal-link": "^3.0.0",
54
56
  "vue": "^3.2.36",
55
57
  "yamljs": "^0.3.0"
56
58
  },