ccommand 1.0.40 → 1.0.41
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 +10 -10
- package/dist/index.mjs +10 -10
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var Ce=require("module"),ue=require("fs/promises"),ne=require("path"),p=require("lazy-js-utils"),oe=require("fast-glob"),se=require("@simon_he/colorize"),ae=require("os"),ie=require("tty");function b(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var Y=b(ue),z=b(ne),ce=b(oe),i=b(se),le=b(ae),fe=b(ie),de=require;const c="\x1B[",j="\x1B]",T="\x07",S=";",U=process.env.TERM_PROGRAM==="Apple_Terminal",a={};a.cursorTo=(e,t)=>{if(typeof e!="number")throw new TypeError("The `x` argument is required");return typeof t!="number"?c+(e+1)+"G":c+(t+1)+";"+(e+1)+"H"},a.cursorMove=(e,t)=>{if(typeof e!="number")throw new TypeError("The `x` argument is required");let r="";return e<0?r+=c+-e+"D":e>0&&(r+=c+e+"C"),t<0?r+=c+-t+"A":t>0&&(r+=c+t+"B"),r},a.cursorUp=(e=1)=>c+e+"A",a.cursorDown=(e=1)=>c+e+"B",a.cursorForward=(e=1)=>c+e+"C",a.cursorBackward=(e=1)=>c+e+"D",a.cursorLeft=c+"G",a.cursorSavePosition=U?"\x1B7":c+"s",a.cursorRestorePosition=U?"\x1B8":c+"u",a.cursorGetPosition=c+"6n",a.cursorNextLine=c+"E",a.cursorPrevLine=c+"F",a.cursorHide=c+"?25l",a.cursorShow=c+"?25h",a.eraseLines=e=>{let t="";for(let r=0;r<e;r++)t+=a.eraseLine+(r<e-1?a.cursorUp():"");return e&&(t+=a.cursorLeft),t},a.eraseEndLine=c+"K",a.eraseStartLine=c+"1K",a.eraseLine=c+"2K",a.eraseDown=c+"J",a.eraseUp=c+"1J",a.eraseScreen=c+"2J",a.scrollUp=c+"S",a.scrollDown=c+"T",a.clearScreen="\x1Bc",a.clearTerminal=process.platform==="win32"?`${a.eraseScreen}${c}0f`:`${a.eraseScreen}${c}3J${c}H`,a.beep=T,a.link=(e,t)=>[j,"8",S,S,t,T,e,j,"8",S,S,T].join(""),a.image=(e,t={})=>{let r=`${j}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")+T},a.iTerm={setCwd:(e=process.cwd())=>`${j}50;CurrentDir=${e}${T}`,annotation:(e,t={})=>{let r=`${j}1337;`;const n=typeof t.x<"u",u=typeof t.y<"u";if((n||u)&&!(n&&u&&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+T}};var W=(e,t=process.argv)=>{const r=e.startsWith("-")?"":e.length===1?"-":"--",n=t.indexOf(r+e),u=t.indexOf("--");return n!==-1&&(u===-1||n<u)};const pe=le.default,K=fe.default,y=W,{env:m}=process;let C;y("no-color")||y("no-colors")||y("color=false")||y("color=never")?C=0:(y("color")||y("colors")||y("color=true")||y("color=always"))&&(C=1),"FORCE_COLOR"in m&&(m.FORCE_COLOR==="true"?C=1:m.FORCE_COLOR==="false"?C=0:C=m.FORCE_COLOR.length===0?1:Math.min(parseInt(m.FORCE_COLOR,10),3));function D(e){return e===0?!1:{level:e,hasBasic:!0,has256:e>=2,has16m:e>=3}}function L(e,t){if(C===0)return 0;if(y("color=16m")||y("color=full")||y("color=truecolor"))return 3;if(y("color=256"))return 2;if(e&&!t&&C===void 0)return 0;const r=C||0;if(m.TERM==="dumb")return r;if(process.platform==="win32"){const n=pe.release().split(".");return Number(n[0])>=10&&Number(n[2])>=10586?Number(n[2])>=14931?3:2:1}if("CI"in m)return["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","GITHUB_ACTIONS","BUILDKITE"].some(n=>n in m)||m.CI_NAME==="codeship"?1:r;if("TEAMCITY_VERSION"in m)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(m.TEAMCITY_VERSION)?1:0;if(m.COLORTERM==="truecolor")return 3;if("TERM_PROGRAM"in m){const n=parseInt((m.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(m.TERM_PROGRAM){case"iTerm.app":return n>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(m.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(m.TERM)||"COLORTERM"in m?1:r}function me(e){const t=L(e,e&&e.isTTY);return D(t)}var Ee={supportsColor:me,stdout:D(L(!0,K.isatty(1))),stderr:D(L(!0,K.isatty(2)))};const he=Ee,A=W;function J(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 P(e){const{env:t}=process;if("FORCE_HYPERLINK"in t)return!(t.FORCE_HYPERLINK.length>0&&parseInt(t.FORCE_HYPERLINK,10)===0);if(A("no-hyperlink")||A("no-hyperlinks")||A("hyperlink=false")||A("hyperlink=never"))return!1;if(A("hyperlink=true")||A("hyperlink=always")||"NETLIFY"in t)return!0;if(!he.supportsColor(e)||e&&!e.isTTY||process.platform==="win32"||"CI"in t||"TEAMCITY_VERSION"in t)return!1;if("TERM_PROGRAM"in t){const r=J(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=J(t.VTE_VERSION);return r.major>0||r.minor>=50}return!1}var M={supportsHyperlink:P,stdout:P(process.stdout),stderr:P(process.stderr)};function k(e,t,{target:r="stdout",...n}={}){return M[r]?a.link(e,t):n.fallback===!1?e:typeof n.fallback=="function"?n.fallback(e,t):`${e} (\u200B${t}\u200B)`}k.isSupported=M.stdout,k.stderr=(e,t,r={})=>k(e,t,{target:"stderr",...r}),k.stderr.isSupported=M.stderr;var X="1.0.41";const N=console.log;function $e(e){const{status:t}=p.jsShell("gum -v","pipe");if(t!==0){N(i.default({color:"blue",text:e?"\u6B63\u5728\u4E3A\u60A8\u5B89\u88C5gum...":"install gum..."}));const{status:r}=p.jsShell("brew install gum");if(r!==0){const{status:n}=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(n!==0){const u=k(e?"gum\u5B98\u7F51\u94FE\u63A5":"the official website of gum","https://github.com/charmbracelet/gum#installation");return N(i.default({color:"red",text:`${e?"gum\u5B89\u88C5\u5931\u8D25,\u4F60\u53EF\u4EE5\u81EA\u884C\u4ECE\u4EE5\u4E0B\u94FE\u63A5\u5B89\u88C5":"gum install error, you can install it yourself through"} ${i.default({color:"yellow",text:u,bold:!0})}`}))}}N(i.default({color:"green",text:e?"gum\u5B89\u88C5\u6210\u529F \u{1F389}":"gum install successfully \u{1F389}"}))}}const ge=de("yamljs");let O=[],F=null;const f=console.log,Q="__ccommand__split",d=process.env.PI_Lang==="zh";async function Z(){$e(d);const e=d?"\u5DF2\u53D6\u6D88":"Cancelled",t=d?"\u5F53\u524D\u76EE\u5F55\u4E0D\u5B58\u5728\u4EFB\u4F55\u5B50\u76EE\u5F55":"The current directory does not have any subdirectories",r=d?"\u8FD0\u884C\u6210\u529F":"run successfully",n=d?"\u8FD0\u884C\u5931\u8D25":"run error",u=process.argv.slice(2);if(u[0]==="-v"||u[0]==="--version")return f(i.default({text:d?`ccommand \u5F53\u524D\u7248\u672C: ${X}`:`ccommand Version: ${X}`,color:"green"}));if(u[0]==="-h"||u[0]==="--help"){const o=k(d?"\u6253\u5F00\u4E00\u4E2A\u65B0\u7684\u95EE\u9898":"open an issue","https://github.com/Simon-He95/ccommand/issues"),s=k(d?"\u2728\u5E2E\u52A9\u70B9\u4E00\u4E2A\u661F\u661F":"\u2728star it","https://github.com/Simon-He95/ccommand");return f(i.default({color:"white",text:`
|
|
5
|
+
${i.default({bold:!0,text:"Common Commands:",bgColor:"blue"})}
|
|
6
|
+
${i.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
|
-
command '${(
|
|
14
|
-
command '${
|
|
15
|
-
command '${
|
|
16
|
-
command ${
|
|
11
|
+
If you encounter any problems, you can ${i.default({color:"magenta",text:o})}.
|
|
12
|
+
If you like it, please ${i.default({text:s,bold:!0,color:"cyan"})} `}))}const l=p.getPkgTool(),[R,_,w]=ye(u);let E=R,v;if(u[0]==="find"){if(_)await x(l),E=O.filter(o=>o.includes(_))[0];else if(l==="yarn"){if(await x(l),!O.length)return f(i.default({color:"yellow",text:t}));const{result:o}=p.jsShell(`echo ${O.join(",")} | sed "s/,/\\n/g" | gum filter --placeholder=" \u{1F914}${d?"\u8BF7\u9009\u62E9\u4E00\u4E2A\u8981\u6267\u884C\u7684\u76EE\u5F55":"Please select a directory to execute"}"`,"pipe");if(E=o,!E)return f(i.default({color:"yellow",text:e}))}else if(l==="pnpm"){if(await x(l),!O.length)return f(i.default({color:"yellow",text:t}));const{result:o}=p.jsShell(`echo ${O.join(",")} | sed "s/,/\\n/g" | gum filter --placeholder=" \u{1F914}${d?"\u8BF7\u9009\u62E9\u4E00\u4E2A\u8981\u6267\u884C\u7684\u76EE\u5F55":"Please select a directory to execute"}"`,"pipe");if(E=o.trim(),!E)return f(i.default({color:"yellow",text:e}))}else return f(i.default({color:"red",text:d?"find\u6307\u4EE4\u53EA\u80FD\u652F\u6301\u5728yarn\u6216pnpm\u7684monorepo\u6A21\u5F0F\u4E0B\u4F7F\u7528":"find command only support yarn or pnpm"}));v=await V()}else{if(v=await V(),R&&F&&!F[R]||!F)try{const o=(await p.getPkg("./package.json")||{})?.scripts;if(o&&o[u[0]])return f(i.default({text:`${d?"ccommand\u6B63\u5728\u6267\u884C":"ccommand is executing"} ${i.default({color:"cyan",text:`'${u[0]}'`})} \u{1F914} `,color:"yellow"})),G(u[0],u.slice(1).join(" "));if(o&&R){const s=we(o,u[0]),g=u.slice(1).join(" ");return G(s,g)}}catch{}F&&!F[u[0]]&&(f(i.default({color:"red",text:`"${u[0]}" ${d?"\u5728\u5DE5\u4F5C\u533A\u3001\u5F53\u524D\u76EE\u5F55\u4E2D\u627E\u4E0D\u5230\u4EFB\u4F55\u53EF\u6267\u884C\u7684\u811A\u672C,\u8BF7\u68C0\u67E5":"is not found in workspace, current directory or current scripts, please check"}`})),process.exit())}if(!v)return f(i.default({color:"red",text:d?"\u627E\u4E0D\u5230\u4EFB\u4F55\u53EF\u6267\u884C\u811A\u672C":"No scripts found"}));const B=[];let $="";if(!_||u[0]==="find"&&(!u[2]||u[2].startsWith("--"))){const o=Object.keys(v).reduce((g,h)=>{const I=v[h];return B.push(h),g+=`"${h}: ${I.replace(/\"/g,"'")}"${Q}`,g},""),{result:s}=p.jsShell(`echo ${o} | sed "s/${Q}/\\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(!_&&!$)return f(i.default({color:"yellow",text:e})),process.exit();const{status:ee}=await p.jsShell(te());if(ee===0)return f(i.default({color:"green",text:`
|
|
13
|
+
command '${(u[0]==="find"?u[2]:u[1])||$}' ${r} \u{1F389}`})),process.exit();f(i.default({color:"red",text:`
|
|
14
|
+
command '${$}' ${n} \u274C`}));function q(o){return B.find(s=>s===o)??B.find(s=>o.startsWith(s))}function te(){let o="",s="";const g=l!=="yarn";l==="npm"?(s=w?` -- ${w}`:"",o=E?` --prefix ${E} `:" "):l==="pnpm"?(s=w?` ${w}`:"",o=E?` --filter ${E} `:" "):l==="yarn"?(s=w?` ${w}`:"",o=E?` workspace ${E} `:" "):l==="bun"&&(s=w?` ${w}`:"",o="");let h="";if(s&&!s.startsWith(" --")){const H=s.split(" ").filter(Boolean);h=H[0],s=H.slice(1).join(" ")}const I=`${l}${g?" run":" "}${o} ${h||($?q($)||$:_)} ${re(s)?`-- ${s}`:s}`;return $=`${h||($?q($):_)}`,u[0]==="find"?f(i.default({text:`${d?"\u63D0\u793A":"tips"}: pfind ${E} ${$} ${s}`.replace(/\s+/g," "),color:"blue",bold:!0})):f(i.default({text:`${d?"\u63D0\u793A":"tips"}: prun ${$} ${s}`.replace(/\s+/g," "),color:"blue",bold:!0})),I}async function V(){try{if(!E||l==="bun"||l==="npm")return(await p.getPkg("./package.json"))?.scripts;if(l==="pnpm")return(await x(l))[E]||(await p.getPkg(`${E}/package.json`))?.scripts;if(l==="yarn")return(await x(l))[E]||(await p.getPkg(`${E}/package.json`))?.scripts}catch{}}function re(o){return u[0]==="find",u[1]&&o}async function G(o,s){let g;switch(o&&u[0]!==o&&f(i.default({text:`\u{1F914} ${i.default({text:`'${u[0]}'`,color:"cyan"})} ${d?"\u81EA\u52A8\u7684\u4E3A\u60A8\u5339\u914D\u6210":"automatically match for you to"} ${i.default({text:`'${o}${s?` ${s}`:""}'`,color:"cyan"})} `,color:"yellow"})),l){case"npm":{const{status:h}=p.jsShell(`npm run ${o}${s?` -- ${s}`:""}`);g=h;break}case"pnpm":{const{status:h}=p.jsShell(`pnpm run ${o}${s?` ${s}`:""}`);g=h;break}case"yarn":{const{status:h}=p.jsShell(`yarn ${o}${s?` ${s}`:""}`);g=h;break}case"bun":{const{status:h}=p.jsShell(`bun ${o} ${s}`);g=h;break}}return f(g===0?i.default({color:"green",text:`
|
|
15
|
+
command '${o}${s?` ${s}`:""}' ${r} \u{1F389}`}):i.default({color:"red",text:`
|
|
16
|
+
command ${i.default({bold:!0,color:"cyan",text:`'${o||u[0]}${s?` ${s}`:""}'`})} ${n} \u274C`}))}}async function x(e){if(F)return F;let t="";try{t=e==="pnpm"?await Y.default.readFile(z.default.resolve(process.cwd(),"pnpm-workspace.yaml"),"utf-8"):await Y.default.readFile(z.default.resolve(process.cwd(),"package.json"),"utf-8")}catch{f(i.default({color:"red",text:d?"pfind\u547D\u4EE4\u9700\u8981\u8BFB\u53D6pnpm-workspace.yaml,\u5F53\u524D\u76EE\u5F55\u4E0B\u5E76\u4E0D\u5B58\u5728":"The pfind command needs to read pnpm-workspace.yaml, which does not exist in the current directory"})),process.exit(0)}let r;if(e==="pnpm")r=ge.parse(t)?.packages||[];else{const n=JSON.parse(t)?.workspaces;p.isPlainObject(n)?r=n?.packages:r=n||[]}return F=await Fe(r)||{},O=Object.keys(F).filter(n=>F[n]&&Object.keys(F[n]).length),F}function ye(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 Fe(e){if(!e.length)return;const t=await ce.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:u,scripts:l}=n;return{name:u,scripts:l}})).then(r=>r.reduce((n,u)=>{const{name:l,scripts:R}=u;return!l||!R||(n[l]=R),n},{}))}function we(e,t){const r=Object.keys(e),n=r.find(u=>u.startsWith(t));if(n)return n;try{const u=new RegExp(t.split("").join("[_-\\w$.:]*"));return r.find(l=>u.test(l))}catch(u){f(i.default({text:`${d?"\u6B63\u5219\u9519\u8BEF":"RegExp error"}: ${u}`,color:"red"})),process.exit(1)}}Z(),exports.ccommand=Z;
|
package/dist/index.mjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{createRequire as
|
|
2
|
+
import{createRequire as ue}from"module";import W from"fs/promises";import q from"path";import{jsShell as F,getPkgTool as ne,getPkg as B,isPlainObject as oe}from"lazy-js-utils";import se from"fast-glob";import c from"@simon_he/colorize";import ie from"os";import ce from"tty";var ae=ue(import.meta.url);const a="\x1B[",_="\x1B]",A="\x07",D=";",z=process.env.TERM_PROGRAM==="Apple_Terminal",i={};i.cursorTo=(e,r)=>{if(typeof e!="number")throw new TypeError("The `x` argument is required");return typeof r!="number"?a+(e+1)+"G":a+(r+1)+";"+(e+1)+"H"},i.cursorMove=(e,r)=>{if(typeof e!="number")throw new TypeError("The `x` argument is required");let t="";return e<0?t+=a+-e+"D":e>0&&(t+=a+e+"C"),r<0?t+=a+-r+"A":r>0&&(t+=a+r+"B"),t},i.cursorUp=(e=1)=>a+e+"A",i.cursorDown=(e=1)=>a+e+"B",i.cursorForward=(e=1)=>a+e+"C",i.cursorBackward=(e=1)=>a+e+"D",i.cursorLeft=a+"G",i.cursorSavePosition=z?"\x1B7":a+"s",i.cursorRestorePosition=z?"\x1B8":a+"u",i.cursorGetPosition=a+"6n",i.cursorNextLine=a+"E",i.cursorPrevLine=a+"F",i.cursorHide=a+"?25l",i.cursorShow=a+"?25h",i.eraseLines=e=>{let r="";for(let t=0;t<e;t++)r+=i.eraseLine+(t<e-1?i.cursorUp():"");return e&&(r+=i.cursorLeft),r},i.eraseEndLine=a+"K",i.eraseStartLine=a+"1K",i.eraseLine=a+"2K",i.eraseDown=a+"J",i.eraseUp=a+"1J",i.eraseScreen=a+"2J",i.scrollUp=a+"S",i.scrollDown=a+"T",i.clearScreen="\x1Bc",i.clearTerminal=process.platform==="win32"?`${i.eraseScreen}${a}0f`:`${i.eraseScreen}${a}3J${a}H`,i.beep=A,i.link=(e,r)=>[_,"8",D,D,r,A,e,_,"8",D,D,A].join(""),i.image=(e,r={})=>{let t=`${_}1337;File=inline=1`;return r.width&&(t+=`;width=${r.width}`),r.height&&(t+=`;height=${r.height}`),r.preserveAspectRatio===!1&&(t+=";preserveAspectRatio=0"),t+":"+e.toString("base64")+A},i.iTerm={setCwd:(e=process.cwd())=>`${_}50;CurrentDir=${e}${A}`,annotation:(e,r={})=>{let t=`${_}1337;`;const n=typeof r.x<"u",u=typeof r.y<"u";if((n||u)&&!(n&&u&&typeof r.length<"u"))throw new Error("`x`, `y` and `length` must be defined when `x` or `y` is defined");return e=e.replace(/\|/g,""),t+=r.isHidden?"AddHiddenAnnotation=":"AddAnnotation=",r.length>0?t+=(n?[e,r.length,r.x,r.y]:[r.length,e]).join("|"):t+=e,t+A}};var K=(e,r=process.argv)=>{const t=e.startsWith("-")?"":e.length===1?"-":"--",n=r.indexOf(t+e),u=r.indexOf("--");return n!==-1&&(u===-1||n<u)};const le=ie,U=ce,g=K,{env:m}=process;let C;g("no-color")||g("no-colors")||g("color=false")||g("color=never")?C=0:(g("color")||g("colors")||g("color=true")||g("color=always"))&&(C=1),"FORCE_COLOR"in m&&(m.FORCE_COLOR==="true"?C=1:m.FORCE_COLOR==="false"?C=0:C=m.FORCE_COLOR.length===0?1:Math.min(parseInt(m.FORCE_COLOR,10),3));function S(e){return e===0?!1:{level:e,hasBasic:!0,has256:e>=2,has16m:e>=3}}function L(e,r){if(C===0)return 0;if(g("color=16m")||g("color=full")||g("color=truecolor"))return 3;if(g("color=256"))return 2;if(e&&!r&&C===void 0)return 0;const t=C||0;if(m.TERM==="dumb")return t;if(process.platform==="win32"){const n=le.release().split(".");return Number(n[0])>=10&&Number(n[2])>=10586?Number(n[2])>=14931?3:2:1}if("CI"in m)return["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","GITHUB_ACTIONS","BUILDKITE"].some(n=>n in m)||m.CI_NAME==="codeship"?1:t;if("TEAMCITY_VERSION"in m)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(m.TEAMCITY_VERSION)?1:0;if(m.COLORTERM==="truecolor")return 3;if("TERM_PROGRAM"in m){const n=parseInt((m.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(m.TERM_PROGRAM){case"iTerm.app":return n>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(m.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(m.TERM)||"COLORTERM"in m?1:t}function fe(e){const r=L(e,e&&e.isTTY);return S(r)}var pe={supportsColor:fe,stdout:S(L(!0,U.isatty(1))),stderr:S(L(!0,U.isatty(2)))};const me=pe,b=K;function J(e){if(/^\d{3,4}$/.test(e)){const t=/(\d{1,2})(\d{2})/.exec(e);return{major:0,minor:parseInt(t[1],10),patch:parseInt(t[2],10)}}const r=(e||"").split(".").map(t=>parseInt(t,10));return{major:r[0],minor:r[1],patch:r[2]}}function M(e){const{env:r}=process;if("FORCE_HYPERLINK"in r)return!(r.FORCE_HYPERLINK.length>0&&parseInt(r.FORCE_HYPERLINK,10)===0);if(b("no-hyperlink")||b("no-hyperlinks")||b("hyperlink=false")||b("hyperlink=never"))return!1;if(b("hyperlink=true")||b("hyperlink=always")||"NETLIFY"in r)return!0;if(!me.supportsColor(e)||e&&!e.isTTY||process.platform==="win32"||"CI"in r||"TEAMCITY_VERSION"in r)return!1;if("TERM_PROGRAM"in r){const t=J(r.TERM_PROGRAM_VERSION);switch(r.TERM_PROGRAM){case"iTerm.app":return t.major===3?t.minor>=1:t.major>3;case"WezTerm":return t.major>=20200620;case"vscode":return t.major>1||t.major===1&&t.minor>=72}}if("VTE_VERSION"in r){if(r.VTE_VERSION==="0.50.0")return!1;const t=J(r.VTE_VERSION);return t.major>0||t.minor>=50}return!1}var P={supportsHyperlink:M,stdout:M(process.stdout),stderr:M(process.stderr)};function k(e,r,{target:t="stdout",...n}={}){return P[t]?i.link(e,r):n.fallback===!1?e:typeof n.fallback=="function"?n.fallback(e,r):`${e} (\u200B${r}\u200B)`}k.isSupported=P.stdout,k.stderr=(e,r,t={})=>k(e,r,{target:"stderr",...t}),k.stderr.isSupported=P.stderr;var X="1.0.41";const N=console.log;function de(e){const{status:r}=F("gum -v","pipe");if(r!==0){N(c({color:"blue",text:e?"\u6B63\u5728\u4E3A\u60A8\u5B89\u88C5gum...":"install gum..."}));const{status:t}=F("brew install gum");if(t!==0){const{status:n}=F(`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(n!==0){const u=k(e?"gum\u5B98\u7F51\u94FE\u63A5":"the official website of gum","https://github.com/charmbracelet/gum#installation");return N(c({color:"red",text:`${e?"gum\u5B89\u88C5\u5931\u8D25,\u4F60\u53EF\u4EE5\u81EA\u884C\u4ECE\u4EE5\u4E0B\u94FE\u63A5\u5B89\u88C5":"gum install error, you can install it yourself through"} ${c({color:"yellow",text:u,bold:!0})}`}))}}N(c({color:"green",text:e?"gum\u5B89\u88C5\u6210\u529F \u{1F389}":"gum install successfully \u{1F389}"}))}}const Ee=ae("yamljs");let O=[],y=null;const f=console.log,Q="__ccommand__split",p=process.env.PI_Lang==="zh";async function Z(){de(p);const e=p?"\u5DF2\u53D6\u6D88":"Cancelled",r=p?"\u5F53\u524D\u76EE\u5F55\u4E0D\u5B58\u5728\u4EFB\u4F55\u5B50\u76EE\u5F55":"The current directory does not have any subdirectories",t=p?"\u8FD0\u884C\u6210\u529F":"run successfully",n=p?"\u8FD0\u884C\u5931\u8D25":"run error",u=process.argv.slice(2);if(u[0]==="-v"||u[0]==="--version")return f(c({text:p?`ccommand \u5F53\u524D\u7248\u672C: ${X}`:`ccommand Version: ${X}`,color:"green"}));if(u[0]==="-h"||u[0]==="--help"){const o=k(p?"\u6253\u5F00\u4E00\u4E2A\u65B0\u7684\u95EE\u9898":"open an issue","https://github.com/Simon-He95/ccommand/issues"),s=k(p?"\u2728\u5E2E\u52A9\u70B9\u4E00\u4E2A\u661F\u661F":"\u2728star it","https://github.com/Simon-He95/ccommand");return f(c({color:"white",text:`
|
|
6
|
+
${c({bold:!0,text:"Common Commands:",bgColor:"blue"})}
|
|
7
|
+
${c({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
|
-
command '${(
|
|
15
|
-
command '${
|
|
16
|
-
command '${
|
|
17
|
-
command ${
|
|
12
|
+
If you encounter any problems, you can ${c({color:"magenta",text:o})}.
|
|
13
|
+
If you like it, please ${c({text:s,bold:!0,color:"cyan"})} `}))}const l=ne(),[R,T,w]=he(u);let d=R,x;if(u[0]==="find"){if(T)await I(l),d=O.filter(o=>o.includes(T))[0];else if(l==="yarn"){if(await I(l),!O.length)return f(c({color:"yellow",text:r}));const{result:o}=F(`echo ${O.join(",")} | sed "s/,/\\n/g" | gum filter --placeholder=" \u{1F914}${p?"\u8BF7\u9009\u62E9\u4E00\u4E2A\u8981\u6267\u884C\u7684\u76EE\u5F55":"Please select a directory to execute"}"`,"pipe");if(d=o,!d)return f(c({color:"yellow",text:e}))}else if(l==="pnpm"){if(await I(l),!O.length)return f(c({color:"yellow",text:r}));const{result:o}=F(`echo ${O.join(",")} | sed "s/,/\\n/g" | gum filter --placeholder=" \u{1F914}${p?"\u8BF7\u9009\u62E9\u4E00\u4E2A\u8981\u6267\u884C\u7684\u76EE\u5F55":"Please select a directory to execute"}"`,"pipe");if(d=o.trim(),!d)return f(c({color:"yellow",text:e}))}else return f(c({color:"red",text:p?"find\u6307\u4EE4\u53EA\u80FD\u652F\u6301\u5728yarn\u6216pnpm\u7684monorepo\u6A21\u5F0F\u4E0B\u4F7F\u7528":"find command only support yarn or pnpm"}));x=await G()}else{if(x=await G(),R&&y&&!y[R]||!y)try{const o=(await B("./package.json")||{})?.scripts;if(o&&o[u[0]])return f(c({text:`${p?"ccommand\u6B63\u5728\u6267\u884C":"ccommand is executing"} ${c({color:"cyan",text:`'${u[0]}'`})} \u{1F914} `,color:"yellow"})),H(u[0],u.slice(1).join(" "));if(o&&R){const s=ge(o,u[0]),$=u.slice(1).join(" ");return H(s,$)}}catch{}y&&!y[u[0]]&&(f(c({color:"red",text:`"${u[0]}" ${p?"\u5728\u5DE5\u4F5C\u533A\u3001\u5F53\u524D\u76EE\u5F55\u4E2D\u627E\u4E0D\u5230\u4EFB\u4F55\u53EF\u6267\u884C\u7684\u811A\u672C,\u8BF7\u68C0\u67E5":"is not found in workspace, current directory or current scripts, please check"}`})),process.exit())}if(!x)return f(c({color:"red",text:p?"\u627E\u4E0D\u5230\u4EFB\u4F55\u53EF\u6267\u884C\u811A\u672C":"No scripts found"}));const v=[];let h="";if(!T||u[0]==="find"&&(!u[2]||u[2].startsWith("--"))){const o=Object.keys(x).reduce(($,E)=>{const j=x[E];return v.push(E),$+=`"${E}: ${j.replace(/\"/g,"'")}"${Q}`,$},""),{result:s}=F(`echo ${o} | sed "s/${Q}/\\n/g" | gum filter --placeholder=" \u{1F914}\u8BF7\u9009\u62E9\u4E00\u4E2A\u8981\u6267\u884C\u7684\u6307\u4EE4"`,"pipe");h=s.substring(0,s.indexOf(": "))}if(!T&&!h)return f(c({color:"yellow",text:e})),process.exit();const{status:ee}=await F(re());if(ee===0)return f(c({color:"green",text:`
|
|
14
|
+
command '${(u[0]==="find"?u[2]:u[1])||h}' ${t} \u{1F389}`})),process.exit();f(c({color:"red",text:`
|
|
15
|
+
command '${h}' ${n} \u274C`}));function V(o){return v.find(s=>s===o)??v.find(s=>o.startsWith(s))}function re(){let o="",s="";const $=l!=="yarn";l==="npm"?(s=w?` -- ${w}`:"",o=d?` --prefix ${d} `:" "):l==="pnpm"?(s=w?` ${w}`:"",o=d?` --filter ${d} `:" "):l==="yarn"?(s=w?` ${w}`:"",o=d?` workspace ${d} `:" "):l==="bun"&&(s=w?` ${w}`:"",o="");let E="";if(s&&!s.startsWith(" --")){const Y=s.split(" ").filter(Boolean);E=Y[0],s=Y.slice(1).join(" ")}const j=`${l}${$?" run":" "}${o} ${E||(h?V(h)||h:T)} ${te(s)?`-- ${s}`:s}`;return h=`${E||(h?V(h):T)}`,u[0]==="find"?f(c({text:`${p?"\u63D0\u793A":"tips"}: pfind ${d} ${h} ${s}`.replace(/\s+/g," "),color:"blue",bold:!0})):f(c({text:`${p?"\u63D0\u793A":"tips"}: prun ${h} ${s}`.replace(/\s+/g," "),color:"blue",bold:!0})),j}async function G(){try{if(!d||l==="bun"||l==="npm")return(await B("./package.json"))?.scripts;if(l==="pnpm")return(await I(l))[d]||(await B(`${d}/package.json`))?.scripts;if(l==="yarn")return(await I(l))[d]||(await B(`${d}/package.json`))?.scripts}catch{}}function te(o){return u[0]==="find",u[1]&&o}async function H(o,s){let $;switch(o&&u[0]!==o&&f(c({text:`\u{1F914} ${c({text:`'${u[0]}'`,color:"cyan"})} ${p?"\u81EA\u52A8\u7684\u4E3A\u60A8\u5339\u914D\u6210":"automatically match for you to"} ${c({text:`'${o}${s?` ${s}`:""}'`,color:"cyan"})} `,color:"yellow"})),l){case"npm":{const{status:E}=F(`npm run ${o}${s?` -- ${s}`:""}`);$=E;break}case"pnpm":{const{status:E}=F(`pnpm run ${o}${s?` ${s}`:""}`);$=E;break}case"yarn":{const{status:E}=F(`yarn ${o}${s?` ${s}`:""}`);$=E;break}case"bun":{const{status:E}=F(`bun ${o} ${s}`);$=E;break}}return f($===0?c({color:"green",text:`
|
|
16
|
+
command '${o}${s?` ${s}`:""}' ${t} \u{1F389}`}):c({color:"red",text:`
|
|
17
|
+
command ${c({bold:!0,color:"cyan",text:`'${o||u[0]}${s?` ${s}`:""}'`})} ${n} \u274C`}))}}async function I(e){if(y)return y;let r="";try{r=e==="pnpm"?await W.readFile(q.resolve(process.cwd(),"pnpm-workspace.yaml"),"utf-8"):await W.readFile(q.resolve(process.cwd(),"package.json"),"utf-8")}catch{f(c({color:"red",text:p?"pfind\u547D\u4EE4\u9700\u8981\u8BFB\u53D6pnpm-workspace.yaml,\u5F53\u524D\u76EE\u5F55\u4E0B\u5E76\u4E0D\u5B58\u5728":"The pfind command needs to read pnpm-workspace.yaml, which does not exist in the current directory"})),process.exit(0)}let t;if(e==="pnpm")t=Ee.parse(r)?.packages||[];else{const n=JSON.parse(r)?.workspaces;oe(n)?t=n?.packages:t=n||[]}return y=await $e(t)||{},O=Object.keys(y).filter(n=>y[n]&&Object.keys(y[n]).length),y}function he(e){const r=e[0];return r?r.startsWith("--")?["","",e.join(" ")]:e[1]&&e[1].startsWith("--")?[r,"",e.slice(1).join(" ")]:[r,e[1],e.slice(2).join(" ")]:["","",""]}async function $e(e){if(!e.length)return;const r=await se(e.map(t=>`${t}/package.json`),{dot:!0,ignore:["**/node_modules/**"]});return Promise.all(r.map(async t=>{const n=await B(t);if(!n)return;const{name:u,scripts:l}=n;return{name:u,scripts:l}})).then(t=>t.reduce((n,u)=>{const{name:l,scripts:R}=u;return!l||!R||(n[l]=R),n},{}))}function ge(e,r){const t=Object.keys(e),n=t.find(u=>u.startsWith(r));if(n)return n;try{const u=new RegExp(r.split("").join("[_-\\w$.:]*"));return t.find(l=>u.test(l))}catch(u){f(c({text:`${p?"\u6B63\u5219\u9519\u8BEF":"RegExp error"}: ${u}`,color:"red"})),process.exit(1)}}Z();export{Z as ccommand};
|