@under_koen/bsm 0.0.3 → 0.0.5

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.
Files changed (3) hide show
  1. package/README.md +486 -8
  2. package/dist/index.js +1 -1
  3. package/package.json +9 -8
package/README.md CHANGED
@@ -3,23 +3,501 @@
3
3
  BSM is a tool that enhances the functionality of NPM by allowing users to define their scripts in a separate files. This
4
4
  makes it easier to create and manage complex scripts using JavaScript, without cluttering your `package.json` file.
5
5
 
6
+ ## Getting started
7
+
8
+ ### Installation
9
+
10
+ Install BSM as a dev dependency or globally.
11
+
12
+ ```bash
13
+ npm install --save-dev bsm
14
+ ```
15
+
16
+ ```bash
17
+ npm install -g bsm
18
+ ```
19
+
20
+ ### Usage
21
+
22
+ Create a `package.scripts.js` or `package.scripts.json` file in the root of your project. This file will contain all of
23
+ your scripts.
24
+
25
+ When using `package.scripts.js`, you can use the following syntax:
26
+
27
+ ```javascript
28
+ module.exports = {
29
+ scripts: {
30
+ build: {
31
+ _default: "bsm clean ~.* --",
32
+ esbuild: "esbuild ...",
33
+ },
34
+ clean: "rimraf dist/",
35
+ lint: {
36
+ _default: "bsm ~.* --",
37
+ eslint: "eslint --ext .ts,.js .",
38
+ prettier: "prettier --check .",
39
+ },
40
+ },
41
+ };
42
+ ```
43
+
44
+ When using `package.scripts.json`, you can use the following syntax:
45
+
46
+ ```json
47
+ {
48
+ "scripts": {
49
+ "build": {
50
+ "_default": "bsm clean ~.*",
51
+ "esbuild": "esbuild ..."
52
+ },
53
+ "clean": "rimraf dist/",
54
+ "lint": {
55
+ "_default": "bsm ~.*",
56
+ "eslint": "eslint --ext .ts,.js .",
57
+ "prettier": "prettier --check ."
58
+ }
59
+ }
60
+ }
61
+ ```
62
+
63
+ You can then run your scripts using the `bsm` command.
64
+
65
+ ```bash
66
+ bsm build
67
+ ```
68
+
69
+ ```bash
70
+ bsm lint
71
+ ```
72
+
73
+ You can also run sub-scripts.
74
+
75
+ ```bash
76
+ bsm lint.eslint
77
+ ```
78
+
6
79
  ## Features
7
80
 
