@under_koen/bsm 0.0.1 → 0.0.3

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 Koen van Staveren
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Koen van Staveren
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ #! /usr/bin/env node
2
+ "use strict";var X=Object.create;var R=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var nn=(n,i)=>()=>(i||n((i={exports:{}}).exports,i),i.exports);var en=(n,i,e,o)=>{if(i&&typeof i=="object"||typeof i=="function")for(let t of Y(i))!k.call(n,t)&&t!==e&&R(n,t,{get:()=>i[t],enumerable:!(o=Q(i,t))||o.enumerable});return n};var P=(n,i,e)=>(e=n!=null?X(V(n)):{},en(i||!n||!n.__esModule?R(e,"default",{value:n,enumerable:!0}):e,n));var W=nn((pn,U)=>{"use strict";function on(n,i){var e=n;i.slice(0,-1).forEach(function(t){e=e[t]||{}});var o=i[i.length-1];return o in e}function K(n){return typeof n=="number"||/^0x[0-9a-f]+$/i.test(n)?!0:/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(n)}function G(n,i){return i==="constructor"&&typeof n[i]=="function"||i==="__proto__"}U.exports=function(n,i){i||(i={});var e={bools:{},strings:{},unknownFn:null};typeof i.unknown=="function"&&(e.unknownFn=i.unknown),typeof i.boolean=="boolean"&&i.boolean?e.allBools=!0:[].concat(i.boolean).filter(Boolean).forEach(function(r){e.bools[r]=!0});var o={};function t(r){return o[r].some(function(a){return e.bools[a]})}Object.keys(i.alias||{}).forEach(function(r){o[r]=[].concat(i.alias[r]),o[r].forEach(function(a){o[a]=[r].concat(o[r].filter(function(S){return a!==S}))})}),[].concat(i.string).filter(Boolean).forEach(function(r){e.strings[r]=!0,o[r]&&[].concat(o[r]).forEach(function(a){e.strings[a]=!0})});var s=i.default||{},u={_:[]};function O(r,a){return e.allBools&&/^--[^=]+$/.test(a)||e.strings[r]||e.bools[r]||o[r]}function $(r,a,S){for(var c=r,A=0;A<a.length-1;A++){var v=a[A];if(G(c,v))return;c[v]===void 0&&(c[v]={}),(c[v]===Object.prototype||c[v]===Number.prototype||c[v]===String.prototype)&&(c[v]={}),c[v]===Array.prototype&&(c[v]=[]),c=c[v]}var g=a[a.length-1];G(c,g)||((c===Object.prototype||c===Number.prototype||c===String.prototype)&&(c={}),c===Array.prototype&&(c=[]),c[g]===void 0||e.bools[g]||typeof c[g]=="boolean"?c[g]=S:Array.isArray(c[g])?c[g].push(S):c[g]=[c[g],S])}function p(r,a,S){if(!(S&&e.unknownFn&&!O(r,S)&&e.unknownFn(S)===!1)){var c=!e.strings[r]&&K(a)?Number(a):a;$(u,r.split("."),c),(o[r]||[]).forEach(function(A){$(u,A.split("."),c)})}}Object.keys(e.bools).forEach(function(r){p(r,s[r]===void 0?!1:s[r])});var B=[];n.indexOf("--")!==-1&&(B=n.slice(n.indexOf("--")+1),n=n.slice(0,n.indexOf("--")));for(var d=0;d<n.length;d++){var f=n[d],l,w;if(/^--.+=/.test(f)){var D=f.match(/^--([^=]+)=([\s\S]*)$/);l=D[1];var x=D[2];e.bools[l]&&(x=x!=="false"),p(l,x,f)}else if(/^--no-.+/.test(f))l=f.match(/^--no-(.+)/)[1],p(l,!1,f);else if(/^--.+/.test(f))l=f.match(/^--(.+)/)[1],w=n[d+1],w!==void 0&&!/^(-|--)[^-]/.test(w)&&!e.bools[l]&&!e.allBools&&(!o[l]||!t(l))?(p(l,w,f),d+=1):/^(true|false)$/.test(w)?(p(l,w==="true",f),d+=1):p(l,e.strings[l]?"":!0,f);else if(/^-[^-]+/.test(f)){for(var m=f.slice(1,-1).split(""),E=!1,b=0;b<m.length;b++){if(w=f.slice(b+2),w==="-"){p(m[b],w,f);continue}if(/[A-Za-z]/.test(m[b])&&w[0]==="="){p(m[b],w.slice(1),f),E=!0;break}if(/[A-Za-z]/.test(m[b])&&/-?\d+(\.\d*)?(e-?\d+)?$/.test(w)){p(m[b],w,f),E=!0;break}if(m[b+1]&&m[b+1].match(/\W/)){p(m[b],f.slice(b+2),f),E=!0;break}else p(m[b],e.strings[m[b]]?"":!0,f)}l=f.slice(-1)[0],!E&&l!=="-"&&(n[d+1]&&!/^(-|--)[^-]/.test(n[d+1])&&!e.bools[l]&&(!o[l]||!t(l))?(p(l,n[d+1],f),d+=1):n[d+1]&&/^(true|false)$/.test(n[d+1])?(p(l,n[d+1]==="true",f),d+=1):p(l,e.strings[l]?"":!0,f))}else if((!e.unknownFn||e.unknownFn(f)!==!1)&&u._.push(e.strings._||!K(f)?f:Number(f)),i.stopEarly){u._.push.apply(u._,n.slice(d+1));break}}return Object.keys(s).forEach(function(r){on(u,r.split("."))||($(u,r.split("."),s[r]),(o[r]||[]).forEach(function(a){$(u,a.split("."),s[r])}))}),i["--"]?u["--"]=B.slice():B.forEach(function(r){u._.push(r)}),u}});var z=P(W());function y(n){return n!==null&&typeof n=="object"}function j(n,i,e=".",o){if(!y(i))return j(n,{},e,o);let t=Object.assign({},i);for(let s in n){if(s==="__proto__"||s==="constructor")continue;let u=n[s];u!=null&&(o&&o(t,s,u,e)||(Array.isArray(u)&&Array.isArray(t[s])?t[s]=[...u,...t[s]]:y(u)&&y(t[s])?t[s]=j(u,t[s],(e?`${e}.`:"")+s.toString(),o):t[s]=u))}return t}function N(n){return(...i)=>i.reduce((e,o)=>j(e,o,"",n),{})}var I=N(),bn=N((n,i,e)=>{if(typeof n[i]<"u"&&typeof e=="function")return n[i]=e(n[i]),!0}),wn=N((n,i,e)=>{if(Array.isArray(n[i])&&typeof e=="function")return n[i]=e(n[i]),!0});var J=P(require("node:child_process")),C=P(require("node:fs")),F=P(require("path")),h=(0,z.default)(process.argv.slice(2),{"--":!0}),L=h.config?[h.config]:[process.env.BSM_CONFIG,"./package.scripts.js","./package.scripts.json"],{config:M,file:rn}=L.reduce((n,i)=>{if(n||!i)return n;let e=Z(i);if(e)return{config:e,file:i}},void 0)??{};process.env.BSM_CONFIG=rn;var q={scripts:{},config:{allowFunction:!1}};function Z(n){if(n)try{n=require.resolve(n,{paths:[process.cwd()]});let i=require(n);if(Object.hasOwn(i,"extends")&&i.extends){let e=[];for(let o of i.extends){let t=Z(o);t?e.push(t):(console.error(`\x1B[31mCannot find config '${o}' to extend\x1B[0m`),process.exit(1))}return I(i,...e,q)}else return I(i,q)}catch(i){if(i.code==="MODULE_NOT_FOUND")return;console.error(`\x1B[31mError loading config '${n}'\x1B[0m`),console.error(i),process.exit(1)}}async function tn(){M||(console.error(`\x1B[31mCannot find config ${L.filter(n=>n!==void 0).map(n=>`'${n}'`).join(" or ")}\x1B[0m`),process.exit(1)),sn(process.env,await fn());for(let n of h._){if(n.startsWith("~")&&process.env.BSM_PATH){let i=process.env.BSM_PATH.split("."),e=H(M.scripts,i);if(e){await _(e,n.split(".").splice(1),i);continue}}await _(M.scripts,n.split("."))}}function sn(n,i){if(i)if(process.platform==="win32"){if(!process.env.Path||process.env.Path.includes(i))return;n.Path=`${process.env.Path};${i}`}else{if(!process.env.PATH||process.env.PATH.includes(i))return;n.PATH=`${process.env.PATH}:${i}`}}async function fn(){let n=process.cwd();for(;await C.promises.access(F.default.join(n,"node_modules/.bin"),C.constants.X_OK).then(()=>!1,()=>!0);){let i=F.default.join(n,"../");if(i===n)return null;n=i}return F.default.join(n,"node_modules/.bin")}function H(n,i){if(i.length===0)return n;let e=i[0];if(typeof n=="object"&&Object.hasOwn(n,e))if(Array.isArray(n)){let o=parseInt(e);return H(n[o],i.slice(1))}else return H(n[e],i.slice(1))}async function _(n,i,e=[],o=!0){try{if(typeof n=="function"){let s=await un(n,i,e);if(!s&&i.length===0)return;await _(s??{},i,e,o);return}await T(n,["_pre"],e,!1,!0);let t=i.slice(1);if(i.length===0)await ln(n,e,o);else if(i[0]==="*")await cn(n,t,e);else if(!await T(n,i,e))return console.error(`\x1B[31mScript '${[...e,...i].join(".")}' not found\x1B[0m`),process.exit(127);await T(n,["_post"],e,!1,!0)}catch(t){if(process.env.BSM_ERROR=t.code.toString(),await T(n,["_onError"],e,!1,!0),!await T(n,["_catch"],e,!1))throw t}finally{await T(n,["_finally"],e,!1,!0)}}async function cn(n,i,e){if(typeof n=="string")await _(n,i,e);else if(typeof n=="function")process.exit(100);else if(Array.isArray(n))for(let o=0;o<n.length;o++)await _(n[o],i,[...e,o.toString()]);else for(let o in n)o.startsWith("_")||Object.hasOwn(n,o)&&await _(n[o],i,[...e,o])}async function un(n,i,e){return console.log(`> \x1B[93mExecuting JavaScript function\x1B[0m \x1B[90m(${[...e].join(".")})\x1B[0m`),await n.call(null,h["--"])}async function T(n,i,e,o=!0,t=!1){if(t&&process.env.BSM_SCRIPT===[...e,...i].join("."))return!1;let s=i[0];if(typeof n!="object"||!Object.hasOwn(n,s))return!1;if(Array.isArray(n)){let u=parseInt(s);await _(n[u],i.slice(1),[...e,s],o)}else await _(n[s],i.slice(1),[...e,s],o);return!0}async function ln(n,i,e){switch(typeof n){case"string":await an(n,i,e);return;case"object":if(Array.isArray(n))for(let o=0;o<n.length;o++)await _(n[o],[],[...i,o.toString()]);else if(!await T(n,[`_${process.platform}`],i)){if(!await T(n,["_default"],i))return console.error(`\x1B[31mScript '${[...i].join(".")}' is not executable\x1B[0m`),process.exit(127)}return}}async function an(n,i,e){var o;if(e&&((o=h["--"])!=null&&o.length)&&(n+=" "+h["--"].join(" ")),console.log(`> ${n} \x1B[90m(${i.join(".")})\x1B[0m`),n!=="")return await new Promise((t,s)=>{J.default.spawn(n,[],{stdio:"inherit",shell:!0,env:{...process.env,BSM_PATH:i.slice(0,-1).join("."),BSM_SCRIPT:i.join(".")}}).on("close",O=>{O===0?t():s({code:O,script:i.join(".")})})})}tn().catch(n=>{console.error(`\x1B[31mScript failed with code ${n.code}\x1B[0m \x1B[90m(${n.script})\x1B[0m`),process.exit(n.code)});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@under_koen/bsm",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "BSM (Basic Script Manager) is a useful tool that enables you to create clear and concise scripts without cluttering your `package.json` file.",
5
5
  "license": "MIT",
