@simon_he/pi 0.0.18 → 0.0.20

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/cli.mjs CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node --no-warnings
2
- import('./dist/index.mjs')
2
+ import('./dist/index.js')
package/dist/index.cjs CHANGED
@@ -1,10 +1,10 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var b=require("path"),x=require("process"),e=require("lazy-js-utils"),I=require("ora"),N=require("fast-glob");function d(t){return t&&typeof t=="object"&&"default"in t?t:{default:t}}var f=d(b),o=d(x),k=d(I),P=d(N),D="0.0.18";const g=o.default.cwd();async function p(t,s,n="ni"){const u=s?`Installing ${s} ...
1
+ "use strict";var D=Object.create;var p=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,M=Object.prototype.hasOwnProperty;var N=(t,e)=>{for(var n in e)p(t,n,{get:e[n],enumerable:!0})},h=(t,e,n,l)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of C(e))!M.call(t,i)&&i!==n&&p(t,i,{get:()=>e[i],enumerable:!(l=U(e,i))||l.enumerable});return t};var d=(t,e,n)=>(n=t!=null?D(J(t)):{},h(e||!t||!t.__esModule?p(n,"default",{value:t,enumerable:!0}):n,t)),H=t=>h(p({},"__esModule",{value:!0}),t);var L={};N(L,{pa:()=>_,pci:()=>P,pfind:()=>v,pi:()=>g,pil:()=>S,pinit:()=>I,prun:()=>j,pu:()=>k,pui:()=>b,runner:()=>F});module.exports=H(L);var f=d(require("path"),1),c=d(require("process"),1),s=require("lazy-js-utils"),w=d(require("ora"),1),$=d(require("fast-glob"),1);var y="0.0.20";var m=c.default.cwd();async function g(t,e,n="ni"){let l=e?`Installing ${e} ...
2
2
  `:`Updating dependency ...
3
- `,l=s?`Installed ${s} successfully! \u{1F60A}`:"Updated dependency successfully! \u{1F60A}",c=s?`Failed to install ${s} \u{1F62D}`:"Failed to update dependency! \u{1F62D}",a=await r(u),{status:i}=await e.useNodeWorker(`${n} ${t}`);i===0?a.succeed(l):a.fail(c),o.default.exit()}async function h(t,s){const n=`Uninstalling ${s} ...
4
- `,u=`
5
- UnInstalled ${s} successfully! \u{1F60A}`,l=`
6
- Failed to uninstall ${s} \u{1F62D}`;s||(console.log("Need to specify an uninstall package name"),o.default.exit(1));const c=await r(n),{status:a}=await e.useNodeWorker(`nun ${t}`);a===0?c.succeed(u):c.fail(l),o.default.exit()}function m(t){return e.jsShell(`ccommand ${t}`)}function $(t){return e.jsShell(`ccommand find ${t}`)}function j(){switch(console.log("Initializing project..."),e.getPkgTool()){case"npm":e.jsShell("npm init -y");return;case"yarn":e.jsShell("yarn init -y");return;case"pnpm":e.jsShell("pnpm init -y");return;default:e.jsShell("npm init -y")}}function y(t,s){const n=e.spaceFormat(t,"@latest ");return p(n,s?e.spaceFormat(`${s} `,"@latest ").trim():"")}function S(){return e.jsShell("nu")}function w(t,s){return p(t,s,"nci")}function v(){return e.jsShell("na")}async function U(){const{result:t="yellow"}=await e.jsShell("echo $PI_COLOR","pipe"),s=t,{result:n="star"}=await e.jsShell("echo $PI_SPINNER","pipe");return{color:s,spinner:n}}async function W(){const{status:t}=e.jsShell("gum -v","pipe");t===1&&await e.jsShell("brew install gum","pipe");const{status:s}=e.jsShell("ni -v","pipe");s===1&&await e.jsShell("npm i -g @antfu/ni","pipe");const{status:n}=e.jsShell("ccommand -v","pipe");n===1&&await e.jsShell("npm i -g ccommand","pipe")}function A(t){const s=t[0];s==="-v"||s==="--version"?(e.jsShell(`gum style --foreground 212 --border-foreground 212 --border double --align center --width 50 --margin "1 2" --padding "2 4" 'pi version:${D}' 'Please give me a \u{1F31F} for my efforts'`),o.default.exit(0)):(s==="-h"||s==="--help")&&(e.jsShell(`gum style --foreground 212 --border-foreground 212 --border double --align left --width 50 --margin "1 2" --padding "1 1" 'PI Commands:' '~ pi: install package' '~ pui: uninstall package' '~ prun: run package script' '~ pinit: package init' '~ pbuild: go build | cargo build' '~ pfind: find monorepo of yarn or pnpm' '~ pa: agent alias' '~ pu: package upgrade' '~ pci: package clean install' '~ pil: package latest install'`),o.default.exit(0))}const F={pi:p,pa:v,pui:h,pu:S,pil:y,pci:w,prun:m,pinit:j,pfind:$};function M(){const t=f.default.resolve(g,"go.mod"),{result:s}=e.jsShell(`(test -f "main.go" || test -f "${t}") && echo "0"|| echo "1"`,"pipe");return s==="0"}function q(){const t=f.default.resolve(g,"Cargo.toml"),{result:s}=e.jsShell(`test -f "${t}" && echo "0"|| echo "1"`,"pipe");return s==="0"}async function r(t){const{color:s,spinner:n}=await U();return k.default({text:t,spinner:n,color:s}).start()}function C(){const t=f.default.resolve(g,"package.json"),{result:s}=e.jsShell(`test -f "${t}" && echo "0"|| echo "1"`,"pipe");return s==="0"}async function _(){const t=o.default.argv[1],s=t.lastIndexOf("/")+1,n=t.slice(s,t.length),u=o.default.argv.slice(2);A(u);const l=e.spaceFormat(u.join(" ")).trim();if(!C()){if(M()){if(n==="pi"){const a=await r(`Installing ${l} ...
7
- `),{status:i}=await e.useNodeWorker(`go get ${l}`);i===0?a.succeed("Installed successfully! \u{1F60A}"):a.fail("Failed to install \u{1F62D}")}else if(n==="pui"){const a=await r(`Uninstalling ${l} ...
8
- `),{status:i}=await e.useNodeWorker(`go clean ${l}`);i===0?a.succeed("Uninstalled successfully! \u{1F60A}"):a.fail("Failed to uninstall \u{1F62D}")}else if(n==="prun"){const a=l?l.endsWith(".go")?[`**/${l}`]:[`**/${l}.go`,`**/${l}/main.go`]:"main.go",i=(await P.default(a))[0];i||(console.log("No such file"),o.default.exit(1)),e.jsShell(`go run ${i}`)}else n==="pinit"?e.jsShell(`go mod init ${l}`):n==="pbuild"?e.jsShell(`go build ${l}`):console.log("The commands is not supported");o.default.exit()}if(q()){if(n==="pi"){const a=await r(`Installing ${l} ...
9
- `),{status:i}=await e.useNodeWorker(`cargo install ${l}`);i===0?a.succeed("Installed successfully! \u{1F60A}"):a.fail("Failed to install \u{1F62D}")}else if(n==="pui"){const a=await r(`Uninstalling ${l} ...
10
- `),{status:i}=await e.useNodeWorker(`cargo uninstall ${l}`);i===0?a.succeed("Uninstalled successfully! \u{1F60A}"):a.fail("Failed to uninstall \u{1F62D}")}else n==="prun"?e.jsShell(`cargo run ${l}`):n==="pinit"?e.jsShell(`cargo init ${l}`):n==="pbuild"?e.jsShell(`cargo build ${l}`):console.log("The commands is not supported");o.default.exit()}if(!F[n]){console.log("The command does not exist, please execute pi -h to view the help");return}}const c=u.filter(a=>!a.startsWith("-")).join(" ");await W(),F[n](l,c)}_(),exports.pa=v,exports.pci=w,exports.pfind=$,exports.pi=p,exports.pil=y,exports.pinit=j,exports.prun=m,exports.pu=S,exports.pui=h,exports.runner=_;
3
+ `,i=e?`Installed ${e} successfully! \u{1F60A}`:"Updated dependency successfully! \u{1F60A}",r=e?`Failed to install ${e} \u{1F62D}`:"Failed to update dependency! \u{1F62D}",o=await q(t),a=await u(l),{status:W}=await(0,s.useNodeWorker)(`${n} ${o}`);W===0?a.succeed(i):a.fail(r),c.default.exit()}async function b(t,e){let n=`Uninstalling ${e} ...
4
+ `,l=`
5
+ UnInstalled ${e} successfully! \u{1F60A}`,i=`
6
+ Failed to uninstall ${e} \u{1F62D}`;e||(console.log("Need to specify an uninstall package name"),c.default.exit(1));let r=await u(n),{status:o}=await(0,s.useNodeWorker)(`nun ${t}`);o===0?r.succeed(l):r.fail(i),c.default.exit()}function j(t){return(0,s.jsShell)(`ccommand ${t}`)}function v(t){return(0,s.jsShell)(`ccommand find ${t}`)}function I(){switch(console.log("Initializing project..."),(0,s.getPkgTool)()){case"npm":(0,s.jsShell)("npm init -y");return;case"yarn":(0,s.jsShell)("yarn init -y");return;case"pnpm":(0,s.jsShell)("pnpm init -y");return;default:(0,s.jsShell)("npm init -y")}}function S(t,e){let n=(0,s.spaceFormat)(t,"@latest ");return g(n,e?(0,s.spaceFormat)(`${e} `,"@latest ").trim():"")}function k(){return(0,s.jsShell)("nu")}function P(t,e){return g(t,e,"nci")}function _(){return(0,s.jsShell)("na")}async function O(){let{result:t="yellow"}=await(0,s.jsShell)("echo $PI_COLOR","pipe"),e=t,{result:n="star"}=await(0,s.jsShell)("echo $PI_SPINNER","pipe");return{color:e,spinner:n}}async function R(){let{status:t}=(0,s.jsShell)("gum -v","pipe");t===1&&await(0,s.jsShell)("brew install gum","pipe");let{status:e}=(0,s.jsShell)("ni -v","pipe");e===1&&await(0,s.jsShell)("npm i -g @antfu/ni","pipe");let{status:n}=(0,s.jsShell)("ccommand -v","pipe");n===1&&await(0,s.jsShell)("npm i -g ccommand","pipe")}function E(t){let e=t[0];e==="-v"||e==="--version"?((0,s.jsShell)(`gum style --foreground 212 --border-foreground 212 --border double --align center --width 50 --margin "1 2" --padding "2 4" 'pi version:${y}' 'Please give me a \u{1F31F} for my efforts'`),c.default.exit(0)):(e==="-h"||e==="--help")&&((0,s.jsShell)(`gum style --foreground 212 --border-foreground 212 --border double --align left --width 50 --margin "1 2" --padding "1 1" 'PI Commands:' '~ pi: install package' '~ pui: uninstall package' '~ prun: run package script' '~ pinit: package init' '~ pbuild: go build | cargo build' '~ pfind: find monorepo of yarn or pnpm' '~ pa: agent alias' '~ pu: package upgrade' '~ pci: package clean install' '~ pil: package latest install'`),c.default.exit(0))}var x={pi:g,pa:_,pui:b,pu:k,pil:S,pci:P,prun:j,pinit:I,pfind:v};function z(){let t=f.default.resolve(m,"go.mod"),{result:e}=(0,s.jsShell)(`(test -f "main.go" || test -f "${t}") && echo "0"|| echo "1"`,"pipe");return e==="0"}function G(){let t=f.default.resolve(m,"Cargo.toml"),{result:e}=(0,s.jsShell)(`test -f "${t}" && echo "0"|| echo "1"`,"pipe");return e==="0"}async function u(t){let{color:e,spinner:n}=await O();return(0,w.default)({text:t,spinner:n,color:e}).start()}function V(){let t=f.default.resolve(m,"package.json"),{result:e}=(0,s.jsShell)(`test -f "${t}" && echo "0"|| echo "1"`,"pipe");return e==="0"}async function q(t){let e=/-DW/,n=/-W/,l=/-Dw/,i=/-w/;switch((0,s.getPkgTool)()){case"pnpm":return e.test(t)?t=t.replace(e,"-Dw"):n.test(t)&&(t=t.replace(n,"-w")),t;case"yarn":return l.test(t)?t=t.replace(l,"-DW"):n.test(t)&&(t=t.replace(i,"-W")),t;default:return t}}async function F(){let t=c.default.argv[1],e=t.lastIndexOf("/")+1,n=t.slice(e,t.length),l=c.default.argv.slice(2);E(l);let i=(0,s.spaceFormat)(l.join(" ")).trim();if(!V()){if(z()){if(n==="pi"){let o=await u(`Installing ${i} ...
7
+ `),{status:a}=await(0,s.useNodeWorker)(`go get ${i}`);a===0?o.succeed("Installed successfully! \u{1F60A}"):o.fail("Failed to install \u{1F62D}")}else if(n==="pui"){let o=await u(`Uninstalling ${i} ...
8
+ `),{status:a}=await(0,s.useNodeWorker)(`go clean ${i}`);a===0?o.succeed("Uninstalled successfully! \u{1F60A}"):o.fail("Failed to uninstall \u{1F62D}")}else if(n==="prun"){let o=i?i.endsWith(".go")?[`**/${i}`]:[`**/${i}.go`,`**/${i}/main.go`]:"main.go",a=(await(0,$.default)(o))[0];a||(console.log("No such file"),c.default.exit(1)),(0,s.jsShell)(`go run ${a}`)}else n==="pinit"?(0,s.jsShell)(`go mod init ${i}`):n==="pbuild"?(0,s.jsShell)(`go build ${i}`):console.log("The commands is not supported");c.default.exit()}if(G()){if(n==="pi"){let o=await u(`Installing ${i} ...
9
+ `),{status:a}=await(0,s.useNodeWorker)(`cargo install ${i}`);a===0?o.succeed("Installed successfully! \u{1F60A}"):o.fail("Failed to install \u{1F62D}")}else if(n==="pui"){let o=await u(`Uninstalling ${i} ...
10
+ `),{status:a}=await(0,s.useNodeWorker)(`cargo uninstall ${i}`);a===0?o.succeed("Uninstalled successfully! \u{1F60A}"):o.fail("Failed to uninstall \u{1F62D}")}else n==="prun"?(0,s.jsShell)(`cargo run ${i}`):n==="pinit"?(0,s.jsShell)(`cargo init ${i}`):n==="pbuild"?(0,s.jsShell)(`cargo build ${i}`):console.log("The commands is not supported");c.default.exit()}if(!x[n]){console.log("The command does not exist, please execute pi -h to view the help");return}}let r=l.filter(o=>!o.startsWith("-")).join(" ");await R(),x[n](i,r)}F();0&&(module.exports={pa,pci,pfind,pi,pil,pinit,prun,pu,pui,runner});
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ import f from"path";import c from"process";import{getPkgTool as x,jsShell as n,spaceFormat as d,useNodeWorker as u}from"lazy-js-utils";import b from"ora";import j from"fast-glob";var h="0.0.20";var g=c.cwd();async function m(t,e,s="ni"){let a=e?`Installing ${e} ...
2
+ `:`Updating dependency ...
3
+ `,i=e?`Installed ${e} successfully! \u{1F60A}`:"Updated dependency successfully! \u{1F60A}",r=e?`Failed to install ${e} \u{1F62D}`:"Failed to update dependency! \u{1F62D}",o=await H(t),l=await p(a),{status:w}=await u(`${s} ${o}`);w===0?l.succeed(i):l.fail(r),c.exit()}async function v(t,e){let s=`Uninstalling ${e} ...
4
+ `,a=`
5
+ UnInstalled ${e} successfully! \u{1F60A}`,i=`
6
+ Failed to uninstall ${e} \u{1F62D}`;e||(console.log("Need to specify an uninstall package name"),c.exit(1));let r=await p(s),{status:o}=await u(`nun ${t}`);o===0?r.succeed(a):r.fail(i),c.exit()}function I(t){return n(`ccommand ${t}`)}function S(t){return n(`ccommand find ${t}`)}function k(){switch(console.log("Initializing project..."),x()){case"npm":n("npm init -y");return;case"yarn":n("yarn init -y");return;case"pnpm":n("pnpm init -y");return;default:n("npm init -y")}}function P(t,e){let s=d(t,"@latest ");return m(s,e?d(`${e} `,"@latest ").trim():"")}function _(){return n("nu")}function F(t,e){return m(t,e,"nci")}function W(){return n("na")}async function D(){let{result:t="yellow"}=await n("echo $PI_COLOR","pipe"),e=t,{result:s="star"}=await n("echo $PI_SPINNER","pipe");return{color:e,spinner:s}}async function U(){let{status:t}=n("gum -v","pipe");t===1&&await n("brew install gum","pipe");let{status:e}=n("ni -v","pipe");e===1&&await n("npm i -g @antfu/ni","pipe");let{status:s}=n("ccommand -v","pipe");s===1&&await n("npm i -g ccommand","pipe")}function C(t){let e=t[0];e==="-v"||e==="--version"?(n(`gum style --foreground 212 --border-foreground 212 --border double --align center --width 50 --margin "1 2" --padding "2 4" 'pi version:${h}' 'Please give me a \u{1F31F} for my efforts'`),c.exit(0)):(e==="-h"||e==="--help")&&(n(`gum style --foreground 212 --border-foreground 212 --border double --align left --width 50 --margin "1 2" --padding "1 1" 'PI Commands:' '~ pi: install package' '~ pui: uninstall package' '~ prun: run package script' '~ pinit: package init' '~ pbuild: go build | cargo build' '~ pfind: find monorepo of yarn or pnpm' '~ pa: agent alias' '~ pu: package upgrade' '~ pci: package clean install' '~ pil: package latest install'`),c.exit(0))}var y={pi:m,pa:W,pui:v,pu:_,pil:P,pci:F,prun:I,pinit:k,pfind:S};function J(){let t=f.resolve(g,"go.mod"),{result:e}=n(`(test -f "main.go" || test -f "${t}") && echo "0"|| echo "1"`,"pipe");return e==="0"}function M(){let t=f.resolve(g,"Cargo.toml"),{result:e}=n(`test -f "${t}" && echo "0"|| echo "1"`,"pipe");return e==="0"}async function p(t){let{color:e,spinner:s}=await D();return b({text:t,spinner:s,color:e}).start()}function N(){let t=f.resolve(g,"package.json"),{result:e}=n(`test -f "${t}" && echo "0"|| echo "1"`,"pipe");return e==="0"}async function H(t){let e=/-DW/,s=/-W/,a=/-Dw/,i=/-w/;switch(x()){case"pnpm":return e.test(t)?t=t.replace(e,"-Dw"):s.test(t)&&(t=t.replace(s,"-w")),t;case"yarn":return a.test(t)?t=t.replace(a,"-DW"):s.test(t)&&(t=t.replace(i,"-W")),t;default:return t}}async function T(){let t=c.argv[1],e=t.lastIndexOf("/")+1,s=t.slice(e,t.length),a=c.argv.slice(2);C(a);let i=d(a.join(" ")).trim();if(!N()){if(J()){if(s==="pi"){let o=await p(`Installing ${i} ...
7
+ `),{status:l}=await u(`go get ${i}`);l===0?o.succeed("Installed successfully! \u{1F60A}"):o.fail("Failed to install \u{1F62D}")}else if(s==="pui"){let o=await p(`Uninstalling ${i} ...
8
+ `),{status:l}=await u(`go clean ${i}`);l===0?o.succeed("Uninstalled successfully! \u{1F60A}"):o.fail("Failed to uninstall \u{1F62D}")}else if(s==="prun"){let o=i?i.endsWith(".go")?[`**/${i}`]:[`**/${i}.go`,`**/${i}/main.go`]:"main.go",l=(await j(o))[0];l||(console.log("No such file"),c.exit(1)),n(`go run ${l}`)}else s==="pinit"?n(`go mod init ${i}`):s==="pbuild"?n(`go build ${i}`):console.log("The commands is not supported");c.exit()}if(M()){if(s==="pi"){let o=await p(`Installing ${i} ...
9
+ `),{status:l}=await u(`cargo install ${i}`);l===0?o.succeed("Installed successfully! \u{1F60A}"):o.fail("Failed to install \u{1F62D}")}else if(s==="pui"){let o=await p(`Uninstalling ${i} ...
10
+ `),{status:l}=await u(`cargo uninstall ${i}`);l===0?o.succeed("Uninstalled successfully! \u{1F60A}"):o.fail("Failed to uninstall \u{1F62D}")}else s==="prun"?n(`cargo run ${i}`):s==="pinit"?n(`cargo init ${i}`):s==="pbuild"?n(`cargo build ${i}`):console.log("The commands is not supported");c.exit()}if(!y[s]){console.log("The command does not exist, please execute pi -h to view the help");return}}let r=a.filter(o=>!o.startsWith("-")).join(" ");await U(),y[s](i,r)}T();export{W as pa,F as pci,S as pfind,m as pi,P as pil,k as pinit,I as prun,_ as pu,v as pui,T as runner};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@simon_he/pi",
3
3
  "type": "module",
