ccommand 1.0.12 → 1.0.14
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 +2 -1
- package/dist/index.js +10 -2
- package/dist/index.mjs +10 -2
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -16,6 +16,7 @@ npm install -g ccommand # 安装ccommand
|
|
|
16
16
|
ccommand -v # 查看版本
|
|
17
17
|
ccommand find # 查找workspace
|
|
18
18
|
ccommand # 执行当前script
|
|
19
|
+
ccommand -help # 查看帮助
|
|
19
20
|
```
|
|
20
21
|
|
|
21
22
|
## 使用 | Usage
|
|
@@ -23,7 +24,7 @@ ccommand # 执行当前script
|
|
|
23
24
|
- ccommand playground 选取当前目录下的playground文件夹下的package.json文件中的scripts中的命令
|
|
24
25
|
- ccommand playground -silent 支持额外的参数传参
|
|
25
26
|
|
|
26
|
-
https://user-images.githubusercontent.com/57086651/
|
|
27
|
+
https://user-images.githubusercontent.com/57086651/198977837-1b2339dc-38d7-4565-b0b6-ea20ce7b5165.mov
|
|
27
28
|
|
|
28
29
|
|
|
29
30
|
<a href="https://github.com/Simon-He95/sponsor" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" style="height: 51px !important;width: 217px !important;" ></a>
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var A=require("module"),F=require("child_process"),x=require("fs"),O=require("path"),f=require("simon-js-tool"),B=require("fast-glob"),C=require("chalk"),I=require("terminal-link");function p(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var d=p(F),v=p(x),_=p(O),R=p(B),r=p(C),k=p(I),N=require;const T=N("yamljs");let h=[],o=null;async function b(){const e=console.log,s="__ccommand__split",{status:l}=d.default.spawnSync("gum -v",{shell:!0,encoding:"utf-8"});if(l!==0){e(r.default.blue("install gum..."));const{status:t}=d.default.spawnSync("brew install gum",{shell:!0});if(t!==0){const{status:a}=d.default.spawnSync(`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`,{shell:!0});if(
|
|
4
|
+
sudo apt update && sudo apt install gum`,{shell:!0});if(a!==0){const g=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(g)))}}e(r.default.green("gum install successfully"))}const c=process.argv.slice(2);if(c[0]==="-v"){const{version:t}=await f.getPkg();return e(r.default.green(`ccommand Version: ${t}`))}if(c[0]==="-help"){const t=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
|
+
${r.default.bgBlueBright.bold("Common Command:")}
|
|
6
|
+
${r.default.cyanBright(`- ccommand -v \u67E5\u770B\u5F53\u524D\u7248\u672C
|
|
7
|
+
- ccommand -help \u67E5\u770B\u5E2E\u52A9
|
|
8
|
+
- ccommand \u6267\u884C\u5F53\u524Dpackage.json
|
|
9
|
+
- ccommand find \u67E5\u627E\u5F53\u524Dworkspace\u7684\u6240\u6709\u76EE\u5F55
|
|
10
|
+
`)}
|
|
11
|
+
If you encounter any problems, you can ${r.default.magentaBright(t)}.
|
|
12
|
+
If you like it, please ${r.default.cyan.bold(a)}`))}const[m,u]=U(c);let n=m;const i=f.getPkgTool();if(c[0]==="find")if(i==="yarn")await S(),n=d.default.spawnSync(`echo ${h.join(",")} | sed "s/,/\\n/g" | gum filter`,{shell:!0,stdio:["inherit","pipe","inherit"],encoding:"utf8"}).output[1].trim();else if(i==="pnpm")await j(),n=d.default.spawnSync(`echo ${h.join(",")} | sed "s/,/\\n/g" | gum filter`,{shell:!0,stdio:["inherit","pipe","inherit"],encoding:"utf8"}).output[1].trim();else return e(r.default.red("find command only support yarn or pnpm"));const y=await E();if(!y)return e(r.default.red("No scripts found"));const w=[],D=Object.keys(y).reduce((t,a)=>{const g=y[a];return w.push(a),t+=`"${a}: ${g}"${s}`,t},""),$=d.default.spawnSync(`echo ${D} | sed "s/${s}/\\n/g" | gum filter | cut -d' ' -f1`,{shell:!0,stdio:["inherit","pipe","inherit"],encoding:"utf8"}).output[1];if(!$)return e(r.default.yellow("\u5DF2\u53D6\u6D88")),process.exit();d.default.spawnSync(L(),{shell:!0,stdio:"inherit"});function P(t){return w.find(a=>t.startsWith(a))}function L(){let t="",a="";const g=i!=="yarn";return i==="npm"?(a=u?` -- ${u}`:"",t=n?` --prefix ${n} `:" "):i==="pnpm"?(a=u?` ${u}`:"",t=n?` --filter ${n.slice(n.lastIndexOf("/")+1)} `:" "):i==="yarn"?(a=u?` ${u}`:"",t=n?` workspace ${n.slice(n.lastIndexOf("/")+1)} `:" "):i==="bun"&&(a=u?` ${u}`:"",t=""),`${i}${g?" run":" "}${t}${P($)}${a}`}async function E(){try{if(!n||i==="bun"||i==="npm")return(await f.getPkg("./package.json"))?.scripts;if(i==="pnpm")return(await j())[n]||(await f.getPkg(`${n}/package.json`))?.scripts;if(i==="yarn")return(await S())[n]||(await f.getPkg(`${n}/package.json`))?.scripts}catch{e(r.default.red("The package.json is not found in workspace or current directory, please check")),process.exit()}}}async function j(){if(o)return o;const e=await v.default.readFileSync(_.default.resolve(process.cwd(),"pnpm-workspace.yaml"),"utf-8"),s=T.parse(e)?.packages||[];return o=await q(s)||{},h=Object.keys(o),o}async function S(){if(o)return o;const e=await v.default.readFileSync(_.default.resolve(process.cwd(),"package.json"),"utf-8"),s=JSON.parse(e)?.workspaces||[];return o=await q(s)||{},h=Object.keys(o),o}function U(e){const s=e[0];return s?s.startsWith("--")?[".",e.join(" ")]:[s,e.slice(1).join(" ")]:["",""]}async function q(e){if(!e.length)return;const s=await R.default(e.map(l=>`${l}/package.json`),{dot:!0,ignore:["**/node_modules/**"]});return Promise.all(s.map(async l=>{const c=await f.getPkg(l);if(!c)return;const{name:m,scripts:u}=c;return{name:m,scripts:u}})).then(l=>l.reduce((c,m)=>{const{name:u,scripts:n}=m;return c[u]=n,c},{}))}b(),exports.ccommand=b;
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{createRequire as
|
|
2
|
+
import{createRequire as O}from"module";import l from"child_process";import $ from"fs";import b from"path";import{getPkg as g,getPkgTool as _}from"simon-js-tool";import C from"fast-glob";import r from"chalk";import y from"terminal-link";var L=O(import.meta.url);const P=L("yamljs");let d=[],u=null;async function S(){const t=console.log,o="__ccommand__split",{status:p}=l.spawnSync("gum -v",{shell:!0,encoding:"utf-8"});if(p!==0){t(r.blue("install gum..."));const{status:e}=l.spawnSync("brew install gum",{shell:!0});if(e!==0){const{status:s}=l.spawnSync(`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`,{shell:!0});if(
|
|
5
|
+
sudo apt update && sudo apt install gum`,{shell:!0});if(s!==0){const f=y("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(f)))}}t(r.green("gum install successfully"))}const c=process.argv.slice(2);if(c[0]==="-v"){const{version:e}=await g();return t(r.green(`ccommand Version: ${e}`))}if(c[0]==="-help"){const e=y("open an issue","https://github.com/Simon-He95/ccommand/issues"),s=y("\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
|
+
- ccommand -help \u67E5\u770B\u5E2E\u52A9
|
|
9
|
+
- ccommand \u6267\u884C\u5F53\u524Dpackage.json
|
|
10
|
+
- ccommand find \u67E5\u627E\u5F53\u524Dworkspace\u7684\u6240\u6709\u76EE\u5F55
|
|
11
|
+
`)}
|
|
12
|
+
If you encounter any problems, you can ${r.magentaBright(e)}.
|
|
13
|
+
If you like it, please ${r.cyan.bold(s)}`))}const[m,i]=I(c);let n=m;const a=_();if(c[0]==="find")if(a==="yarn")await v(),n=l.spawnSync(`echo ${d.join(",")} | sed "s/,/\\n/g" | gum filter`,{shell:!0,stdio:["inherit","pipe","inherit"],encoding:"utf8"}).output[1].trim();else if(a==="pnpm")await j(),n=l.spawnSync(`echo ${d.join(",")} | sed "s/,/\\n/g" | gum filter`,{shell:!0,stdio:["inherit","pipe","inherit"],encoding:"utf8"}).output[1].trim();else return t(r.red("find command only support yarn or pnpm"));const h=await B();if(!h)return t(r.red("No scripts found"));const w=[],E=Object.keys(h).reduce((e,s)=>{const f=h[s];return w.push(s),e+=`"${s}: ${f}"${o}`,e},""),k=l.spawnSync(`echo ${E} | sed "s/${o}/\\n/g" | gum filter | cut -d' ' -f1`,{shell:!0,stdio:["inherit","pipe","inherit"],encoding:"utf8"}).output[1];if(!k)return t(r.yellow("\u5DF2\u53D6\u6D88")),process.exit();l.spawnSync(x(),{shell:!0,stdio:"inherit"});function F(e){return w.find(s=>e.startsWith(s))}function x(){let e="",s="";const f=a!=="yarn";return a==="npm"?(s=i?` -- ${i}`:"",e=n?` --prefix ${n} `:" "):a==="pnpm"?(s=i?` ${i}`:"",e=n?` --filter ${n.slice(n.lastIndexOf("/")+1)} `:" "):a==="yarn"?(s=i?` ${i}`:"",e=n?` workspace ${n.slice(n.lastIndexOf("/")+1)} `:" "):a==="bun"&&(s=i?` ${i}`:"",e=""),`${a}${f?" run":" "}${e}${F(k)}${s}`}async function B(){try{if(!n||a==="bun"||a==="npm")return(await g("./package.json"))?.scripts;if(a==="pnpm")return(await j())[n]||(await g(`${n}/package.json`))?.scripts;if(a==="yarn")return(await v())[n]||(await g(`${n}/package.json`))?.scripts}catch{t(r.red("The package.json is not found in workspace or current directory, please check")),process.exit()}}}async function j(){if(u)return u;const t=await $.readFileSync(b.resolve(process.cwd(),"pnpm-workspace.yaml"),"utf-8"),o=P.parse(t)?.packages||[];return u=await D(o)||{},d=Object.keys(u),u}async function v(){if(u)return u;const t=await $.readFileSync(b.resolve(process.cwd(),"package.json"),"utf-8"),o=JSON.parse(t)?.workspaces||[];return u=await D(o)||{},d=Object.keys(u),u}function I(t){const o=t[0];return o?o.startsWith("--")?[".",t.join(" ")]:[o,t.slice(1).join(" ")]:["",""]}async function D(t){if(!t.length)return;const o=await C(t.map(p=>`${p}/package.json`),{dot:!0,ignore:["**/node_modules/**"]});return Promise.all(o.map(async p=>{const c=await g(p);if(!c)return;const{name:m,scripts:i}=c;return{name:m,scripts:i}})).then(p=>p.reduce((c,m)=>{const{name:i,scripts:n}=m;return c[i]=n,c},{}))}S();export{S as ccommand};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ccommand",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.14",
|
|
4
4
|
"packageManager": "pnpm@6.32.3",
|
|
5
5
|
"description": "ccommand",
|
|
6
6
|
"author": "Simon He",
|
|
@@ -49,8 +49,10 @@
|
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@vueuse/core": "^8.1.1",
|
|
52
|
+
"chalk": "^5.1.2",
|
|
52
53
|
"fast-glob": "^3.2.12",
|
|
53
54
|
"simon-js-tool": "^4.1.13",
|
|
55
|
+
"terminal-link": "^3.0.0",
|
|
54
56
|
"vue": "^3.2.36",
|
|
55
57
|
"yamljs": "^0.3.0"
|
|
56
58
|
},
|