nipox 0.0.1
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 +2 -0
- package/package.json +23 -0
- package/tsup.config.js +8 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{spawn as f}from"child_process";import{createWriteStream as u,unlinkSync as d,chmodSync as w}from"fs";import{tmpdir as x,platform as m}from"os";import{join as g}from"path";import{pipeline as b}from"stream/promises";function S(){return m()==="win32"?{shells:[{command:"bash",args:[],name:"Git Bash/WSL"},{command:"wsl",args:["bash"],name:"WSL bash"},{command:"powershell",args:["-File"],name:"PowerShell",extension:".ps1"}],scriptExtension:".sh"}:{shells:[{command:"bash",args:[],name:"bash"},{command:"sh",args:[],name:"sh"}],scriptExtension:".sh"}}function y(r){return r.toLowerCase().endsWith(".yml")||r.toLowerCase().endsWith(".yaml")}function E(r,e){return new Promise((o,s)=>{let t=["@go-task/cli","--dir",process.cwd(),"--taskfile",r,...e],i=f("npx",t,{stdio:"inherit",shell:!1});i.on("close",n=>{o(n)}),i.on("error",n=>{s(n)})})}async function $(r,e){let o=await fetch(r,{headers:{"Cache-Control":"no-cache, no-store, must-revalidate",Pragma:"no-cache",Expires:"0"}});if(!o.ok)throw new Error(`Failed to download: ${o.status} ${o.statusText}`);let s=u(e);await b(o.body,s)}async function W(r){for(let e of r)try{let o=f(e.command,["--version"],{stdio:"pipe",shell:!1});return await new Promise((s,t)=>{let i=setTimeout(()=>{o.kill(),t(new Error("Timeout"))},3e3);o.on("close",n=>{clearTimeout(i),n===0||n===null?s():t(new Error(`Exit code: ${n}`))}),o.on("error",t)}),e}catch(o){console.error(`${e.name} not available: ${o.message}`);continue}throw new Error("No compatible shell found. Please install bash, Git for Windows, or WSL.")}function P(r,e,o){return new Promise((s,t)=>{let i;if(o.extension===".ps1"){t(new Error("PowerShell execution not yet implemented. Please install Git Bash or WSL."));return}else i=[...o.args,r,...e];let n=f(o.command,i,{stdio:"inherit",shell:!1,cwd:process.cwd()});n.on("close",c=>{s(c)}),n.on("error",c=>{t(c)})})}async function L(){let r=process.argv.slice(2);r.length===0&&(console.error("Usage: npx nipox <url|script-name> [args...]"),console.error(""),console.error("Examples:"),console.error(" npx nipox https://example.com/script.sh arg1 arg2"),console.error(" npx nipox my-script arg1 arg2 # downloads from n-p-x/e repo"),console.error(" npx nipox repo/my-script arg1 arg2 # downloads from n-p-x/repo"),console.error(""),console.error("Platform:",m()),process.exit(1));let[e,...o]=r,s;if(e.startsWith("http://")||e.startsWith("https://"))s=e;else if(e.includes("/")){let[l,...p]=e.split("/"),h=p.join("/");s=`https://raw.githubusercontent.com/n-p-x/${l}/main/${h}`}else s=`https://raw.githubusercontent.com/n-p-x/e/main/${e}`;let t=S(),i=x(),n=y(s),c=n?".yml":t.scriptExtension,a=g(i,`nipox-${Date.now()}${c}`);try{if(console.error(`Platform: ${m()}`),console.error(`Downloading: ${s}`),await $(s,a),m()!=="win32"&&w(a,493),n){console.error("Detected YAML file. Executing with Taskfile...");let h=await E(a,o);d(a),process.exit(h)}console.error("Finding compatible shell...");let l=await W(t.shells);console.error(`Using: ${l.name}`),console.error(`Executing: ${e} ${o.join(" ")}`);let p=await P(a,o,l);d(a),process.exit(p)}catch(l){try{d(a)}catch{}console.error(`Error: ${l.message}`),l.message.includes("No compatible shell found")&&(console.error(""),console.error("Solutions:"),m()==="win32"?(console.error(" - Install Git for Windows (includes Git Bash)"),console.error(" - Install Windows Subsystem for Linux (WSL)"),console.error(" - Use PowerShell (limited support)")):(console.error(" - Install bash: sudo apt install bash (Ubuntu/Debian)"),console.error(" - Install bash: brew install bash (macOS)"))),process.exit(1)}}(async()=>await L())();
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nipox",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Download and execute bash scripts.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": "./dist/index.js",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsup"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [],
|
|
12
|
+
"author": "Asfandyar Sheikh",
|
|
13
|
+
"license": "ISC",
|
|
14
|
+
"dependencies": {},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"tsup": "^8.5.1",
|
|
17
|
+
"typescript": "^5.9.3"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/asfandyarsheikh/nipox.git"
|
|
22
|
+
}
|
|
23
|
+
}
|