4
- "version": "0.0.18",
4
+ "version": "0.0.20",
5
5
  "packageManager": "pnpm@7.2.1",
6
6
  "description": "",
7
7
  "author": "Simon He",
@@ -22,7 +22,7 @@
22
22
  "import": "./dist/index.mjs"
23
23
  }
24
24
  },
25
- "main": "./dist/index.cjs",
25
+ "main": "./dist/index.js",
26
26
  "module": "./dist/index.mjs",
27
27
  "types": "./dist/index.d.ts",
28
28
  "typesVersions": {
@@ -50,8 +50,8 @@
50
50
  ],
51
51
  "scripts": {
52
52
  "postinstall": "simple-git-hooks",
53
- "build": "pkgroll --minify",
54
- "dev": "pkgroll --watch",
53
+ "build": "tsup ./src/index.ts --format cjs,esm --dts --clean --minify",
54
+ "dev": "npm run build -- --watch src",
55
55
  "format": "prettier --write --cache .",
56
56
  "lint": "eslint .",
57
57
  "lint:fix": "eslint . --fix",
@@ -62,29 +62,30 @@
62
62
  "typecheck": "tsc --noEmit"
63
63
  },
64
64
  "dependencies": {
65
+ "build": "^0.1.4",
65
66
  "fast-glob": "^3.2.12",
66
- "lazy-js-utils": "^0.0.8",
67
+ "lazy-js-utils": "^0.0.10",
67
68
  "ora": "^6.1.2"
68
69
  },