8
- [//]: # "TODO Write features"
81
+ ### Script groups
9
82
 
10
- - ...
83
+ You can group scripts by using an object or array.
11
84
 
12
- ## Getting started
85
+ ```javascript
86
+ module.exports = {
87
+ scripts: {
88
+ example: {
89
+ test: "echo test script",
90
+ variant: "echo variant script",
91
+ subgroups: {
92
+ test: "echo test script",
93
+ variant: "echo variant script",
94
+ },
95
+ },
96
+ },
97
+ };
98
+ ```
99
+
100
+ In this example the following scripts are available:
101
+ - `bsm example.test`
102
+ - `bsm example.variant`
103
+ - `bsm example.subgroups.test`
104
+ - `bsm example.subgroups.variant`
105
+
106
+ ```javascript
107
+ module.exports = {
108
+ scripts: {
109
+ example: ["echo test script", "echo variant script"],
110
+ },
111
+ };
112
+ ```
113
+
114
+ In this example the following scripts are available:
115
+ - `bsm example` (will run all scripts in the array)
116
+ - `bsm example.0`
117
+ - `bsm example.1`
118
+
119
+ ### Default scripts
120
+
121
+ You can define a default script for a group of scripts by using the `_default` key.
122
+
123
+ ```javascript
124
+ module.exports = {
125
+ scripts: {
126
+ example: {
127
+ _default: "echo default script",
128
+ variant: "echo variant script",
129
+ },
130
+ },
131
+ };
132
+ ```
133
+
134
+ `bsm example` will execute the default script, while `bsm example.variant` will execute the variant script.
135
+
136
+ ### Specified scripts
137
+
138
+ Specified scripts replace the default script when an condition is met.
139
+
140
+ The order of precedence is as follows:
141
+ - _ci
142
+ - _[os]
143
+ - _default
13
144
 
14
- To get started with BSM, simply install it as an NPM package and create a `package.scripts.js` file in your project
15
- directory. Then, define your scripts in that file using JavaScript. You can execute your scripts using `bsm <script>`.
145
+ #### CI Specified scripts
16
146
 
147
+ You can specify CI specific scripts with `_ci` key.
148
+
149
+ ```javascript
150
+ module.exports = {
151
+ scripts: {
152
+ example: {
153
+ _default: "echo default script",
154
+ _ci: "echo ci script",
155
+ },
156
+ },
157
+ };
158
+ ```
159
+
160
+ `bsm example` will execute the `example._ci` when running on a CI environment. When no CI specific script is found, the
161
+ default script will be executed.
162
+
163
+ #### OS Specified scripts
164
+
165
+ You can specify OS specific scripts with `_win32`, `_darwin`, and `_linux` keys.
166
+ All platforms can be seen [here](https://nodejs.org/api/os.html#os_os_platform).
167
+
168
+ ```javascript
169
+ module.exports = {
170
+ scripts: {
171
+ example: {
172
+ _default: "echo default script",
173
+ _win32: "echo windows script",
174
+ _darwin: "echo macos script",
175
+ _linux: "echo linux script",
176
+ },
177
+ },
178
+ };
179
+ ```
180
+
181
+ `bsm example` will execute the `example._win32` on Windows, `example._darwin` on MacOS, and `example._linux` on Linux.
182
+ When no OS specific script is found, the default script will be executed.
183
+
184
+ ### Script arguments
185
+
186
+ All arguments passed to the `bsm` command after `--` will be passed to all specified scripts.
187
+
188
+ ```javascript
189
+ module.exports = {
190
+ scripts: {
191
+ example: "echo",
192
+ },
193
+ };
194
+ ```
195
+
196
+ ```bash
197
+ bsm example -- Hello World!
198
+ ```
199
+
200
+ The above command will execute `echo Hello World!`.
201
+
202
+ ### Relative scripts
203
+
204
+ You can run scripts relative to the current script by using the `~` prefix.
205
+
206
+ ```javascript
207
+ module.exports = {
208
+ scripts: {
209
+ example: {
210
+ _default: "bsm ~.variant",
211
+ variant: "echo variant script",
212
+ },
213
+ },
214
+ };
215
+ ```
216
+
217
+ ```bash
218
+ bsm example
219
+ ```
220
+
221
+ The above command will execute `example.variant`.
222
+
223
+ ### All scripts
224
+
225
+ You can run all scripts in a group by using a `*`.
226
+ Ignores scripts that start with `_`.
227
+
228
+ ```javascript
229
+ module.exports = {
230
+ scripts: {
231
+ example: {
232
+ test: "echo test script",
233
+ variant: "echo variant script",
234
+ _ignore: "echo ignore script",
235
+ },
236
+ },
237
+ };
17
238
  ```
18
- npm install bsm --save-dev
239
+
240
+ ```bash
241
+ bsm example.*
19
242
  ```
20
243
 
21
- For more information and examples, please see the documentation on
22
- the [BSM GitHub page](https://github.com/example/bsm).
244
+ The above command will execute `example.test` and `example.variant`.
245
+
246
+ ### Hooks
247
+
248
+ #### Pre hooks
249
+
250
+ You can run scripts before a script by using `_pre`.
251
+
252
+ ```javascript
253
+ module.exports = {
254
+ scripts: {
255
+ example: {
256
+ _pre: "echo pre script",
257
+ _default: "echo default script",
258
+ },
259
+ },
260
+ };
261
+ ```
262
+
263
+ ```bash
264
+ bsm example
265
+ ```
266
+
267
+ The above command will execute `example._pre` and `example._default`.
268
+
269
+ #### Post hooks
270
+
271
+ You can run scripts after a script by using `_post`.
272
+ Does not run when a script fails.
273
+
274
+ ```javascript
275
+ module.exports = {
276
+ scripts: {
277
+ example: {
278
+ _default: "echo default script",
279
+ _post: "echo post script",
280
+ },
281
+ },
282
+ };
283
+ ```
284
+
285
+ ```bash
286
+ bsm example
287
+ ```
288
+
289
+ The above command will execute `example._default` and `example._post`.
290
+
291
+ #### On error hooks
292
+
293
+ You can run scripts when a script fails by using `_onError`.
294
+
295
+ ```javascript
296
+ module.exports = {
297
+ scripts: {
298
+ example: {
299
+ _default: "exit 1",
300
+ _onError: "echo error script",
301
+ },
302
+ },
303
+ };
304
+ ```
305
+
306
+ ```bash
307
+ bsm example
308
+ ```
309
+
310
+ The above command will execute `example._default` and `example._onError`.
311
+ This will also exit with code `1`.
312
+
313
+ #### Catch hooks
314
+
315
+ You can run scripts when a script fails by using `_catch`.
316
+
317
+ ```javascript
318
+ module.exports = {
319
+ scripts: {
320
+ example: {
321
+ _default: "exit 1",
322
+ _catch: "echo catch script",
323
+ },
324
+ },
325
+ };
326
+ ```
327
+
328
+ ```bash
329
+ bsm example
330
+ ```
331
+
332
+ The above command will execute `example._default` and `example._catch`.
333
+
334
+ #### Finally hooks
335
+
336
+ You can run scripts when a script fails by using `_finally`.
337
+
338
+ ```javascript
339
+ module.exports = {
340
+ scripts: {
341
+ example: {
342
+ _default: "echo default script",
343
+ error: "exit 1",
344
+ _finally: "echo finally script",
345
+ },
346
+ },
347
+ };
348
+ ```
349
+
350
+ ```bash
351
+ bsm example
352
+ ```
353
+
354
+ The above command will execute `example._default` and `example._finally`.
355
+
356
+ ```bash
357
+ bsm example.error
358
+ ```
359
+
360
+ The above command will execute `example.error` and `example._finally`.
361
+ And exit with code `1`.
362
+
363
+ ### Functions
364
+
365
+ You can use functions in your scripts. This only work in javascript files.
366
+
367
+ ```javascript
368
+ module.exports = {
369
+ scripts: {
370
+ example: () => {
371
+ console.log("Hello World!");
372
+ },
373
+ },
374
+ };
375
+ ```
376
+
377
+ ```bash
378
+ bsm example
379
+ ```
380
+
381
+ The above command will execute the function and log `Hello World!`.
382
+
383
+ #### Async functions
384
+
385
+ You can use async functions in your scripts. This only work in javascript files.
386
+
387
+ ```javascript
388
+ import { setTimeout } from "timers/promises";
389
+
390
+ module.exports = {
391
+ scripts: {
392
+ example: async () => {
393
+ await setTimeout(5000);
394
+ console.log("Hello World!");
395
+ },
396
+ },
397
+ };
398
+ ```
399
+
400
+ ```bash
401
+ bsm example
402
+ ```
403
+
404
+ The above command will execute the function and log `Hello World!` after 5 seconds.
405
+
406
+ #### Arguments
407
+
408
+ The function is passed an array of all arguments passed to the script after `--`.
409
+
410
+ ```javascript
411
+ module.exports = {
412
+ scripts: {
413
+ example: (args) => {
414
+ console.log(args);
415
+ },
416
+ },
417
+ };
418
+ ```
419
+
420
+ ```bash
421
+ bsm example -- Hello World!
422
+ ```
423
+
424
+ The above command will execute the function and log `["Hello", "World!"]`.
425
+
426
+ #### Return value
427
+
428
+ The function can return scripts, these will handled as if function was not used.
429
+ Return value can be a string, an array, an object or another function.
430
+
431
+ ```javascript
432
+ module.exports = {
433
+ scripts: {
434
+ example: () => {
435
+ return "echo Hello World!";
436
+ },
437
+ },
438
+ };
439
+ ```
440
+
441
+ ```bash
442
+ bsm example
443
+ ```
444
+
445
+ The above command will execute `echo Hello World!`.
446
+
447
+ ### Extending
448
+
449
+ You can extend scripts by using the `extends` key. You can import scripts from other files or packages.
450
+
451
+ ```javascript
452
+ module.exports = {
453
+ extends: ['@under_koen/bsm/package.scripts.js'],
454
+ scripts: {},
455
+ }
456
+ ```
457
+
458
+ ```bash
459
+ bsm lint
460
+ ```
461
+
462
+ The above command will execute `lint` coming from the `package.scripts.js` of `@under_koen/bsm`.
463
+
464
+ #### Extending with options (experimental)
465
+
466
+ You can extend scripts with options by using the `extends` key. You can import scripts from other files or packages.
467
+
468
+ ```javascript
469
+ // package.scripts.js
470
+ module.exports = {
471
+ extends: [
472
+ ['./test', "World"]
473
+ ],
474
+ scripts: {},
475
+ }
476
+ ```
477
+
478
+ ```javascript
479
+ // test.js
480
+
481
+ module.exports = (name) => ({
482
+ scripts: {
483
+ test: `echo Hello ${name}!`,
484
+ },
485
+ });
486
+ ```
487
+
488
+ ```bash
489
+ bsm test
490
+ ```
491
+
492
+ The above command will execute `echo Hello World!`.
493
+
494
+ ## Future plans
495
+
496
+ - [ ] Have support for workspaces / lerna
497
+ - [ ] Have support for running scripts in parallel
498
+ - [ ] Have support for specifying environment variables
499
+ - [ ] Have support for an interactive mode
500
+ - [ ] Jetbrains and VSCode integration
23
501
 
24
502
  ## License
25
503
 
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
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)});
2
+ "use strict";var on=Object.create;var y=Object.defineProperty;var sn=Object.getOwnPropertyDescriptor;var cn=Object.getOwnPropertyNames;var an=Object.getPrototypeOf,fn=Object.prototype.hasOwnProperty;var h=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports);var V=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of cn(e))!fn.call(n,i)&&i!==t&&y(n,i,{get:()=>e[i],enumerable:!(r=sn(e,i))||r.enumerable});return n};var P=(n,e,t)=>(t=n!=null?on(an(n)):{},V(e||!n||!n.__esModule?y(t,"default",{value:n,enumerable:!0}):t,n)),un=n=>V(y({},"__esModule",{value:!0}),n);var j=h((vn,W)=>{"use strict";function ln(n,e){var t=n;e.slice(0,-1).forEach(function(i){t=t[i]||{}});var r=e[e.length-1];return r in t}function K(n){return typeof n=="number"||/^0x[0-9a-f]+$/i.test(n)?!0:/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(n)}function Y(n,e){return e==="constructor"&&typeof n[e]=="function"||e==="__proto__"}W.exports=function(n,e){e||(e={});var t={bools:{},strings:{},unknownFn:null};typeof e.unknown=="function"&&(t.unknownFn=e.unknown),typeof e.boolean=="boolean"&&e.boolean?t.allBools=!0:[].concat(e.boolean).filter(Boolean).forEach(function(o){t.bools[o]=!0});var r={};function i(o){return r[o].some(function(l){return t.bools[l]})}Object.keys(e.alias||{}).forEach(function(o){r[o]=[].concat(e.alias[o]),r[o].forEach(function(l){r[l]=[o].concat(r[o].filter(function(d){return l!==d}))})}),[].concat(e.string).filter(Boolean).forEach(function(o){t.strings[o]=!0,r[o]&&[].concat(r[o]).forEach(function(l){t.strings[l]=!0})});var c=e.default||{},s={_:[]};function A(o,l){return t.allBools&&/^--[^=]+$/.test(l)||t.strings[o]||t.bools[o]||r[o]}function O(o,l,d){for(var f=o,D=0;D<l.length-1;D++){var T=l[D];if(Y(f,T))return;f[T]===void 0&&(f[T]={}),(f[T]===Object.prototype||f[T]===Number.prototype||f[T]===String.prototype)&&(f[T]={}),f[T]===Array.prototype&&(f[T]=[]),f=f[T]}var m=l[l.length-1];Y(f,m)||((f===Object.prototype||f===Number.prototype||f===String.prototype)&&(f={}),f===Array.prototype&&(f=[]),f[m]===void 0||t.bools[m]||typeof f[m]=="boolean"?f[m]=d:Array.isArray(f[m])?f[m].push(d):f[m]=[f[m],d])}function I(o,l,d){if(!(d&&t.unknownFn&&!A(o,d)&&t.unknownFn(d)===!1)){var f=!t.strings[o]&&K(l)?Number(l):l;O(s,o.split("."),f),(r[o]||[]).forEach(function(D){O(s,D.split("."),f)})}}Object.keys(t.bools).forEach(function(o){I(o,c[o]===void 0?!1:c[o])});var w=[];n.indexOf("--")!==-1&&(w=n.slice(n.indexOf("--")+1),n=n.slice(0,n.indexOf("--")));for(var _=0;_<n.length;_++){var a=n[_],u,p;if(/^--.+=/.test(a)){var Q=a.match(/^--([^=]+)=([\s\S]*)$/);u=Q[1];var g=Q[2];t.bools[u]&&(g=g!=="false"),I(u,g,a)}else if(/^--no-.+/.test(a))u=a.match(/^--no-(.+)/)[1],I(u,!1,a);else if(/^--.+/.test(a))u=a.match(/^--(.+)/)[1],p=n[_+1],p!==void 0&&!/^(-|--)[^-]/.test(p)&&!t.bools[u]&&!t.allBools&&(!r[u]||!i(u))?(I(u,p,a),_+=1):/^(true|false)$/.test(p)?(I(u,p==="true",a),_+=1):I(u,t.strings[u]?"":!0,a);else if(/^-[^-]+/.test(a)){for(var R=a.slice(1,-1).split(""),B=!1,S=0;S<R.length;S++){if(p=a.slice(S+2),p==="-"){I(R[S],p,a);continue}if(/[A-Za-z]/.test(R[S])&&p[0]==="="){I(R[S],p.slice(1),a),B=!0;break}if(/[A-Za-z]/.test(R[S])&&/-?\d+(\.\d*)?(e-?\d+)?$/.test(p)){I(R[S],p,a),B=!0;break}if(R[S+1]&&R[S+1].match(/\W/)){I(R[S],a.slice(S+2),a),B=!0;break}else I(R[S],t.strings[R[S]]?"":!0,a)}u=a.slice(-1)[0],!B&&u!=="-"&&(n[_+1]&&!/^(-|--)[^-]/.test(n[_+1])&&!t.bools[u]&&(!r[u]||!i(u))?(I(u,n[_+1],a),_+=1):n[_+1]&&/^(true|false)$/.test(n[_+1])?(I(u,n[_+1]==="true",a),_+=1):I(u,t.strings[u]?"":!0,a))}else if((!t.unknownFn||t.unknownFn(a)!==!1)&&s._.push(t.strings._||!K(a)?a:Number(a)),e.stopEarly){s._.push.apply(s._,n.slice(_+1));break}}return Object.keys(c).forEach(function(o){ln(s,o.split("."))||(O(s,o.split("."),c[o]),(r[o]||[]).forEach(function(l){O(s,l.split("."),c[o])}))}),e["--"]?s["--"]=w.slice():w.forEach(function(o){s._.push(o)}),s}});var X=h((Pn,En)=>{En.exports=[{name:"Appcircle",constant:"APPCIRCLE",env:"AC_APPCIRCLE"},{name:"AppVeyor",constant:"APPVEYOR",env:"APPVEYOR",pr:"APPVEYOR_PULL_REQUEST_NUMBER"},{name:"AWS CodeBuild",constant:"CODEBUILD",env:"CODEBUILD_BUILD_ARN"},{name:"Azure Pipelines",constant:"AZURE_PIPELINES",env:"SYSTEM_TEAMFOUNDATIONCOLLECTIONURI",pr:"SYSTEM_PULLREQUEST_PULLREQUESTID"},{name:"Bamboo",constant:"BAMBOO",env:"bamboo_planKey"},{name:"Bitbucket Pipelines",constant:"BITBUCKET",env:"BITBUCKET_COMMIT",pr:"BITBUCKET_PR_ID"},{name:"Bitrise",constant:"BITRISE",env:"BITRISE_IO",pr:"BITRISE_PULL_REQUEST"},{name:"Buddy",constant:"BUDDY",env:"BUDDY_WORKSPACE_ID",pr:"BUDDY_EXECUTION_PULL_REQUEST_ID"},{name:"Buildkite",constant:"BUILDKITE",env:"BUILDKITE",pr:{env:"BUILDKITE_PULL_REQUEST",ne:"false"}},{name:"CircleCI",constant:"CIRCLE",env:"CIRCLECI",pr:"CIRCLE_PULL_REQUEST"},{name:"Cirrus CI",constant:"CIRRUS",env:"CIRRUS_CI",pr:"CIRRUS_PR"},{name:"Codefresh",constant:"CODEFRESH",env:"CF_BUILD_ID",pr:{any:["CF_PULL_REQUEST_NUMBER","CF_PULL_REQUEST_ID"]}},{name:"Codemagic",constant:"CODEMAGIC",env:"CM_BUILD_ID",pr:"CM_PULL_REQUEST"},{name:"Codeship",constant:"CODESHIP",env:{CI_NAME:"codeship"}},{name:"Drone",constant:"DRONE",env:"DRONE",pr:{DRONE_BUILD_EVENT:"pull_request"}},{name:"dsari",constant:"DSARI",env:"DSARI"},{name:"Expo Application Services",constant:"EAS",env:"EAS_BUILD"},{name:"Gerrit",constant:"GERRIT",env:"GERRIT_PROJECT"},{name:"GitHub Actions",constant:"GITHUB_ACTIONS",env:"GITHUB_ACTIONS",pr:{GITHUB_EVENT_NAME:"pull_request"}},{name:"GitLab CI",constant:"GITLAB",env:"GITLAB_CI",pr:"CI_MERGE_REQUEST_ID"},{name:"GoCD",constant:"GOCD",env:"GO_PIPELINE_LABEL"},{name:"Google Cloud Build",constant:"GOOGLE_CLOUD_BUILD",env:"BUILDER_OUTPUT"},{name:"Harness CI",constant:"HARNESS",env:"HARNESS_BUILD_ID"},{name:"Heroku",constant:"HEROKU",env:{env:"NODE",includes:"/app/.heroku/node/bin/node"}},{name:"Hudson",constant:"HUDSON",env:"HUDSON_URL"},{name:"Jenkins",constant:"JENKINS",env:["JENKINS_URL","BUILD_ID"],pr:{any:["ghprbPullId","CHANGE_ID"]}},{name:"LayerCI",constant:"LAYERCI",env:"LAYERCI",pr:"LAYERCI_PULL_REQUEST"},{name:"Magnum CI",constant:"MAGNUM",env:"MAGNUM"},{name:"Netlify CI",constant:"NETLIFY",env:"NETLIFY",pr:{env:"PULL_REQUEST",ne:"false"}},{name:"Nevercode",constant:"NEVERCODE",env:"NEVERCODE",pr:{env:"NEVERCODE_PULL_REQUEST",ne:"false"}},{name:"ReleaseHub",constant:"RELEASEHUB",env:"RELEASE_BUILD_ID"},{name:"Render",constant:"RENDER",env:"RENDER",pr:{IS_PULL_REQUEST:"true"}},{name:"Sail CI",constant:"SAIL",env:"SAILCI",pr:"SAIL_PULL_REQUEST_NUMBER"},{name:"Screwdriver",constant:"SCREWDRIVER",env:"SCREWDRIVER",pr:{env:"SD_PULL_REQUEST",ne:"false"}},{name:"Semaphore",constant:"SEMAPHORE",env:"SEMAPHORE",pr:"PULL_REQUEST_NUMBER"},{name:"Shippable",constant:"SHIPPABLE",env:"SHIPPABLE",pr:{IS_PULL_REQUEST:"true"}},{name:"Solano CI",constant:"SOLANO",env:"TDDIUM",pr:"TDDIUM_PR_ID"},{name:"Sourcehut",constant:"SOURCEHUT",env:{CI_NAME:"sourcehut"}},{name:"Strider CD",constant:"STRIDER",env:"STRIDER"},{name:"TaskCluster",constant:"TASKCLUSTER",env:["TASK_ID","RUN_ID"]},{name:"TeamCity",constant:"TEAMCITY",env:"TEAMCITY_VERSION"},{name:"Travis CI",constant:"TRAVIS",env:"TRAVIS",pr:{env:"TRAVIS_PULL_REQUEST",ne:"false"}},{name:"Vercel",constant:"VERCEL",env:{any:["NOW_BUILDER","VERCEL"]}},{name:"Visual Studio App Center",constant:"APPCENTER",env:"APPCENTER_BUILD_ID"},{name:"Woodpecker",constant:"WOODPECKER",env:{CI:"woodpecker"},pr:{CI_BUILD_EVENT:"pull_request"}},{name:"Xcode Cloud",constant:"XCODE_CLOUD",env:"CI_XCODE_PROJECT",pr:"CI_PULL_REQUEST_NUMBER"},{name:"Xcode Server",constant:"XCODE_SERVER",env:"XCS"}]});var z=h(C=>{"use strict";var q=X(),E=process.env;Object.defineProperty(C,"_vendors",{value:q.map(function(n){return n.constant})});C.name=null;C.isPR=null;q.forEach(function(n){let t=(Array.isArray(n.env)?n.env:[n.env]).every(function(r){return J(r)});if(C[n.constant]=t,!!t)switch(C.name=n.name,typeof n.pr){case"string":C.isPR=!!E[n.pr];break;case"object":"env"in n.pr?C.isPR=n.pr.env in E&&E[n.pr.env]!==n.pr.ne:"any"in n.pr?C.isPR=n.pr.any.some(function(r){return!!E[r]}):C.isPR=J(n.pr);break;default:C.isPR=null}});C.isCI=!!(E.CI!=="false"&&(E.BUILD_ID||E.BUILD_NUMBER||E.CI||E.CI_APP_ID||E.CI_BUILD_ID||E.CI_BUILD_NUMBER||E.CI_NAME||E.CONTINUOUS_INTEGRATION||E.RUN_ID||C.name));function J(n){return typeof n=="string"?!!E[n]:"env"in n?E[n.env]&&E[n.env].includes(n.includes):"any"in n?n.any.some(function(e){return!!E[e]}):Object.keys(n).every(function(e){return E[e]===n[e]})}});var mn={};module.exports=un(mn);var k=P(j());function M(n){return n!==null&&typeof n=="object"}function H(n,e,t=".",r){if(!M(e))return H(n,{},t,r);let i=Object.assign({},e);for(let c in n){if(c==="__proto__"||c==="constructor")continue;let s=n[c];s!=null&&(r&&r(i,c,s,t)||(Array.isArray(s)&&Array.isArray(i[c])?i[c]=[...s,...i[c]]:M(s)&&M(i[c])?i[c]=H(s,i[c],(t?`${t}.`:"")+c.toString(),r):i[c]=s))}return i}function F(n){return(...e)=>e.reduce((t,r)=>H(t,r,"",n),{})}var G=F(),An=F((n,e,t)=>{if(typeof n[e]<"u"&&typeof t=="function")return n[e]=t(n[e]),!0}),Ln=F((n,e,t)=>{if(Array.isArray(n[e])&&typeof t=="function")return n[e]=t(n[e]),!0});var nn=P(require("node:child_process")),N=P(require("node:fs")),b=P(require("path")),en=P(z()),L=(0,k.default)(process.argv.slice(2),{"--":!0}),tn=L.config?[L.config]:[process.env.BSM_CONFIG,"./package.scripts.js","./package.scripts.json"],{config:$,file:_n}=tn.reduce((n,e)=>{if(n||!e)return n;let t=rn(e);if(t)return{config:t,file:e}},void 0)??{};process.env.BSM_CONFIG=_n;var Z={scripts:{},config:{allowFunction:!1}};function rn(n){if(n)try{let e=Array.isArray(n)?n[0]:n;e=require.resolve(e,{paths:[process.cwd()]});let t=require(e);if(typeof t=="function"&&(t=t(...Array.isArray(n)?n.slice(1):[])),Object.hasOwn(t,"extends")&&t.extends){let r=[];for(let i of t.extends){let c=rn(i);Array.isArray(i)&&(i=i[0]),c?r.push(c):(console.error(`\x1B[31mCannot find config '${i}' to extend\x1B[0m`),process.exit(1))}return G(t,...r,Z)}else return G(t,Z)}catch(e){if((e==null?void 0:e.code)==="MODULE_NOT_FOUND")return;console.error(e),Array.isArray(n)&&(n=n[0]),console.error(`\x1B[31mError loading config '${n}'\x1B[0m`),process.exit(1)}}async function In(){$||(console.error(`\x1B[31mCannot find config ${tn.filter(n=>n!==void 0).map(n=>`'${n}'`).join(" or ")}\x1B[0m`),process.exit(1)),Sn(process.env,await pn());for(let n of L._){if(n.startsWith("~")&&process.env.BSM_PATH){let e=process.env.BSM_PATH.split("."),t=x($.scripts,e);if(t){await v(t,n.split(".").splice(1),e);continue}}await v($.scripts,n.split("."))}}function Sn(n,e){if(e)if(process.platform==="win32"){if(!process.env.Path||process.env.Path.includes(e))return;n.Path=`${process.env.Path};${e}`}else{if(!process.env.PATH||process.env.PATH.includes(e))return;n.PATH=`${process.env.PATH}:${e}`}}async function pn(){let n=process.cwd();for(;await N.promises.access(b.default.join(n,"node_modules/.bin"),N.constants.X_OK).then(()=>!1,()=>!0);){let e=b.default.join(n,"../");if(e===n)return null;n=e}return b.default.join(n,"node_modules/.bin")}function x(n,e){if(e.length===0)return n;let t=e[0];if(typeof n=="object"&&Object.hasOwn(n,t))if(Array.isArray(n)){let r=parseInt(t);return x(n[r],e.slice(1))}else return x(n[t],e.slice(1))}async function v(n,e,t=[],r=!0,i=!1){try{if(typeof n=="function")try{let s=await Rn(n,e,t);if(!s&&e.length===0)return;await v(s??{},e,t,r);return}catch(s){throw console.error(s),console.error(`\x1B[31mError executing function '${t.join(".")}'\x1B[0m`),{code:1,script:t.join(".")}}await U(n,["_pre"],t,!1,!0);let c=e.slice(1);if(e.length===0)await Tn(n,t,r,i);else if(e[0]==="*")await Cn(n,c,t);else if(!await U(n,e,t,!0,!1,!1))return console.error(`\x1B[31mScript '${[...t,...e].join(".")}' not found\x1B[0m`),process.exit(127);await U(n,["_post"],t,!1,!0)}catch(c){if(process.env.BSM_ERROR=c.code.toString(),await U(n,["_onError"],t,!1,!0),!await U(n,["_catch"],t,!1))throw c}finally{await U(n,["_finally"],t,!1,!0)}}async function Cn(n,e,t){if(typeof n=="string")await v(n,e,t);else if(typeof n=="function")process.exit(100);else if(Array.isArray(n))for(let r=0;r<n.length;r++)await v(n[r],e,[...t,r.toString()],!0,!0);else for(let r in n)r.startsWith("_")||Object.hasOwn(n,r)&&await v(n[r],e,[...t,r],!0,!0)}async function Rn(n,e,t){return console.log(`> \x1B[93mExecuting JavaScript function\x1B[0m \x1B[90m(${[...t].join(".")})\x1B[0m`),await n.call(null,L["--"])}async function U(n,e,t,r=!0,i=!1,c=!0){if(i&&process.env.BSM_SCRIPT===[...t,...e].join("."))return!1;let s=e[0];if(typeof n!="object"||!Object.hasOwn(n,s))return!1;if(Array.isArray(n)){let A=parseInt(s);await v(n[A],e.slice(1),[...t,s],r,c)}else await v(n[s],e.slice(1),[...t,s],r,c);return!0}async function Tn(n,e,t,r){switch(typeof n){case"string":await dn(n,e,t);return;case"object":if(Array.isArray(n))for(let i=0;i<n.length;i++)await v(n[i],[],[...e,i.toString()]);else if(!(en.isCI&&await U(n,["_ci"],e))){if(!await U(n,[`_${process.platform}`],e)){if(!await U(n,["_default"],e)){if(!r)return console.error(`\x1B[31mScript '${[...e].join(".")}' is not executable\x1B[0m`),process.exit(127)}}}return}}async function dn(n,e,t){var r;if(t&&((r=L["--"])!=null&&r.length)&&(n+=" "+L["--"].join(" ")),console.log(`> ${n} \x1B[90m(${e.join(".")})\x1B[0m`),n!=="")return await new Promise((i,c)=>{nn.default.spawn(n,[],{stdio:"inherit",shell:!0,env:{...process.env,BSM_PATH:e.slice(0,-1).join("."),BSM_SCRIPT:e.join(".")}}).on("close",A=>{A===0?i():c({code:A,script:e.join(".")})})})}In().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.3",
3
+ "version": "0.0.5",
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>",
@@ -28,18 +28,19 @@
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/minimist": "^1.2.2",
31
- "@types/node": "^18.16.3",
32
- "@typescript-eslint/eslint-plugin": "^5.59.2",
33
- "@typescript-eslint/parser": "^5.59.2",
34
- "@under_koen/bsm": "^0.0.2",
31
+ "@types/node": "^20.3.1",
32
+ "@typescript-eslint/eslint-plugin": "^5.60.0",
33
+ "@typescript-eslint/parser": "^5.60.0",
34
+ "@under_koen/bsm": "^0.0.4",
35
+ "ci-info": "^3.8.0",
35
36
  "defu": "^6.1.2",
36
- "esbuild": "0.17.18",
37
- "eslint": "^8.39.0",
37
+ "esbuild": "^0.18.6",
38
+ "eslint": "^8.43.0",
38
39
  "eslint-config-prettier": "^8.8.0",
39
40
  "minimist": "^1.2.8",
40
41
  "prettier": "2.8.8",
41
42
  "prettier-package-json": "^2.8.0",
42
- "typescript": "^5.0.4"
43
+ "typescript": "^5.1.3"
43
44
  },
44
45
  "keywords": [
45
46
  "script",