ccommand 1.0.21 → 1.0.22
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/dist/index.js +7 -6
- package/dist/index.mjs +4 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var N=require("module"),D=require("fs"),q=require("path"),s=require("simon-js-tool"),B=require("fast-glob"),C=require("chalk"),L=require("terminal-link");function m(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var b=m(D),j=m(q),P=m(B),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var N=require("module"),D=require("fs"),q=require("path"),s=require("simon-js-tool"),B=require("fast-glob"),C=require("chalk"),L=require("terminal-link");function m(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var b=m(D),j=m(q),P=m(B),a=m(C),y=m(L),x=require,O="1.0.22";const A=x("yamljs");let k=[],f=null;async function v(){const e=console.log,l="__ccommand__split",{status:i}=s.jsShell("gum -v","pipe");if(i!==0){e(a.default.blue("install gum..."));const{status:r}=s.jsShell("brew install gum");if(r!==0){const{status:c}=s.jsShell(`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`);if(c!==0){const d=
|
|
5
|
-
${
|
|
6
|
-
${
|
|
4
|
+
sudo apt update && sudo apt install gum`);if(c!==0){const d=y.default("the official website of gum","https://github.com/charmbracelet/gum#installation");return e(a.default.red("gum install error, you can install it yourself through ",a.default.yellow.bold(d)))}}e(a.default.green("gum install successfully"))}const t=process.argv.slice(2);if(t[0]==="-v"||t[0]==="--version")return e(a.default.green(`ccommand Version: ${O}`));if(t[0]==="-help"){const r=y.default("open an issue","https://github.com/Simon-He95/ccommand/issues"),c=y.default("\u2728star it","https://github.com/Simon-He95/ccommand");return e(a.default.white(`
|
|
5
|
+
${a.default.bgBlueBright.bold("Common Command:")}
|
|
6
|
+
${a.default.cyanBright(`- ccommand -v \u67E5\u770B\u5F53\u524D\u7248\u672C
|
|
7
7
|
- ccommand -help \u67E5\u770B\u5E2E\u52A9
|
|
8
8
|
- ccommand \u6267\u884C\u5F53\u524Dpackage.json
|
|
9
9
|
- ccommand find \u67E5\u627E\u5F53\u524Dworkspace\u7684\u6240\u6709\u76EE\u5F55
|
|
10
10
|
`)}
|
|
11
|
-
If you encounter any problems, you can ${
|
|
12
|
-
If you like it, please ${
|
|
11
|
+
If you encounter any problems, you can ${a.default.magentaBright(r)}.
|
|
12
|
+
If you like it, please ${a.default.cyan.bold(c)}`))}const u=s.getPkgTool();if(t[0])try{const r=(await s.getPkg("./package.json")||{})?.scripts;if(r&&r[t[0]]){switch(e(a.default.yellow(`ccommand is executing ${a.default.bgCyan(`'${t[0]}'`)} \u{1F914} `)),u){case"npm":s.jsShell(`npm run ${t[0]}`);break;case"pnpm":s.jsShell(`pnpm run ${t[0]}`);break;case"yarn":s.jsShell(`yarn ${t[0]}`);break;case"bun":s.jsShell(`bun ${t[0]}`);break}return e(a.default.green(`command ${t[0]} run successfully`))}}catch{}const[p,o]=I(t);let n=p;if(t[0]==="find")if(u==="yarn"){await g(u);const{result:r}=s.jsShell(`echo ${k.join(",")} | sed "s/,/\\n/g" | gum filter --placeholder=" \u{1F914}\u8BF7\u9009\u62E9\u4E00\u4E2A\u8981\u6267\u884C\u7684\u76EE\u5F55"`,"pipe");if(n=r,!n)return console.log(a.default.yellow("\u5DF2\u53D6\u6D88"))}else if(u==="pnpm"){await g(u);const{result:r}=s.jsShell(`echo ${k.join(",")} | sed "s/,/\\n/g" | gum filter --placeholder=" \u{1F914}\u8BF7\u9009\u62E9\u4E00\u4E2A\u8981\u6267\u884C\u7684\u76EE\u5F55"`,"pipe");if(n=r.trim(),!n)return console.log(a.default.yellow("\u5DF2\u53D6\u6D88"))}else return e(a.default.red("find command only support yarn or pnpm"));const h=await F();if(!h)return e(a.default.red("No scripts found"));const $=[],E=Object.keys(h).reduce((r,c)=>{const d=h[c];return $.push(c),r+=`"${c}: ${d.replace(/\"/g,"'")}"${l}`,r},""),{result:w}=s.jsShell(`echo ${E} | sed "s/${l}/\\n/g" | gum filter --placeholder=" \u{1F914}\u8BF7\u9009\u62E9\u4E00\u4E2A\u8981\u6267\u884C\u7684\u6307\u4EE4" | cut -d' ' -f1`,"pipe");if(!w)return e(a.default.yellow("\u5DF2\u53D6\u6D88")),process.exit();s.jsShell(_());function S(r){return $.find(c=>r.startsWith(c))}function _(){let r="",c="";const d=u!=="yarn";return u==="npm"?(c=o?` -- ${o}`:"",r=n?` --prefix ${n} `:" "):u==="pnpm"?(c=o?` ${o}`:"",r=n?` --filter ${n.slice(n.lastIndexOf("/")+1)} `:" "):u==="yarn"?(c=o?` ${o}`:"",r=n?` workspace ${n.slice(n.lastIndexOf("/")+1)} `:" "):u==="bun"&&(c=o?` ${o}`:"",r=""),`${u}${d?" run":" "}${r}${S(w)}${c}`}async function F(){try{if(!n||u==="bun"||u==="npm")return(await s.getPkg("./package.json"))?.scripts;if(u==="pnpm")return(await g(u))[n]||(await s.getPkg(`${n}/package.json`))?.scripts;if(u==="yarn")return(await g(u))[n]||(await s.getPkg(`${n}/package.json`))?.scripts}catch{e(a.default.red(`"${t[0]}" is not found in workspace, current directory
|
|
13
|
+
or current scripts, please check`)),process.exit()}}}async function g(e){if(f)return f;const l=e==="pnpm"?await b.default.readFileSync(j.default.resolve(process.cwd(),"pnpm-workspace.yaml"),"utf-8"):await b.default.readFileSync(j.default.resolve(process.cwd(),"package.json"),"utf-8"),i=e==="pnpm"?A.parse(l)?.packages||[]:JSON.parse(l)?.workspaces||[];return f=await R(i)||{},k=Object.keys(f).filter(t=>f[t]&&Object.keys(f[t]).length),f}function I(e){const l=e[0];return l?l.startsWith("--")?[".",e.join(" ")]:[l,e.slice(1).join(" ")]:["",""]}async function R(e){if(!e.length)return;const l=await P.default(e.map(i=>`${i}/package.json`),{dot:!0,ignore:["**/node_modules/**"]});return Promise.all(l.map(async i=>{const t=await s.getPkg(i);if(!t)return;const{name:u,scripts:p}=t;return{name:u,scripts:p}})).then(i=>i.reduce((t,u)=>{const{name:p,scripts:o}=u;return t[p]=o,t},{}))}v(),exports.ccommand=v;
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{createRequire as B}from"module";import b from"fs";import E from"path";import{jsShell as c,getPkgTool as C,getPkg as g}from"simon-js-tool";import x from"fast-glob";import s from"chalk";import y from"terminal-link";var O=B(import.meta.url),A="1.0.
|
|
2
|
+
import{createRequire as B}from"module";import b from"fs";import E from"path";import{jsShell as c,getPkgTool as C,getPkg as g}from"simon-js-tool";import x from"fast-glob";import s from"chalk";import y from"terminal-link";var O=B(import.meta.url),A="1.0.22";const L=O("yamljs");let k=[],l=null;async function F(){const r=console.log,a="__ccommand__split",{status:p}=c("gum -v","pipe");if(p!==0){r(s.blue("install gum..."));const{status:t}=c("brew install gum");if(t!==0){const{status:o}=c(`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`);if(
|
|
5
|
+
sudo apt update && sudo apt install gum`);if(o!==0){const f=y("the official website of gum","https://github.com/charmbracelet/gum#installation");return r(s.red("gum install error, you can install it yourself through ",s.yellow.bold(f)))}}r(s.green("gum install successfully"))}const e=process.argv.slice(2);if(e[0]==="-v"||e[0]==="--version")return r(s.green(`ccommand Version: ${A}`));if(e[0]==="-help"){const t=y("open an issue","https://github.com/Simon-He95/ccommand/issues"),o=y("\u2728star it","https://github.com/Simon-He95/ccommand");return r(s.white(`
|
|
6
6
|
${s.bgBlueBright.bold("Common Command:")}
|
|
7
7
|
${s.cyanBright(`- ccommand -v \u67E5\u770B\u5F53\u524D\u7248\u672C
|
|
8
8
|
- ccommand -help \u67E5\u770B\u5E2E\u52A9
|
|
@@ -10,4 +10,5 @@ import{createRequire as B}from"module";import b from"fs";import E from"path";imp
|
|
|
10
10
|
- ccommand find \u67E5\u627E\u5F53\u524Dworkspace\u7684\u6240\u6709\u76EE\u5F55
|
|
11
11
|
`)}
|
|
12
12
|
If you encounter any problems, you can ${s.magentaBright(t)}.
|
|
13
|
-
If you like it, please ${s.cyan.bold(
|
|
13
|
+
If you like it, please ${s.cyan.bold(o)}`))}const n=C();if(e[0])try{const t=(await g("./package.json")||{})?.scripts;if(t&&t[e[0]]){switch(r(s.yellow(`ccommand is executing ${s.bgCyan(`'${e[0]}'`)} \u{1F914} `)),n){case"npm":c(`npm run ${e[0]}`);break;case"pnpm":c(`pnpm run ${e[0]}`);break;case"yarn":c(`yarn ${e[0]}`);break;case"bun":c(`bun ${e[0]}`);break}return r(s.green(`command ${e[0]} run successfully`))}}catch{}const[m,i]=_(e);let u=m;if(e[0]==="find")if(n==="yarn"){await d(n);const{result:t}=c(`echo ${k.join(",")} | sed "s/,/\\n/g" | gum filter --placeholder=" \u{1F914}\u8BF7\u9009\u62E9\u4E00\u4E2A\u8981\u6267\u884C\u7684\u76EE\u5F55"`,"pipe");if(u=t,!u)return console.log(s.yellow("\u5DF2\u53D6\u6D88"))}else if(n==="pnpm"){await d(n);const{result:t}=c(`echo ${k.join(",")} | sed "s/,/\\n/g" | gum filter --placeholder=" \u{1F914}\u8BF7\u9009\u62E9\u4E00\u4E2A\u8981\u6267\u884C\u7684\u76EE\u5F55"`,"pipe");if(u=t.trim(),!u)return console.log(s.yellow("\u5DF2\u53D6\u6D88"))}else return r(s.red("find command only support yarn or pnpm"));const h=await S();if(!h)return r(s.red("No scripts found"));const $=[],j=Object.keys(h).reduce((t,o)=>{const f=h[o];return $.push(o),t+=`"${o}: ${f.replace(/\"/g,"'")}"${a}`,t},""),{result:w}=c(`echo ${j} | sed "s/${a}/\\n/g" | gum filter --placeholder=" \u{1F914}\u8BF7\u9009\u62E9\u4E00\u4E2A\u8981\u6267\u884C\u7684\u6307\u4EE4" | cut -d' ' -f1`,"pipe");if(!w)return r(s.yellow("\u5DF2\u53D6\u6D88")),process.exit();c(v());function D(t){return $.find(o=>t.startsWith(o))}function v(){let t="",o="";const f=n!=="yarn";return n==="npm"?(o=i?` -- ${i}`:"",t=u?` --prefix ${u} `:" "):n==="pnpm"?(o=i?` ${i}`:"",t=u?` --filter ${u.slice(u.lastIndexOf("/")+1)} `:" "):n==="yarn"?(o=i?` ${i}`:"",t=u?` workspace ${u.slice(u.lastIndexOf("/")+1)} `:" "):n==="bun"&&(o=i?` ${i}`:"",t=""),`${n}${f?" run":" "}${t}${D(w)}${o}`}async function S(){try{if(!u||n==="bun"||n==="npm")return(await g("./package.json"))?.scripts;if(n==="pnpm")return(await d(n))[u]||(await g(`${u}/package.json`))?.scripts;if(n==="yarn")return(await d(n))[u]||(await g(`${u}/package.json`))?.scripts}catch{r(s.red(`"${e[0]}" is not found in workspace, current directory
|
|
14
|
+
or current scripts, please check`)),process.exit()}}}async function d(r){if(l)return l;const a=r==="pnpm"?await b.readFileSync(E.resolve(process.cwd(),"pnpm-workspace.yaml"),"utf-8"):await b.readFileSync(E.resolve(process.cwd(),"package.json"),"utf-8"),p=r==="pnpm"?L.parse(a)?.packages||[]:JSON.parse(a)?.workspaces||[];return l=await I(p)||{},k=Object.keys(l).filter(e=>l[e]&&Object.keys(l[e]).length),l}function _(r){const a=r[0];return a?a.startsWith("--")?[".",r.join(" ")]:[a,r.slice(1).join(" ")]:["",""]}async function I(r){if(!r.length)return;const a=await x(r.map(p=>`${p}/package.json`),{dot:!0,ignore:["**/node_modules/**"]});return Promise.all(a.map(async p=>{const e=await g(p);if(!e)return;const{name:n,scripts:m}=e;return{name:n,scripts:m}})).then(p=>p.reduce((e,n)=>{const{name:m,scripts:i}=n;return e[m]=i,e},{}))}F();export{F as ccommand};
|