6
6
  "author": "Koen van Staveren <koen@underkoen.nl>",
@@ -20,23 +20,29 @@
20
20
  "dist"
21
21
  ],
22
22
  "scripts": {
23
- "build": "esbuild src/index.ts --bundle --minify --platform=node --target=node16 --outfile=dist/index.js",
23
+ "build": "bsm build",
24
+ "build:dev": "bsm build.dev",
25
+ "build:watch": "bsm build.watch",
24
26
  "prettier": "bsm prettier",
25
- "watch": "npm run build -- --watch"
26
- },
27
- "dependencies": {
28
- "minimist": "^1.2.8"
27
+ "prepublishOnly": "bsm build.prod"
29
28
  },
30
29
  "devDependencies": {
30
+ "@types/minimist": "^1.2.2",
31
31
  "@types/node": "^18.16.3",
32
32
  "@typescript-eslint/eslint-plugin": "^5.59.2",
33
33
  "@typescript-eslint/parser": "^5.59.2",
34
+ "@under_koen/bsm": "^0.0.2",
35
+ "defu": "^6.1.2",
34
36
  "esbuild": "0.17.18",
35
37
  "eslint": "^8.39.0",
36
38
  "eslint-config-prettier": "^8.8.0",
39
+ "minimist": "^1.2.8",
37
40
  "prettier": "2.8.8",
38
41
  "prettier-package-json": "^2.8.0",
39
42
  "typescript": "^5.0.4"
40
43
  },
