ccommand 1.0.35 → 1.0.36
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 +5 -0
- package/dist/index.js +11 -11
- package/dist/index.mjs +11 -11
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -22,6 +22,11 @@ ccommand # 执行当前script
|
|
|
22
22
|
ccommand -help # 查看帮助
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
+
## 新特性 | Feature
|
|
26
|
+
|
|
27
|
+
when you run command with search the quick command will be output with tips
|
|
28
|
+
当你使用命令通过查找执行, 会在终端输出一个快速执行命令的提示
|
|
29
|
+
|
|
25
30
|
## 使用 | Usage
|
|
26
31
|
|
|
27
32
|
- ccommand 选取当前目录下的 package.json 文件中的 scripts 中的命令
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var ge=require("module"),X=require("fs"),Q=require("path"),p=require("lazy-js-utils"),Z=require("fast-glob"),ee=require("@simon_he/colorize"),re=require("os"),te=require("tty");function _(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var q=_(X),V=_(Q),ne=_(Z),a=_(ee),se=_(re),oe=_(te),ue=require;const i="\x1B[",v="\x1B]",b="\x07",j=";",G=process.env.TERM_PROGRAM==="Apple_Terminal",u={};u.cursorTo=(e,t)=>{if(typeof e!="number")throw new TypeError("The `x` argument is required");return typeof t!="number"?i+(e+1)+"G":i+(t+1)+";"+(e+1)+"H"},u.cursorMove=(e,t)=>{if(typeof e!="number")throw new TypeError("The `x` argument is required");let r="";return e<0?r+=i+-e+"D":e>0&&(r+=i+e+"C"),t<0?r+=i+-t+"A":t>0&&(r+=i+t+"B"),r},u.cursorUp=(e=1)=>i+e+"A",u.cursorDown=(e=1)=>i+e+"B",u.cursorForward=(e=1)=>i+e+"C",u.cursorBackward=(e=1)=>i+e+"D",u.cursorLeft=i+"G",u.cursorSavePosition=G?"\x1B7":i+"s",u.cursorRestorePosition=G?"\x1B8":i+"u",u.cursorGetPosition=i+"6n",u.cursorNextLine=i+"E",u.cursorPrevLine=i+"F",u.cursorHide=i+"?25l",u.cursorShow=i+"?25h",u.eraseLines=e=>{let t="";for(let r=0;r<e;r++)t+=u.eraseLine+(r<e-1?u.cursorUp():"");return e&&(t+=u.cursorLeft),t},u.eraseEndLine=i+"K",u.eraseStartLine=i+"1K",u.eraseLine=i+"2K",u.eraseDown=i+"J",u.eraseUp=i+"1J",u.eraseScreen=i+"2J",u.scrollUp=i+"S",u.scrollDown=i+"T",u.clearScreen="\x1Bc",u.clearTerminal=process.platform==="win32"?`${u.eraseScreen}${i}0f`:`${u.eraseScreen}${i}3J${i}H`,u.beep=b,u.link=(e,t)=>[v,"8",j,j,t,b,e,v,"8",j,j,b].join(""),u.image=(e,t={})=>{let r=`${v}1337;File=inline=1`;return t.width&&(r+=`;width=${t.width}`),t.height&&(r+=`;height=${t.height}`),t.preserveAspectRatio===!1&&(r+=";preserveAspectRatio=0"),r+":"+e.toString("base64")+b},u.iTerm={setCwd:(e=process.cwd())=>`${v}50;CurrentDir=${e}${b}`,annotation:(e,t={})=>{let r=`${v}1337;`;const n=typeof t.x<"u",c=typeof t.y<"u";if((n||c)&&!(n&&c&&typeof t.length<"u"))throw new Error("`x`, `y` and `length` must be defined when `x` or `y` is defined");return e=e.replace(/\|/g,""),r+=t.isHidden?"AddHiddenAnnotation=":"AddAnnotation=",t.length>0?r+=(n?[e,t.length,t.x,t.y]:[t.length,e]).join("|"):r+=e,r+b}};var H=(e,t=process.argv)=>{const r=e.startsWith("-")?"":e.length===1?"-":"--",n=t.indexOf(r+e),c=t.indexOf("--");return n!==-1&&(c===-1||n<c)};const ae=se.default,Y=oe.default,y=H,{env:f}=process;let R;y("no-color")||y("no-colors")||y("color=false")||y("color=never")?R=0:(y("color")||y("colors")||y("color=true")||y("color=always"))&&(R=1),"FORCE_COLOR"in f&&(f.FORCE_COLOR==="true"?R=1:f.FORCE_COLOR==="false"?R=0:R=f.FORCE_COLOR.length===0?1:Math.min(parseInt(f.FORCE_COLOR,10),3));function I(e){return e===0?!1:{level:e,hasBasic:!0,has256:e>=2,has16m:e>=3}}function x(e,t){if(R===0)return 0;if(y("color=16m")||y("color=full")||y("color=truecolor"))return 3;if(y("color=256"))return 2;if(e&&!t&&R===void 0)return 0;const r=R||0;if(f.TERM==="dumb")return r;if(process.platform==="win32"){const n=ae.release().split(".");return Number(n[0])>=10&&Number(n[2])>=10586?Number(n[2])>=14931?3:2:1}if("CI"in f)return["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","GITHUB_ACTIONS","BUILDKITE"].some(n=>n in f)||f.CI_NAME==="codeship"?1:r;if("TEAMCITY_VERSION"in f)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(f.TEAMCITY_VERSION)?1:0;if(f.COLORTERM==="truecolor")return 3;if("TERM_PROGRAM"in f){const n=parseInt((f.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(f.TERM_PROGRAM){case"iTerm.app":return n>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(f.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(f.TERM)||"COLORTERM"in f?1:r}function ie(e){const t=x(e,e&&e.isTTY);return I(t)}var ce={supportsColor:ie,stdout:I(x(!0,Y.isatty(1))),stderr:I(x(!0,Y.isatty(2)))};const le=ce,C=H;function z(e){if(/^\d{3,4}$/.test(e)){const r=/(\d{1,2})(\d{2})/.exec(e);return{major:0,minor:parseInt(r[1],10),patch:parseInt(r[2],10)}}const t=(e||"").split(".").map(r=>parseInt(r,10));return{major:t[0],minor:t[1],patch:t[2]}}function L(e){const{env:t}=process;if("FORCE_HYPERLINK"in t)return!(t.FORCE_HYPERLINK.length>0&&parseInt(t.FORCE_HYPERLINK,10)===0);if(C("no-hyperlink")||C("no-hyperlinks")||C("hyperlink=false")||C("hyperlink=never"))return!1;if(C("hyperlink=true")||C("hyperlink=always")||"NETLIFY"in t)return!0;if(!le.supportsColor(e)||e&&!e.isTTY||process.platform==="win32"||"CI"in t||"TEAMCITY_VERSION"in t)return!1;if("TERM_PROGRAM"in t){const r=z(t.TERM_PROGRAM_VERSION);switch(t.TERM_PROGRAM){case"iTerm.app":return r.major===3?r.minor>=1:r.major>3;case"WezTerm":return r.major>=20200620;case"vscode":return r.major>1||r.major===1&&r.minor>=72}}if("VTE_VERSION"in t){if(t.VTE_VERSION==="0.50.0")return!1;const r=z(t.VTE_VERSION);return r.major>0||r.minor>=50}return!1}var A={supportsHyperlink:L,stdout:L(process.stdout),stderr:L(process.stderr)};function k(e,t,{target:r="stdout",...n}={}){return A[r]?u.link(e,t):n.fallback===!1?e:typeof n.fallback=="function"?n.fallback(e,t):`${e} (\u200B${t}\u200B)`}k.isSupported=A.stdout,k.stderr=(e,t,r={})=>k(e,t,{target:"stderr",...r}),k.stderr.isSupported=A.stderr;var fe="1.0.36";const de=ue("yamljs");let T=[],E=null;const l=console.log;async function U(){const e="__ccommand__split",{status:t}=p.jsShell("gum -v","pipe");if(t!==0){l(a.default({color:"blue",text:"install gum..."}));const{status:s}=p.jsShell("brew install gum");if(s!==0){const{status:o}=p.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(
|
|
5
|
-
${
|
|
6
|
-
${
|
|
4
|
+
sudo apt update && sudo apt install gum`);if(o!==0){const h=k("the official website of gum","https://github.com/charmbracelet/gum#installation");return l(a.default({color:"red",text:`gum install error, you can install it yourself through ${a.default({color:"yellow",text:h,bold:!0})}`}))}}l(a.default({color:"green",text:"gum install successfully \u{1F389}"}))}const r=process.argv.slice(2);if(r[0]==="-v"||r[0]==="--version")return l(a.default({text:`ccommand Version: ${fe}`,color:"green"}));if(r[0]==="-h"||r[0]==="--help"){const s=k("open an issue","https://github.com/Simon-He95/ccommand/issues"),o=k("\u2728star it","https://github.com/Simon-He95/ccommand");return l(a.default({color:"white",text:`
|
|
5
|
+
${a.default({bold:!0,text:"Common Commands:",bgColor:"blue"})}
|
|
6
|
+
${a.default({text:`- 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
|
`,color:"cyan"})}
|
|
11
|
-
If you encounter any problems, you can ${
|
|
12
|
-
If you like it, please ${
|
|
13
|
-
or current scripts, please check`})),process.exit())}if(
|
|
14
|
-
command '${(
|
|
15
|
-
command '${
|
|
16
|
-
command '${
|
|
17
|
-
command ${
|
|
11
|
+
If you encounter any problems, you can ${a.default({color:"magenta",text:s})}.
|
|
12
|
+
If you like it, please ${a.default({text:o,bold:!0,color:"cyan"})} `}))}const n=p.getPkgTool(),[c,g,w]=pe(r);let d=c,O;if(r[0]==="find"){if(g)await S(n),d=T.filter(s=>s.includes(g))[0];else if(n==="yarn"){await S(n);const{result:s}=p.jsShell(`echo ${T.join(",")} | sed "s/,/\\n/g" | gum filter --placeholder=" \u{1F914}\u8BF7\u9009\u62E9\u4E00\u4E2A\u8981\u6267\u884C\u7684\u76EE\u5F55"`,"pipe");if(d=s,!d)return l(a.default({color:"yellow",text:"\u5DF2\u53D6\u6D88"}))}else if(n==="pnpm"){await S(n);const{result:s}=p.jsShell(`echo ${T.join(",")} | sed "s/,/\\n/g" | gum filter --placeholder=" \u{1F914}\u8BF7\u9009\u62E9\u4E00\u4E2A\u8981\u6267\u884C\u7684\u76EE\u5F55"`,"pipe");if(d=s.trim(),!d)return l(a.default({color:"yellow",text:"\u5DF2\u53D6\u6D88"}))}else return l(a.default({color:"red",text:"find command only support yarn or pnpm"}));O=await D()}else{if(O=await D(),c&&E&&!E[c]||!E)try{const s=(await p.getPkg("./package.json")||{})?.scripts;if(s&&s[r[0]])return l(a.default({text:`ccommand is executing ${a.default({color:"cyan",text:`'${r[0]}'`})} \u{1F914} `,color:"yellow"})),N(r[0],r.slice(1).join(" "));if(s&&c){const o=he(s,r[0]),h=r.slice(1).join(" ");return N(o,h)}}catch{}E&&!E[r[0]]&&(l(a.default({color:"red",text:`"${r[0]}" is not found in workspace, current directory
|
|
13
|
+
or current scripts, please check`})),process.exit())}if(!O)return l(a.default({color:"red",text:"No scripts found"}));const M=[];let $="";if(!g||r[0]==="find"&&(!r[2]||r[2].startsWith("--"))){const s=Object.keys(O).reduce((h,m)=>{const F=O[m];return M.push(m),h+=`"${m}: ${F.replace(/\"/g,"'")}"${e}`,h},""),{result:o}=p.jsShell(`echo ${s} | sed "s/${e}/\\n/g" | gum filter --placeholder=" \u{1F914}\u8BF7\u9009\u62E9\u4E00\u4E2A\u8981\u6267\u884C\u7684\u6307\u4EE4"`,"pipe");$=o.substring(0,o.indexOf(": "))}if(!g&&!$)return l(a.default({color:"yellow",text:"\u5DF2\u53D6\u6D88"})),process.exit();const{status:W}=await p.jsShell(K());if(W===0)return l(a.default({color:"green",text:`
|
|
14
|
+
command '${(r[0]==="find"?r[2]:r[1])||$}' run successfully \u{1F389}`})),process.exit();l(a.default({color:"red",text:`
|
|
15
|
+
command '${$}' run error \u274C`}));function P(s){return M.find(o=>s.startsWith(o))}function K(){let s="",o="";const h=n!=="yarn";n==="npm"?(o=w?` -- ${w}`:"",s=d?` --prefix ${d} `:" "):n==="pnpm"?(o=w?` ${w}`:"",s=d?` --filter ${d} `:" "):n==="yarn"?(o=w?` ${w}`:"",s=d?` workspace ${d} `:" "):n==="bun"&&(o=w?` ${w}`:"",s="");let m="";if(o&&!o.startsWith(" --")){const B=o.split(" ").filter(Boolean);m=B[0],o=B.slice(1).join(" ")}const F=`${n}${h?" run":" "}${s} ${m||($?P($)||$:g)} ${J(o)?`-- ${o}`:o}`;return $=`${m||($?P($):g)}`,r[0]==="find"?l(a.default({text:`tips: pfind ${d} ${$} ${o}`.replace(/\s+/g," "),color:"blue",bold:!0})):l(a.default({text:`tips: prun ${$} ${o}`.replace(/\s+/g," "),color:"blue",bold:!0})),F}async function D(){try{if(!d||n==="bun"||n==="npm")return(await p.getPkg("./package.json"))?.scripts;if(n==="pnpm")return(await S(n))[d]||(await p.getPkg(`${d}/package.json`))?.scripts;if(n==="yarn")return(await S(n))[d]||(await p.getPkg(`${d}/package.json`))?.scripts}catch{}}function J(s){return r[0]==="find",r[1]&&s}async function N(s,o){let h;switch(s&&r[0]!==s&&l(a.default({text:`\u{1F914} ${a.default({text:`'${r[0]}'`,color:"cyan"})} automatically match for you to ${a.default({text:`'${s}${o?` ${o}`:""}'`,color:"cyan"})} `,color:"yellow"})),n){case"npm":{const{status:m}=p.jsShell(`npm run ${s}${o?` -- ${o}`:""}`);h=m;break}case"pnpm":{const{status:m}=p.jsShell(`pnpm run ${s}${o?` ${o}`:""}`);h=m;break}case"yarn":{const{status:m}=p.jsShell(`yarn ${s}${o?` ${o}`:""}`);h=m;break}case"bun":{const{status:m}=p.jsShell(`bun ${s} ${o}`);h=m;break}}return l(h===0?a.default({color:"green",text:`
|
|
16
|
+
command '${s}${o?` ${o}`:""}' run successfully \u{1F389}`}):a.default({color:"red",text:`
|
|
17
|
+
command ${a.default({bold:!0,color:"cyan",text:`'${s||r[0]}${o?` ${o}`:""}'`})} run error \u274C`}))}}async function S(e){if(E)return E;const t=e==="pnpm"?await q.default.readFileSync(V.default.resolve(process.cwd(),"pnpm-workspace.yaml"),"utf-8"):await q.default.readFileSync(V.default.resolve(process.cwd(),"package.json"),"utf-8"),r=e==="pnpm"?de.parse(t)?.packages||[]:JSON.parse(t)?.workspaces||[];return E=await me(r)||{},T=Object.keys(E).filter(n=>E[n]&&Object.keys(E[n]).length),E}function pe(e){const t=e[0];return t?t.startsWith("--")?["","",e.join(" ")]:e[1]&&e[1].startsWith("--")?[t,"",e.slice(1).join(" ")]:[t,e[1],e.slice(2).join(" ")]:["","",""]}async function me(e){if(!e.length)return;const t=await ne.default(e.map(r=>`${r}/package.json`),{dot:!0,ignore:["**/node_modules/**"]});return Promise.all(t.map(async r=>{const n=await p.getPkg(r);if(!n)return;const{name:c,scripts:g}=n;return{name:c,scripts:g}})).then(r=>r.reduce((n,c)=>{const{name:g,scripts:w}=c;return!g||!w||(n[g]=w),n},{}))}function he(e,t){const r=Object.keys(e),n=r.find(c=>c.startsWith(t));if(n)return n;try{const c=new RegExp(t.split("").join("[_-\\w$.:]*"));return r.find(g=>c.test(g))}catch(c){l(a.default({text:`RegExp error: ${c}`,color:"red"})),process.exit(1)}}U(),exports.ccommand=U;
|
package/dist/index.mjs
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{createRequire as
|
|
2
|
+
import{createRequire as X}from"module";import V from"fs";import G from"path";import{jsShell as w,getPkgTool as Q,getPkg as T}from"lazy-js-utils";import Z from"fast-glob";import i from"@simon_he/colorize";import ee from"os";import re from"tty";var te=X(import.meta.url);const c="\x1B[",F="\x1B]",C="\x07",I=";",H=process.env.TERM_PROGRAM==="Apple_Terminal",u={};u.cursorTo=(r,t)=>{if(typeof r!="number")throw new TypeError("The `x` argument is required");return typeof t!="number"?c+(r+1)+"G":c+(t+1)+";"+(r+1)+"H"},u.cursorMove=(r,t)=>{if(typeof r!="number")throw new TypeError("The `x` argument is required");let e="";return r<0?e+=c+-r+"D":r>0&&(e+=c+r+"C"),t<0?e+=c+-t+"A":t>0&&(e+=c+t+"B"),e},u.cursorUp=(r=1)=>c+r+"A",u.cursorDown=(r=1)=>c+r+"B",u.cursorForward=(r=1)=>c+r+"C",u.cursorBackward=(r=1)=>c+r+"D",u.cursorLeft=c+"G",u.cursorSavePosition=H?"\x1B7":c+"s",u.cursorRestorePosition=H?"\x1B8":c+"u",u.cursorGetPosition=c+"6n",u.cursorNextLine=c+"E",u.cursorPrevLine=c+"F",u.cursorHide=c+"?25l",u.cursorShow=c+"?25h",u.eraseLines=r=>{let t="";for(let e=0;e<r;e++)t+=u.eraseLine+(e<r-1?u.cursorUp():"");return r&&(t+=u.cursorLeft),t},u.eraseEndLine=c+"K",u.eraseStartLine=c+"1K",u.eraseLine=c+"2K",u.eraseDown=c+"J",u.eraseUp=c+"1J",u.eraseScreen=c+"2J",u.scrollUp=c+"S",u.scrollDown=c+"T",u.clearScreen="\x1Bc",u.clearTerminal=process.platform==="win32"?`${u.eraseScreen}${c}0f`:`${u.eraseScreen}${c}3J${c}H`,u.beep=C,u.link=(r,t)=>[F,"8",I,I,t,C,r,F,"8",I,I,C].join(""),u.image=(r,t={})=>{let e=`${F}1337;File=inline=1`;return t.width&&(e+=`;width=${t.width}`),t.height&&(e+=`;height=${t.height}`),t.preserveAspectRatio===!1&&(e+=";preserveAspectRatio=0"),e+":"+r.toString("base64")+C},u.iTerm={setCwd:(r=process.cwd())=>`${F}50;CurrentDir=${r}${C}`,annotation:(r,t={})=>{let e=`${F}1337;`;const n=typeof t.x<"u",a=typeof t.y<"u";if((n||a)&&!(n&&a&&typeof t.length<"u"))throw new Error("`x`, `y` and `length` must be defined when `x` or `y` is defined");return r=r.replace(/\|/g,""),e+=t.isHidden?"AddHiddenAnnotation=":"AddAnnotation=",t.length>0?e+=(n?[r,t.length,t.x,t.y]:[t.length,r]).join("|"):e+=r,e+C}};var Y=(r,t=process.argv)=>{const e=r.startsWith("-")?"":r.length===1?"-":"--",n=t.indexOf(e+r),a=t.indexOf("--");return n!==-1&&(a===-1||n<a)};const ne=ee,W=re,g=Y,{env:f}=process;let R;g("no-color")||g("no-colors")||g("color=false")||g("color=never")?R=0:(g("color")||g("colors")||g("color=true")||g("color=always"))&&(R=1),"FORCE_COLOR"in f&&(f.FORCE_COLOR==="true"?R=1:f.FORCE_COLOR==="false"?R=0:R=f.FORCE_COLOR.length===0?1:Math.min(parseInt(f.FORCE_COLOR,10),3));function j(r){return r===0?!1:{level:r,hasBasic:!0,has256:r>=2,has16m:r>=3}}function v(r,t){if(R===0)return 0;if(g("color=16m")||g("color=full")||g("color=truecolor"))return 3;if(g("color=256"))return 2;if(r&&!t&&R===void 0)return 0;const e=R||0;if(f.TERM==="dumb")return e;if(process.platform==="win32"){const n=ne.release().split(".");return Number(n[0])>=10&&Number(n[2])>=10586?Number(n[2])>=14931?3:2:1}if("CI"in f)return["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","GITHUB_ACTIONS","BUILDKITE"].some(n=>n in f)||f.CI_NAME==="codeship"?1:e;if("TEAMCITY_VERSION"in f)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(f.TEAMCITY_VERSION)?1:0;if(f.COLORTERM==="truecolor")return 3;if("TERM_PROGRAM"in f){const n=parseInt((f.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(f.TERM_PROGRAM){case"iTerm.app":return n>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(f.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(f.TERM)||"COLORTERM"in f?1:e}function oe(r){const t=v(r,r&&r.isTTY);return j(t)}var se={supportsColor:oe,stdout:j(v(!0,W.isatty(1))),stderr:j(v(!0,W.isatty(2)))};const ue=se,O=Y;function q(r){if(/^\d{3,4}$/.test(r)){const e=/(\d{1,2})(\d{2})/.exec(r);return{major:0,minor:parseInt(e[1],10),patch:parseInt(e[2],10)}}const t=(r||"").split(".").map(e=>parseInt(e,10));return{major:t[0],minor:t[1],patch:t[2]}}function A(r){const{env:t}=process;if("FORCE_HYPERLINK"in t)return!(t.FORCE_HYPERLINK.length>0&&parseInt(t.FORCE_HYPERLINK,10)===0);if(O("no-hyperlink")||O("no-hyperlinks")||O("hyperlink=false")||O("hyperlink=never"))return!1;if(O("hyperlink=true")||O("hyperlink=always")||"NETLIFY"in t)return!0;if(!ue.supportsColor(r)||r&&!r.isTTY||process.platform==="win32"||"CI"in t||"TEAMCITY_VERSION"in t)return!1;if("TERM_PROGRAM"in t){const e=q(t.TERM_PROGRAM_VERSION);switch(t.TERM_PROGRAM){case"iTerm.app":return e.major===3?e.minor>=1:e.major>3;case"WezTerm":return e.major>=20200620;case"vscode":return e.major>1||e.major===1&&e.minor>=72}}if("VTE_VERSION"in t){if(t.VTE_VERSION==="0.50.0")return!1;const e=q(t.VTE_VERSION);return e.major>0||e.minor>=50}return!1}var L={supportsHyperlink:A,stdout:A(process.stdout),stderr:A(process.stderr)};function k(r,t,{target:e="stdout",...n}={}){return L[e]?u.link(r,t):n.fallback===!1?r:typeof n.fallback=="function"?n.fallback(r,t):`${r} (\u200B${t}\u200B)`}k.isSupported=L.stdout,k.stderr=(r,t,e={})=>k(r,t,{target:"stderr",...e}),k.stderr.isSupported=L.stderr;var ie="1.0.36";const ce=te("yamljs");let S=[],y=null;const l=console.log;async function K(){const r="__ccommand__split",{status:t}=w("gum -v","pipe");if(t!==0){l(i({color:"blue",text:"install gum..."}));const{status:o}=w("brew install gum");if(o!==0){const{status:s}=w(`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(
|
|
6
|
-
${
|
|
7
|
-
${
|
|
5
|
+
sudo apt update && sudo apt install gum`);if(s!==0){const d=k("the official website of gum","https://github.com/charmbracelet/gum#installation");return l(i({color:"red",text:`gum install error, you can install it yourself through ${i({color:"yellow",text:d,bold:!0})}`}))}}l(i({color:"green",text:"gum install successfully \u{1F389}"}))}const e=process.argv.slice(2);if(e[0]==="-v"||e[0]==="--version")return l(i({text:`ccommand Version: ${ie}`,color:"green"}));if(e[0]==="-h"||e[0]==="--help"){const o=k("open an issue","https://github.com/Simon-He95/ccommand/issues"),s=k("\u2728star it","https://github.com/Simon-He95/ccommand");return l(i({color:"white",text:`
|
|
6
|
+
${i({bold:!0,text:"Common Commands:",bgColor:"blue"})}
|
|
7
|
+
${i({text:`- ccommand -v \u67E5\u770B\u5F53\u524D\u7248\u672C
|
|
8
8
|
- ccommand -help \u67E5\u770B\u5E2E\u52A9
|
|
9
9
|
- ccommand \u6267\u884C\u5F53\u524Dpackage.json
|
|
10
10
|
- ccommand find \u67E5\u627E\u5F53\u524Dworkspace\u7684\u6240\u6709\u76EE\u5F55
|
|
11
11
|
`,color:"cyan"})}
|
|
12
|
-
If you encounter any problems, you can ${
|
|
13
|
-
If you like it, please ${
|
|
14
|
-
or current scripts, please check`})),process.exit())}if(!
|
|
15
|
-
command '${(
|
|
16
|
-
command '${$}' run error \u274C`}));function
|
|
17
|
-
command '${
|
|
18
|
-
command ${
|
|
12
|
+
If you encounter any problems, you can ${i({color:"magenta",text:o})}.
|
|
13
|
+
If you like it, please ${i({text:s,bold:!0,color:"cyan"})} `}))}const n=Q(),[a,h,E]=ae(e);let p=a,b;if(e[0]==="find"){if(h)await _(n),p=S.filter(o=>o.includes(h))[0];else if(n==="yarn"){await _(n);const{result:o}=w(`echo ${S.join(",")} | sed "s/,/\\n/g" | gum filter --placeholder=" \u{1F914}\u8BF7\u9009\u62E9\u4E00\u4E2A\u8981\u6267\u884C\u7684\u76EE\u5F55"`,"pipe");if(p=o,!p)return l(i({color:"yellow",text:"\u5DF2\u53D6\u6D88"}))}else if(n==="pnpm"){await _(n);const{result:o}=w(`echo ${S.join(",")} | sed "s/,/\\n/g" | gum filter --placeholder=" \u{1F914}\u8BF7\u9009\u62E9\u4E00\u4E2A\u8981\u6267\u884C\u7684\u76EE\u5F55"`,"pipe");if(p=o.trim(),!p)return l(i({color:"yellow",text:"\u5DF2\u53D6\u6D88"}))}else return l(i({color:"red",text:"find command only support yarn or pnpm"}));b=await N()}else{if(b=await N(),a&&y&&!y[a]||!y)try{const o=(await T("./package.json")||{})?.scripts;if(o&&o[e[0]])return l(i({text:`ccommand is executing ${i({color:"cyan",text:`'${e[0]}'`})} \u{1F914} `,color:"yellow"})),B(e[0],e.slice(1).join(" "));if(o&&a){const s=fe(o,e[0]),d=e.slice(1).join(" ");return B(s,d)}}catch{}y&&!y[e[0]]&&(l(i({color:"red",text:`"${e[0]}" is not found in workspace, current directory
|
|
14
|
+
or current scripts, please check`})),process.exit())}if(!b)return l(i({color:"red",text:"No scripts found"}));const M=[];let $="";if(!h||e[0]==="find"&&(!e[2]||e[2].startsWith("--"))){const o=Object.keys(b).reduce((d,m)=>{const x=b[m];return M.push(m),d+=`"${m}: ${x.replace(/\"/g,"'")}"${r}`,d},""),{result:s}=w(`echo ${o} | sed "s/${r}/\\n/g" | gum filter --placeholder=" \u{1F914}\u8BF7\u9009\u62E9\u4E00\u4E2A\u8981\u6267\u884C\u7684\u6307\u4EE4"`,"pipe");$=s.substring(0,s.indexOf(": "))}if(!h&&!$)return l(i({color:"yellow",text:"\u5DF2\u53D6\u6D88"})),process.exit();const{status:z}=await w(U());if(z===0)return l(i({color:"green",text:`
|
|
15
|
+
command '${(e[0]==="find"?e[2]:e[1])||$}' run successfully \u{1F389}`})),process.exit();l(i({color:"red",text:`
|
|
16
|
+
command '${$}' run error \u274C`}));function P(o){return M.find(s=>o.startsWith(s))}function U(){let o="",s="";const d=n!=="yarn";n==="npm"?(s=E?` -- ${E}`:"",o=p?` --prefix ${p} `:" "):n==="pnpm"?(s=E?` ${E}`:"",o=p?` --filter ${p} `:" "):n==="yarn"?(s=E?` ${E}`:"",o=p?` workspace ${p} `:" "):n==="bun"&&(s=E?` ${E}`:"",o="");let m="";if(s&&!s.startsWith(" --")){const D=s.split(" ").filter(Boolean);m=D[0],s=D.slice(1).join(" ")}const x=`${n}${d?" run":" "}${o} ${m||($?P($)||$:h)} ${J(s)?`-- ${s}`:s}`;return $=`${m||($?P($):h)}`,e[0]==="find"?l(i({text:`tips: pfind ${p} ${$} ${s}`.replace(/\s+/g," "),color:"blue",bold:!0})):l(i({text:`tips: prun ${$} ${s}`.replace(/\s+/g," "),color:"blue",bold:!0})),x}async function N(){try{if(!p||n==="bun"||n==="npm")return(await T("./package.json"))?.scripts;if(n==="pnpm")return(await _(n))[p]||(await T(`${p}/package.json`))?.scripts;if(n==="yarn")return(await _(n))[p]||(await T(`${p}/package.json`))?.scripts}catch{}}function J(o){return e[0]==="find",e[1]&&o}async function B(o,s){let d;switch(o&&e[0]!==o&&l(i({text:`\u{1F914} ${i({text:`'${e[0]}'`,color:"cyan"})} automatically match for you to ${i({text:`'${o}${s?` ${s}`:""}'`,color:"cyan"})} `,color:"yellow"})),n){case"npm":{const{status:m}=w(`npm run ${o}${s?` -- ${s}`:""}`);d=m;break}case"pnpm":{const{status:m}=w(`pnpm run ${o}${s?` ${s}`:""}`);d=m;break}case"yarn":{const{status:m}=w(`yarn ${o}${s?` ${s}`:""}`);d=m;break}case"bun":{const{status:m}=w(`bun ${o} ${s}`);d=m;break}}return l(d===0?i({color:"green",text:`
|
|
17
|
+
command '${o}${s?` ${s}`:""}' run successfully \u{1F389}`}):i({color:"red",text:`
|
|
18
|
+
command ${i({bold:!0,color:"cyan",text:`'${o||e[0]}${s?` ${s}`:""}'`})} run error \u274C`}))}}async function _(r){if(y)return y;const t=r==="pnpm"?await V.readFileSync(G.resolve(process.cwd(),"pnpm-workspace.yaml"),"utf-8"):await V.readFileSync(G.resolve(process.cwd(),"package.json"),"utf-8"),e=r==="pnpm"?ce.parse(t)?.packages||[]:JSON.parse(t)?.workspaces||[];return y=await le(e)||{},S=Object.keys(y).filter(n=>y[n]&&Object.keys(y[n]).length),y}function ae(r){const t=r[0];return t?t.startsWith("--")?["","",r.join(" ")]:r[1]&&r[1].startsWith("--")?[t,"",r.slice(1).join(" ")]:[t,r[1],r.slice(2).join(" ")]:["","",""]}async function le(r){if(!r.length)return;const t=await Z(r.map(e=>`${e}/package.json`),{dot:!0,ignore:["**/node_modules/**"]});return Promise.all(t.map(async e=>{const n=await T(e);if(!n)return;const{name:a,scripts:h}=n;return{name:a,scripts:h}})).then(e=>e.reduce((n,a)=>{const{name:h,scripts:E}=a;return!h||!E||(n[h]=E),n},{}))}function fe(r,t){const e=Object.keys(r),n=e.find(a=>a.startsWith(t));if(n)return n;try{const a=new RegExp(t.split("").join("[_-\\w$.:]*"));return e.find(h=>a.test(h))}catch(a){l(i({text:`RegExp error: ${a}`,color:"red"})),process.exit(1)}}K();export{K as ccommand};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ccommand",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.36",
|
|
4
4
|
"packageManager": "pnpm@6.32.3",
|
|
5
5
|
"description": "ccommand",
|
|
6
6
|
"author": "Simon He",
|
|
@@ -55,7 +55,6 @@
|
|
|
55
55
|
"chalk": "^5.1.2",
|
|
56
56
|
"fast-glob": "^3.2.12",
|
|
57
57
|
"lazy-js-utils": "^0.0.5",
|
|
58
|
-
"terminal-link": "^3.0.0",
|
|
59
58
|
"vue": "^3.2.36",
|
|
60
59
|
"yamljs": "^0.3.0"
|
|
61
60
|
},
|
|
@@ -71,6 +70,7 @@
|
|
|
71
70
|
"pkgroll": "^1.3.1",
|
|
72
71
|
"prettier": "^2.8.1",
|
|
73
72
|
"simple-git-hooks": "^2.8.1",
|
|
73
|
+
"terminal-link": "^3.0.0",
|
|
74
74
|
"tsx": "^3.12.1",
|
|
75
75
|
"typescript": "^4.7.2",
|
|
76
76
|
"vite": "^3.0.2",
|