ccommand 1.0.37 → 1.0.38
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 -7
- package/dist/index.mjs +7 -7
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var $e=require("module"),X=require("fs/promises"),Q=require("path"),d=require("lazy-js-utils"),Z=require("fast-glob"),ee=require("@simon_he/colorize"),re=require("os"),te=require("tty");function k(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var B=k(X),q=k(Q),ne=k(Z),a=k(ee),se=k(re),oe=k(te),ue=require;const i="\x1B[",C="\x1B]",_="\x07",v=";",V=process.env.TERM_PROGRAM==="Apple_Terminal",u={};u.cursorTo=(e,r)=>{if(typeof e!="number")throw new TypeError("The `x` argument is required");return typeof r!="number"?i+(e+1)+"G":i+(r+1)+";"+(e+1)+"H"},u.cursorMove=(e,r)=>{if(typeof e!="number")throw new TypeError("The `x` argument is required");let t="";return e<0?t+=i+-e+"D":e>0&&(t+=i+e+"C"),r<0?t+=i+-r+"A":r>0&&(t+=i+r+"B"),t},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=V?"\x1B7":i+"s",u.cursorRestorePosition=V?"\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 r="";for(let t=0;t<e;t++)r+=u.eraseLine+(t<e-1?u.cursorUp():"");return e&&(r+=u.cursorLeft),r},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=_,u.link=(e,r)=>[C,"8",v,v,r,_,e,C,"8",v,v,_].join(""),u.image=(e,r={})=>{let t=`${C}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")+_},u.iTerm={setCwd:(e=process.cwd())=>`${C}50;CurrentDir=${e}${_}`,annotation:(e,r={})=>{let t=`${C}1337;`;const n=typeof r.x<"u",l=typeof r.y<"u";if((n||l)&&!(n&&l&&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+_}};var G=(e,r=process.argv)=>{const t=e.startsWith("-")?"":e.length===1?"-":"--",n=r.indexOf(t+e),l=r.indexOf("--");return n!==-1&&(l===-1||n<l)};const ae=se.default,H=oe.default,$=G,{env:f}=process;let w;$("no-color")||$("no-colors")||$("color=false")||$("color=never")?w=0:($("color")||$("colors")||$("color=true")||$("color=always"))&&(w=1),"FORCE_COLOR"in f&&(f.FORCE_COLOR==="true"?w=1:f.FORCE_COLOR==="false"?w=0:w=f.FORCE_COLOR.length===0?1:Math.min(parseInt(f.FORCE_COLOR,10),3));function F(e){return e===0?!1:{level:e,hasBasic:!0,has256:e>=2,has16m:e>=3}}function I(e,r){if(w===0)return 0;if($("color=16m")||$("color=full")||$("color=truecolor"))return 3;if($("color=256"))return 2;if(e&&!r&&w===void 0)return 0;const t=w||0;if(f.TERM==="dumb")return t;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:t;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:t}function ie(e){const r=I(e,e&&e.isTTY);return F(r)}var le={supportsColor:ie,stdout:F(I(!0,H.isatty(1))),stderr:F(I(!0,H.isatty(2)))};const ce=le,b=G;function Y(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 x(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(!ce.supportsColor(e)||e&&!e.isTTY||process.platform==="win32"||"CI"in r||"TEAMCITY_VERSION"in r)return!1;if("TERM_PROGRAM"in r){const t=Y(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=Y(r.VTE_VERSION);return t.major>0||t.minor>=50}return!1}var L={supportsHyperlink:x,stdout:x(process.stdout),stderr:x(process.stderr)};function R(e,r,{target:t="stdout",...n}={}){return L[t]?u.link(e,r):n.fallback===!1?e:typeof n.fallback=="function"?n.fallback(e,r):`${e} (\u200B${r}\u200B)`}R.isSupported=L.stdout,R.stderr=(e,r,t={})=>R(e,r,{target:"stderr",...t}),R.stderr.isSupported=L.stderr;var fe="1.0.38";const A=console.log;function de(){const{status:e}=d.jsShell("gum -v","pipe");if(e!==0){A(a.default({color:"blue",text:"install gum..."}));const{status:r}=d.jsShell("brew install gum");if(r!==0){const{status:t}=d.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(
|
|
4
|
+
sudo apt update && sudo apt install gum`);if(t!==0){const n=R("the official website of gum","https://github.com/charmbracelet/gum#installation");return A(a.default({color:"red",text:`gum install error, you can install it yourself through ${a.default({color:"yellow",text:n,bold:!0})}`}))}}A(a.default({color:"green",text:"gum install successfully \u{1F389}"}))}}const pe=ue("yamljs");let j=[],y=null;const p=console.log,z="__ccommand__split";async function U(){de();const e=process.argv.slice(2);if(e[0]==="-v"||e[0]==="--version")return p(a.default({text:`ccommand Version: ${fe}`,color:"green"}));if(e[0]==="-h"||e[0]==="--help"){const s=R("open an issue","https://github.com/Simon-He95/ccommand/issues"),o=R("\u2728star it","https://github.com/Simon-He95/ccommand");return p(a.default({color:"white",text:`
|
|
5
5
|
${a.default({bold:!0,text:"Common Commands:",bgColor:"blue"})}
|
|
6
6
|
${a.default({text:`- ccommand -v \u67E5\u770B\u5F53\u524D\u7248\u672C
|
|
7
7
|
- ccommand -help \u67E5\u770B\u5E2E\u52A9
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
- ccommand find \u67E5\u627E\u5F53\u524Dworkspace\u7684\u6240\u6709\u76EE\u5F55
|
|
10
10
|
`,color:"cyan"})}
|
|
11
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
|
|
13
|
-
or current scripts, please check`})),process.exit())}if(!
|
|
14
|
-
command '${(
|
|
15
|
-
command '${
|
|
12
|
+
If you like it, please ${a.default({text:o,bold:!0,color:"cyan"})} `}))}const r=d.getPkgTool(),[t,n,l]=me(e);let c=t,E;if(e[0]==="find"){if(n)await O(r),c=j.filter(s=>s.includes(n))[0];else if(r==="yarn"){await O(r);const{result:s}=d.jsShell(`echo ${j.join(",")} | sed "s/,/\\n/g" | gum filter --placeholder=" \u{1F914}\u8BF7\u9009\u62E9\u4E00\u4E2A\u8981\u6267\u884C\u7684\u76EE\u5F55"`,"pipe");if(c=s,!c)return p(a.default({color:"yellow",text:"\u5DF2\u53D6\u6D88"}))}else if(r==="pnpm"){await O(r);const{result:s}=d.jsShell(`echo ${j.join(",")} | sed "s/,/\\n/g" | gum filter --placeholder=" \u{1F914}\u8BF7\u9009\u62E9\u4E00\u4E2A\u8981\u6267\u884C\u7684\u76EE\u5F55"`,"pipe");if(c=s.trim(),!c)return p(a.default({color:"yellow",text:"\u5DF2\u53D6\u6D88"}))}else return p(a.default({color:"red",text:"find command only support yarn or pnpm"}));E=await P()}else{if(E=await P(),t&&y&&!y[t]||!y)try{const s=(await d.getPkg("./package.json")||{})?.scripts;if(s&&s[e[0]])return p(a.default({text:`ccommand is executing ${a.default({color:"cyan",text:`'${e[0]}'`})} \u{1F914} `,color:"yellow"})),D(e[0],e.slice(1).join(" "));if(s&&t){const o=ge(s,e[0]),g=e.slice(1).join(" ");return D(o,g)}}catch{}y&&!y[e[0]]&&(p(a.default({color:"red",text:`"${e[0]}" is not found in workspace, current directory
|
|
13
|
+
or current scripts, please check`})),process.exit())}if(!E)return p(a.default({color:"red",text:"No scripts found"}));const T=[];let h="";if(!n||e[0]==="find"&&(!e[2]||e[2].startsWith("--"))){const s=Object.keys(E).reduce((g,m)=>{const S=E[m];return T.push(m),g+=`"${m}: ${S.replace(/\"/g,"'")}"${z}`,g},""),{result:o}=d.jsShell(`echo ${s} | sed "s/${z}/\\n/g" | gum filter --placeholder=" \u{1F914}\u8BF7\u9009\u62E9\u4E00\u4E2A\u8981\u6267\u884C\u7684\u6307\u4EE4"`,"pipe");h=o.substring(0,o.indexOf(": "))}if(!n&&!h)return p(a.default({color:"yellow",text:"\u5DF2\u53D6\u6D88"})),process.exit();const{status:W}=await d.jsShell(K());if(W===0)return p(a.default({color:"green",text:`
|
|
14
|
+
command '${(e[0]==="find"?e[2]:e[1])||h}' run successfully \u{1F389}`})),process.exit();p(a.default({color:"red",text:`
|
|
15
|
+
command '${h}' run error \u274C`}));function M(s){return T.find(o=>o===s)??T.find(o=>s.startsWith(o))}function K(){let s="",o="";const g=r!=="yarn";r==="npm"?(o=l?` -- ${l}`:"",s=c?` --prefix ${c} `:" "):r==="pnpm"?(o=l?` ${l}`:"",s=c?` --filter ${c} `:" "):r==="yarn"?(o=l?` ${l}`:"",s=c?` workspace ${c} `:" "):r==="bun"&&(o=l?` ${l}`:"",s="");let m="";if(o&&!o.startsWith(" --")){const N=o.split(" ").filter(Boolean);m=N[0],o=N.slice(1).join(" ")}const S=`${r}${g?" run":" "}${s} ${m||(h?M(h)||h:n)} ${J(o)?`-- ${o}`:o}`;return h=`${m||(h?M(h):n)}`,e[0]==="find"?p(a.default({text:`tips: pfind ${c} ${h} ${o}`.replace(/\s+/g," "),color:"blue",bold:!0})):p(a.default({text:`tips: prun ${h} ${o}`.replace(/\s+/g," "),color:"blue",bold:!0})),S}async function P(){try{if(!c||r==="bun"||r==="npm")return(await d.getPkg("./package.json"))?.scripts;if(r==="pnpm")return(await O(r))[c]||(await d.getPkg(`${c}/package.json`))?.scripts;if(r==="yarn")return(await O(r))[c]||(await d.getPkg(`${c}/package.json`))?.scripts}catch{}}function J(s){return e[0]==="find",e[1]&&s}async function D(s,o){let g;switch(s&&e[0]!==s&&p(a.default({text:`\u{1F914} ${a.default({text:`'${e[0]}'`,color:"cyan"})} automatically match for you to ${a.default({text:`'${s}${o?` ${o}`:""}'`,color:"cyan"})} `,color:"yellow"})),r){case"npm":{const{status:m}=d.jsShell(`npm run ${s}${o?` -- ${o}`:""}`);g=m;break}case"pnpm":{const{status:m}=d.jsShell(`pnpm run ${s}${o?` ${o}`:""}`);g=m;break}case"yarn":{const{status:m}=d.jsShell(`yarn ${s}${o?` ${o}`:""}`);g=m;break}case"bun":{const{status:m}=d.jsShell(`bun ${s} ${o}`);g=m;break}}return p(g===0?a.default({color:"green",text:`
|
|
16
16
|
command '${s}${o?` ${o}`:""}' run successfully \u{1F389}`}):a.default({color:"red",text:`
|
|
17
|
-
command ${a.default({bold:!0,color:"cyan",text:`'${s||
|
|
17
|
+
command ${a.default({bold:!0,color:"cyan",text:`'${s||e[0]}${o?` ${o}`:""}'`})} run error \u274C`}))}}async function O(e){if(y)return y;const r=e==="pnpm"?await B.default.readFile(q.default.resolve(process.cwd(),"pnpm-workspace.yaml"),"utf-8"):await B.default.readFile(q.default.resolve(process.cwd(),"package.json"),"utf-8"),t=e==="pnpm"?pe.parse(r)?.packages||[]:JSON.parse(r)?.workspaces||[];return y=await he(t)||{},j=Object.keys(y).filter(n=>y[n]&&Object.keys(y[n]).length),y}function me(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 he(e){if(!e.length)return;const r=await ne.default(e.map(t=>`${t}/package.json`),{dot:!0,ignore:["**/node_modules/**"]});return Promise.all(r.map(async t=>{const n=await d.getPkg(t);if(!n)return;const{name:l,scripts:c}=n;return{name:l,scripts:c}})).then(t=>t.reduce((n,l)=>{const{name:c,scripts:E}=l;return!c||!E||(n[c]=E),n},{}))}function ge(e,r){const t=Object.keys(e),n=t.find(l=>l.startsWith(r));if(n)return n;try{const l=new RegExp(r.split("").join("[_-\\w$.:]*"));return t.find(c=>l.test(c))}catch(l){p(a.default({text:`RegExp error: ${l}`,color:"red"})),process.exit(1)}}U(),exports.ccommand=U;
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{createRequire as X}from"module";import
|
|
2
|
+
import{createRequire as X}from"module";import D from"fs/promises";import V from"path";import{jsShell as E,getPkgTool as Q,getPkg as O}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[",b="\x1B]",k="\x07",F=";",G=process.env.TERM_PROGRAM==="Apple_Terminal",u={};u.cursorTo=(e,r)=>{if(typeof e!="number")throw new TypeError("The `x` argument is required");return typeof r!="number"?c+(e+1)+"G":c+(r+1)+";"+(e+1)+"H"},u.cursorMove=(e,r)=>{if(typeof e!="number")throw new TypeError("The `x` argument is required");let t="";return e<0?t+=c+-e+"D":e>0&&(t+=c+e+"C"),r<0?t+=c+-r+"A":r>0&&(t+=c+r+"B"),t},u.cursorUp=(e=1)=>c+e+"A",u.cursorDown=(e=1)=>c+e+"B",u.cursorForward=(e=1)=>c+e+"C",u.cursorBackward=(e=1)=>c+e+"D",u.cursorLeft=c+"G",u.cursorSavePosition=G?"\x1B7":c+"s",u.cursorRestorePosition=G?"\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=e=>{let r="";for(let t=0;t<e;t++)r+=u.eraseLine+(t<e-1?u.cursorUp():"");return e&&(r+=u.cursorLeft),r},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=k,u.link=(e,r)=>[b,"8",F,F,r,k,e,b,"8",F,F,k].join(""),u.image=(e,r={})=>{let t=`${b}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")+k},u.iTerm={setCwd:(e=process.cwd())=>`${b}50;CurrentDir=${e}${k}`,annotation:(e,r={})=>{let t=`${b}1337;`;const n=typeof r.x<"u",a=typeof r.y<"u";if((n||a)&&!(n&&a&&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+k}};var H=(e,r=process.argv)=>{const t=e.startsWith("-")?"":e.length===1?"-":"--",n=r.indexOf(t+e),a=r.indexOf("--");return n!==-1&&(a===-1||n<a)};const ne=ee,Y=re,$=H,{env:f}=process;let w;$("no-color")||$("no-colors")||$("color=false")||$("color=never")?w=0:($("color")||$("colors")||$("color=true")||$("color=always"))&&(w=1),"FORCE_COLOR"in f&&(f.FORCE_COLOR==="true"?w=1:f.FORCE_COLOR==="false"?w=0:w=f.FORCE_COLOR.length===0?1:Math.min(parseInt(f.FORCE_COLOR,10),3));function S(e){return e===0?!1:{level:e,hasBasic:!0,has256:e>=2,has16m:e>=3}}function j(e,r){if(w===0)return 0;if($("color=16m")||$("color=full")||$("color=truecolor"))return 3;if($("color=256"))return 2;if(e&&!r&&w===void 0)return 0;const t=w||0;if(f.TERM==="dumb")return t;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:t;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:t}function oe(e){const r=j(e,e&&e.isTTY);return S(r)}var se={supportsColor:oe,stdout:S(j(!0,Y.isatty(1))),stderr:S(j(!0,Y.isatty(2)))};const ue=se,C=H;function W(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 v(e){const{env:r}=process;if("FORCE_HYPERLINK"in r)return!(r.FORCE_HYPERLINK.length>0&&parseInt(r.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 r)return!0;if(!ue.supportsColor(e)||e&&!e.isTTY||process.platform==="win32"||"CI"in r||"TEAMCITY_VERSION"in r)return!1;if("TERM_PROGRAM"in r){const t=W(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=W(r.VTE_VERSION);return t.major>0||t.minor>=50}return!1}var A={supportsHyperlink:v,stdout:v(process.stdout),stderr:v(process.stderr)};function R(e,r,{target:t="stdout",...n}={}){return A[t]?u.link(e,r):n.fallback===!1?e:typeof n.fallback=="function"?n.fallback(e,r):`${e} (\u200B${r}\u200B)`}R.isSupported=A.stdout,R.stderr=(e,r,t={})=>R(e,r,{target:"stderr",...t}),R.stderr.isSupported=A.stderr;var ie="1.0.38";const L=console.log;function ce(){const{status:e}=E("gum -v","pipe");if(e!==0){L(i({color:"blue",text:"install gum..."}));const{status:r}=E("brew install gum");if(r!==0){const{status:t}=E(`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(t!==0){const n=R("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:n,bold:!0})}`}))}}L(i({color:"green",text:"gum install successfully \u{1F389}"}))}}const ae=te("yamljs");let _=[],g=null;const p=console.log,q="__ccommand__split";async function K(){ce();const e=process.argv.slice(2);if(e[0]==="-v"||e[0]==="--version")return p(i({text:`ccommand Version: ${ie}`,color:"green"}));if(e[0]==="-h"||e[0]==="--help"){const o=R("open an issue","https://github.com/Simon-He95/ccommand/issues"),s=R("\u2728star it","https://github.com/Simon-He95/ccommand");return p(i({color:"white",text:`
|
|
6
6
|
${i({bold:!0,text:"Common Commands:",bgColor:"blue"})}
|
|
7
7
|
${i({text:`- ccommand -v \u67E5\u770B\u5F53\u524D\u7248\u672C
|
|
8
8
|
- ccommand -help \u67E5\u770B\u5E2E\u52A9
|
|
@@ -10,9 +10,9 @@ import{createRequire as X}from"module";import V from"fs";import G from"path";imp
|
|
|
10
10
|
- ccommand find \u67E5\u627E\u5F53\u524Dworkspace\u7684\u6240\u6709\u76EE\u5F55
|
|
11
11
|
`,color:"cyan"})}
|
|
12
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
|
|
14
|
-
or current scripts, please check`})),process.exit())}if(!
|
|
15
|
-
command '${(e[0]==="find"?e[2]:e[1])
|
|
16
|
-
command '${
|
|
13
|
+
If you like it, please ${i({text:s,bold:!0,color:"cyan"})} `}))}const r=Q(),[t,n,a]=le(e);let l=t,y;if(e[0]==="find"){if(n)await T(r),l=_.filter(o=>o.includes(n))[0];else if(r==="yarn"){await T(r);const{result:o}=E(`echo ${_.join(",")} | sed "s/,/\\n/g" | gum filter --placeholder=" \u{1F914}\u8BF7\u9009\u62E9\u4E00\u4E2A\u8981\u6267\u884C\u7684\u76EE\u5F55"`,"pipe");if(l=o,!l)return p(i({color:"yellow",text:"\u5DF2\u53D6\u6D88"}))}else if(r==="pnpm"){await T(r);const{result:o}=E(`echo ${_.join(",")} | sed "s/,/\\n/g" | gum filter --placeholder=" \u{1F914}\u8BF7\u9009\u62E9\u4E00\u4E2A\u8981\u6267\u884C\u7684\u76EE\u5F55"`,"pipe");if(l=o.trim(),!l)return p(i({color:"yellow",text:"\u5DF2\u53D6\u6D88"}))}else return p(i({color:"red",text:"find command only support yarn or pnpm"}));y=await P()}else{if(y=await P(),t&&g&&!g[t]||!g)try{const o=(await O("./package.json")||{})?.scripts;if(o&&o[e[0]])return p(i({text:`ccommand is executing ${i({color:"cyan",text:`'${e[0]}'`})} \u{1F914} `,color:"yellow"})),N(e[0],e.slice(1).join(" "));if(o&&t){const s=pe(o,e[0]),h=e.slice(1).join(" ");return N(s,h)}}catch{}g&&!g[e[0]]&&(p(i({color:"red",text:`"${e[0]}" is not found in workspace, current directory
|
|
14
|
+
or current scripts, please check`})),process.exit())}if(!y)return p(i({color:"red",text:"No scripts found"}));const I=[];let d="";if(!n||e[0]==="find"&&(!e[2]||e[2].startsWith("--"))){const o=Object.keys(y).reduce((h,m)=>{const x=y[m];return I.push(m),h+=`"${m}: ${x.replace(/\"/g,"'")}"${q}`,h},""),{result:s}=E(`echo ${o} | sed "s/${q}/\\n/g" | gum filter --placeholder=" \u{1F914}\u8BF7\u9009\u62E9\u4E00\u4E2A\u8981\u6267\u884C\u7684\u6307\u4EE4"`,"pipe");d=s.substring(0,s.indexOf(": "))}if(!n&&!d)return p(i({color:"yellow",text:"\u5DF2\u53D6\u6D88"})),process.exit();const{status:z}=await E(U());if(z===0)return p(i({color:"green",text:`
|
|
15
|
+
command '${(e[0]==="find"?e[2]:e[1])||d}' run successfully \u{1F389}`})),process.exit();p(i({color:"red",text:`
|
|
16
|
+
command '${d}' run error \u274C`}));function M(o){return I.find(s=>s===o)??I.find(s=>o.startsWith(s))}function U(){let o="",s="";const h=r!=="yarn";r==="npm"?(s=a?` -- ${a}`:"",o=l?` --prefix ${l} `:" "):r==="pnpm"?(s=a?` ${a}`:"",o=l?` --filter ${l} `:" "):r==="yarn"?(s=a?` ${a}`:"",o=l?` workspace ${l} `:" "):r==="bun"&&(s=a?` ${a}`:"",o="");let m="";if(s&&!s.startsWith(" --")){const B=s.split(" ").filter(Boolean);m=B[0],s=B.slice(1).join(" ")}const x=`${r}${h?" run":" "}${o} ${m||(d?M(d)||d:n)} ${J(s)?`-- ${s}`:s}`;return d=`${m||(d?M(d):n)}`,e[0]==="find"?p(i({text:`tips: pfind ${l} ${d} ${s}`.replace(/\s+/g," "),color:"blue",bold:!0})):p(i({text:`tips: prun ${d} ${s}`.replace(/\s+/g," "),color:"blue",bold:!0})),x}async function P(){try{if(!l||r==="bun"||r==="npm")return(await O("./package.json"))?.scripts;if(r==="pnpm")return(await T(r))[l]||(await O(`${l}/package.json`))?.scripts;if(r==="yarn")return(await T(r))[l]||(await O(`${l}/package.json`))?.scripts}catch{}}function J(o){return e[0]==="find",e[1]&&o}async function N(o,s){let h;switch(o&&e[0]!==o&&p(i({text:`\u{1F914} ${i({text:`'${e[0]}'`,color:"cyan"})} automatically match for you to ${i({text:`'${o}${s?` ${s}`:""}'`,color:"cyan"})} `,color:"yellow"})),r){case"npm":{const{status:m}=E(`npm run ${o}${s?` -- ${s}`:""}`);h=m;break}case"pnpm":{const{status:m}=E(`pnpm run ${o}${s?` ${s}`:""}`);h=m;break}case"yarn":{const{status:m}=E(`yarn ${o}${s?` ${s}`:""}`);h=m;break}case"bun":{const{status:m}=E(`bun ${o} ${s}`);h=m;break}}return p(h===0?i({color:"green",text:`
|
|
17
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
|
|
18
|
+
command ${i({bold:!0,color:"cyan",text:`'${o||e[0]}${s?` ${s}`:""}'`})} run error \u274C`}))}}async function T(e){if(g)return g;const r=e==="pnpm"?await D.readFile(V.resolve(process.cwd(),"pnpm-workspace.yaml"),"utf-8"):await D.readFile(V.resolve(process.cwd(),"package.json"),"utf-8"),t=e==="pnpm"?ae.parse(r)?.packages||[]:JSON.parse(r)?.workspaces||[];return g=await fe(t)||{},_=Object.keys(g).filter(n=>g[n]&&Object.keys(g[n]).length),g}function le(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 fe(e){if(!e.length)return;const r=await Z(e.map(t=>`${t}/package.json`),{dot:!0,ignore:["**/node_modules/**"]});return Promise.all(r.map(async t=>{const n=await O(t);if(!n)return;const{name:a,scripts:l}=n;return{name:a,scripts:l}})).then(t=>t.reduce((n,a)=>{const{name:l,scripts:y}=a;return!l||!y||(n[l]=y),n},{}))}function pe(e,r){const t=Object.keys(e),n=t.find(a=>a.startsWith(r));if(n)return n;try{const a=new RegExp(r.split("").join("[_-\\w$.:]*"));return t.find(l=>a.test(l))}catch(a){p(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.38",
|
|
4
4
|
"packageManager": "pnpm@6.32.3",
|
|
5
5
|
"description": "ccommand",
|
|
6
6
|
"author": "Simon He",
|
|
@@ -63,6 +63,7 @@
|
|
|
63
63
|
"@types/node": "^17.0.45",
|
|
64
64
|
"@vitejs/plugin-vue": "^3.0.1",
|
|
65
65
|
"bumpp": "^8.2.1",
|
|
66
|
+
"commander": "^10.0.0",
|
|
66
67
|
"eslint": "^8.16.0",
|
|
67
68
|
"eslint-plugin-n": "^15.2.1",
|
|
68
69
|
"lint-staged": "^13.1.0",
|