41
- "keywords": ["script", "scripting"]
44
+ "keywords": [
45
+ "script",
46
+ "scripting"
47
+ ]
42
48
  }
package/dist/bin/bsm.js DELETED
@@ -1,2 +0,0 @@
1
- #! /usr/bin/env node
2
- "use strict";var K=(n,i)=>()=>(i||n((i={exports:{}}).exports,i),i.exports);var q=K((L,g)=>{"use strict";function z(n,i){var t=n;i.slice(0,-1).forEach(function(a){t=t[a]||{}});var f=i[i.length-1];return f in t}function B(n){return typeof n=="number"||/^0x[0-9a-f]+$/i.test(n)?!0:/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(n)}function P(n,i){return i==="constructor"&&typeof n[i]=="function"||i==="__proto__"}g.exports=function(n,i){i||(i={});var t={bools:{},strings:{},unknownFn:null};typeof i.unknown=="function"&&(t.unknownFn=i.unknown),typeof i.boolean=="boolean"&&i.boolean?t.allBools=!0:[].concat(i.boolean).filter(Boolean).forEach(function(o){t.bools[o]=!0});var f={};function a(o){return f[o].some(function(u){return t.bools[u]})}Object.keys(i.alias||{}).forEach(function(o){f[o]=[].concat(i.alias[o]),f[o].forEach(function(u){f[u]=[o].concat(f[o].filter(function(m){return u!==m}))})}),[].concat(i.string).filter(Boolean).forEach(function(o){t.strings[o]=!0,f[o]&&[].concat(f[o]).forEach(function(u){t.strings[u]=!0})});var s=i.default||{},h={_:[]};function C(o,u){return t.allBools&&/^--[^=]+$/.test(u)||t.strings[o]||t.bools[o]||f[o]}function A(o,u,m){for(var e=o,O=0;O<u.length-1;O++){var v=u[O];if(P(e,v))return;e[v]===void 0&&(e[v]={}),(e[v]===Object.prototype||e[v]===Number.prototype||e[v]===String.prototype)&&(e[v]={}),e[v]===Array.prototype&&(e[v]=[]),e=e[v]}var S=u[u.length-1];P(e,S)||((e===Object.prototype||e===Number.prototype||e===String.prototype)&&(e={}),e===Array.prototype&&(e=[]),e[S]===void 0||t.bools[S]||typeof e[S]=="boolean"?e[S]=m:Array.isArray(e[S])?e[S].push(m):e[S]=[e[S],m])}function p(o,u,m){if(!(m&&t.unknownFn&&!C(o,m)&&t.unknownFn(m)===!1)){var e=!t.strings[o]&&B(u)?Number(u):u;A(h,o.split("."),e),(f[o]||[]).forEach(function(O){A(h,O.split("."),e)})}}Object.keys(t.bools).forEach(function(o){p(o,s[o]===void 0?!1:s[o])});var E=[];n.indexOf("--")!==-1&&(E=n.slice(n.indexOf("--")+1),n=n.slice(0,n.indexOf("--")));for(var l=0;l<n.length;l++){var r=n[l],c,d;if(/^--.+=/.test(r)){var N=r.match(/^--([^=]+)=([\s\S]*)$/);c=N[1];var T=N[2];t.bools[c]&&(T=T!=="false"),p(c,T,r)}else if(/^--no-.+/.test(r))c=r.match(/^--no-(.+)/)[1],p(c,!1,r);else if(/^--.+/.test(r))c=r.match(/^--(.+)/)[1],d=n[l+1],d!==void 0&&!/^(-|--)[^-]/.test(d)&&!t.bools[c]&&!t.allBools&&(!f[c]||!a(c))?(p(c,d,r),l+=1):/^(true|false)$/.test(d)?(p(c,d==="true",r),l+=1):p(c,t.strings[c]?"":!0,r);else if(/^-[^-]+/.test(r)){for(var w=r.slice(1,-1).split(""),$=!1,b=0;b<w.length;b++){if(d=r.slice(b+2),d==="-"){p(w[b],d,r);continue}if(/[A-Za-z]/.test(w[b])&&d[0]==="="){p(w[b],d.slice(1),r),$=!0;break}if(/[A-Za-z]/.test(w[b])&&/-?\d+(\.\d*)?(e-?\d+)?$/.test(d)){p(w[b],d,r),$=!0;break}if(w[b+1]&&w[b+1].match(/\W/)){p(w[b],r.slice(b+2),r),$=!0;break}else p(w[b],t.strings[w[b]]?"":!0,r)}c=r.slice(-1)[0],!$&&c!=="-"&&(n[l+1]&&!/^(-|--)[^-]/.test(n[l+1])&&!t.bools[c]&&(!f[c]||!a(c))?(p(c,n[l+1],r),l+=1):n[l+1]&&/^(true|false)$/.test(n[l+1])?(p(c,n[l+1]==="true",r),l+=1):p(c,t.strings[c]?"":!0,r))}else if((!t.unknownFn||t.unknownFn(r)!==!1)&&h._.push(t.strings._||!B(r)?r:Number(r)),i.stopEarly){h._.push.apply(h._,n.slice(l+1));break}}return Object.keys(s).forEach(function(o){z(h,o.split("."))||(A(h,o.split("."),s[o]),(f[o]||[]).forEach(function(u){A(h,u.split("."),s[o])}))}),i["--"]?h["--"]=E.slice():E.forEach(function(o){h._.push(o)}),h}});var I=q()(process.argv.slice(2),{"--":!0}),W=require("path"),Z=require(W.join(process.cwd(),"package.scripts.js")),j=require("node:child_process"),D=Z.scripts;async function _(n,i,t=[]){if(i===""){await F(n,t);return}else if(typeof n=="object"){let f=i.split(".",2)[0],a=i.substring(f.length+1);if(f==="*"){if(Array.isArray(n))for(let s=0;s<n.length;s++)await _(n[s],a,[...t,s.toString()]);else for(let s in n)s.startsWith("_")||Object.hasOwn(n,s)&&await _(n[s],a,[...t,s]);return}if(Array.isArray(n)){let s=parseInt(f);if(!isNaN(s)&&n[s])return await _(n[s],a,[...t,f])}else if(Object.hasOwn(n,f))return await _(n[f],a,[...t,f])}console.error(`\x1B[31mScript '${t.join(".")}.${i}' not found\x1B[0m`)}async function F(n,i){switch(typeof n){case"string":await G(n,i);return;case"object":if(Array.isArray(n))for(let t=0;t<n.length;t++)await F(n[t],[...i,t.toString()]);else Object.hasOwn(n,"_default")&&await F(n._default,i);return}}async function G(n,i){return new Promise((t,f)=>{console.log(`> ${n} \x1B[90m(${i.join(".")})\x1B[0m`);let a=j.exec(n);a.stdout.on("data",s=>{console.log(s.toString().replace(/\n$/,""))}),a.stderr.on("data",s=>{console.error(s.toString().replace(/\n$/,""))}),process.stdin.pipe(a.stdin),a.on("close",s=>{s===0?t():f()})})}async function H(){for(let n of I._)await _(D,n)}H().catch(()=>{process.exit(1)});