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