69
70
  "devDependencies": {
70
- "@antfu/eslint-config": "^0.25.2",
71
- "@antfu/ni": "^0.16.3",
72
- "@antfu/utils": "^0.5.2",
71
+ "@antfu/eslint-config": "^0.34.0",
72
+ "@antfu/ni": "^0.18.0",
73
+ "@antfu/utils": "^0.7.0",
73
74
  "@types/node": "^18.11.15",
74
75
  "bumpp": "^8.2.1",
75
76
  "eslint": "^8.29.0",
76
77
  "esno": "^0.16.3",
77
78
  "lint-staged": "^13.1.0",
78
79
  "picocolors": "^1.0.0",
79
- "pkgroll": "^1.8.0",
80
80
  "pnpm": "^7.18.2",
81
81
  "prettier": "^2.8.1",
82
82
  "rimraf": "^3.0.2",
83
83
  "simple-git-hooks": "^2.8.1",
84
+ "tsup": "^6.5.0",
84
85
  "tsx": "^3.12.1",
85
86
  "typescript": "^4.9.4",
86
- "unbuild": "^0.7.6",
87
- "vitest": "^0.25.8"
87
+ "unbuild": "^1.0.0",
88
+ "vitest": "^0.26.0"
88
89
  },
89
90
  "simple-git-hooks": {
90
91
  "pre-commit": "pnpm exec lint-staged --concurrent false",
package/dist/index.mjs DELETED
@@ -1,10 +0,0 @@
1
- import d from"path";import l from"process";import{useNodeWorker as r,jsShell as e,getPkgTool as P,spaceFormat as g}from"lazy-js-utils";import D from"ora";import U from"fast-glob";var A="0.0.18";const m=l.cwd();async function f(n,t,s="ni"){const c=t?`Installing ${t} ...
2
- `:`Updating dependency ...
3
- `,i=t?`Installed ${t} successfully! \u{1F60A}`:"Updated dependency successfully! \u{1F60A}",u=t?`Failed to install ${t} \u{1F62D}`:"Failed to update dependency! \u{1F62D}",a=await p(c),{status:o}=await r(`${s} ${n}`);o===0?a.succeed(i):a.fail(u),l.exit()}async function $(n,t){const s=`Uninstalling ${t} ...
4
- `,c=`
5
- UnInstalled ${t} successfully! \u{1F60A}`,i=`
6
- Failed to uninstall ${t} \u{1F62D}`;t||(console.log("Need to specify an uninstall package name"),l.exit(1));const u=await p(s),{status:a}=await r(`nun ${n}`);a===0?u.succeed(c):u.fail(i),l.exit()}function h(n){return e(`ccommand ${n}`)}function y(n){return e(`ccommand find ${n}`)}function w(){switch(console.log("Initializing project..."),P()){case"npm":e("npm init -y");return;case"yarn":e("yarn init -y");return;case"pnpm":e("pnpm init -y");return;default:e("npm init -y")}}function F(n,t){const s=g(n,"@latest ");return f(s,t?g(`${t} `,"@latest ").trim():"")}function v(){return e("nu")}function x(n,t){return f(n,t,"nci")}function b(){return e("na")}async function N(){const{result:n="yellow"}=await e("echo $PI_COLOR","pipe"),t=n,{result:s="star"}=await e("echo $PI_SPINNER","pipe");return{color:t,spinner:s}}async function j(){const{status:n}=e("gum -v","pipe");n===1&&await e("brew install gum","pipe");const{status:t}=e("ni -v","pipe");t===1&&await e("npm i -g @antfu/ni","pipe");const{status:s}=e("ccommand -v","pipe");s===1&&await e("npm i -g ccommand","pipe")}function k(n){const t=n[0];t==="-v"||t==="--version"?(e(`gum style --foreground 212 --border-foreground 212 --border double --align center --width 50 --margin "1 2" --padding "2 4" 'pi version:${A}' 'Please give me a \u{1F31F} for my efforts'`),l.exit(0)):(t==="-h"||t==="--help")&&(e(`gum style --foreground 212 --border-foreground 212 --border double --align left --width 50 --margin "1 2" --padding "1 1" 'PI Commands:' '~ pi: install package' '~ pui: uninstall package' '~ prun: run package script' '~ pinit: package init' '~ pbuild: go build | cargo build' '~ pfind: find monorepo of yarn or pnpm' '~ pa: agent alias' '~ pu: package upgrade' '~ pci: package clean install' '~ pil: package latest install'`),l.exit(0))}const I={pi:f,pa:b,pui:$,pu:v,pil:F,pci:x,prun:h,pinit:w,pfind:y};function M(){const n=d.resolve(m,"go.mod"),{result:t}=e(`(test -f "main.go" || test -f "${n}") && echo "0"|| echo "1"`,"pipe");return t==="0"}function C(){const n=d.resolve(m,"Cargo.toml"),{result:t}=e(`test -f "${n}" && echo "0"|| echo "1"`,"pipe");return t==="0"}async function p(n){const{color:t,spinner:s}=await N();return D({text:n,spinner:s,color:t}).start()}function T(){const n=d.resolve(m,"package.json"),{result:t}=e(`test -f "${n}" && echo "0"|| echo "1"`,"pipe");return t==="0"}async function _(){const n=l.argv[1],t=n.lastIndexOf("/")+1,s=n.slice(t,n.length),c=l.argv.slice(2);k(c);const i=g(c.join(" ")).trim();if(!T()){if(M()){if(s==="pi"){const a=await p(`Installing ${i} ...
7
- `),{status:o}=await r(`go get ${i}`);o===0?a.succeed("Installed successfully! \u{1F60A}"):a.fail("Failed to install \u{1F62D}")}else if(s==="pui"){const a=await p(`Uninstalling ${i} ...
8
- `),{status:o}=await r(`go clean ${i}`);o===0?a.succeed("Uninstalled successfully! \u{1F60A}"):a.fail("Failed to uninstall \u{1F62D}")}else if(s==="prun"){const a=i?i.endsWith(".go")?[`**/${i}`]:[`**/${i}.go`,`**/${i}/main.go`]:"main.go",o=(await U(a))[0];o||(console.log("No such file"),l.exit(1)),e(`go run ${o}`)}else s==="pinit"?e(`go mod init ${i}`):s==="pbuild"?e(`go build ${i}`):console.log("The commands is not supported");l.exit()}if(C()){if(s==="pi"){const a=await p(`Installing ${i} ...
9
- `),{status:o}=await r(`cargo install ${i}`);o===0?a.succeed("Installed successfully! \u{1F60A}"):a.fail("Failed to install \u{1F62D}")}else if(s==="pui"){const a=await p(`Uninstalling ${i} ...
10
- `),{status:o}=await r(`cargo uninstall ${i}`);o===0?a.succeed("Uninstalled successfully! \u{1F60A}"):a.fail("Failed to uninstall \u{1F62D}")}else s==="prun"?e(`cargo run ${i}`):s==="pinit"?e(`cargo init ${i}`):s==="pbuild"?e(`cargo build ${i}`):console.log("The commands is not supported");l.exit()}if(!I[s]){console.log("The command does not exist, please execute pi -h to view the help");return}}const u=c.filter(a=>!a.startsWith("-")).join(" ");await j(),I[s](i,u)}_();export{b as pa,x as pci,y as pfind,f as pi,F as pil,w as pinit,h as prun,v as pu,$ as pui,_ as runner};