bare-script 2.2.2 → 2.2.4
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/lib/bare.js +10 -3
- package/lib/library.js +19 -17
- package/package.json +1 -1
package/lib/bare.js
CHANGED
|
@@ -42,6 +42,7 @@ options:
|
|
|
42
42
|
* @ignore
|
|
43
43
|
*/
|
|
44
44
|
export async function main(options) {
|
|
45
|
+
let statusCode = 0;
|
|
45
46
|
let currentFile = null;
|
|
46
47
|
try {
|
|
47
48
|
const args = parseArgs(options.argv);
|
|
@@ -101,7 +102,7 @@ export async function main(options) {
|
|
|
101
102
|
// Execute the script
|
|
102
103
|
const timeBegin = performance.now();
|
|
103
104
|
// eslint-disable-next-line no-await-in-loop
|
|
104
|
-
await executeScriptAsync(script, {
|
|
105
|
+
const result = await executeScriptAsync(script, {
|
|
105
106
|
'debug': args.debug ?? false,
|
|
106
107
|
'fetchFn': options.fetchFn,
|
|
107
108
|
'globals': args.variables,
|
|
@@ -110,20 +111,26 @@ export async function main(options) {
|
|
|
110
111
|
'urlFn': (url) => (rURL.test(url) || url.startsWith('/') ? url : `${file.slice(0, file.lastIndexOf('/') + 1)}${url}`)
|
|
111
112
|
|
|
112
113
|
});
|
|
114
|
+
statusCode = (Number.isInteger(result) && result >= 0 && result <= 255 ? result : (result ? 1 : 0));
|
|
113
115
|
|
|
114
116
|
// Log script execution end with timing
|
|
115
117
|
if (args.debug) {
|
|
116
118
|
const timeEnd = performance.now();
|
|
117
119
|
options.logFn(`BareScript: Script executed in ${(timeEnd - timeBegin).toFixed(1)} milliseconds`);
|
|
118
120
|
}
|
|
121
|
+
|
|
122
|
+
// Stop on error status code
|
|
123
|
+
if (statusCode !== 0) {
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
119
126
|
}
|
|
120
127
|
} catch ({message}) {
|
|
121
128
|
const fileStr = (currentFile !== null ? `${currentFile}:\n` : '');
|
|
122
129
|
options.logFn(`${fileStr}${message}`);
|
|
123
|
-
|
|
130
|
+
statusCode = 1;
|
|
124
131
|
}
|
|
125
132
|
|
|
126
|
-
return
|
|
133
|
+
return statusCode;
|
|
127
134
|
}
|
|
128
135
|
|
|
129
136
|
|
package/lib/library.js
CHANGED
|
@@ -28,7 +28,7 @@ export const scriptFunctions = {
|
|
|
28
28
|
// $doc: Create a copy of an array
|
|
29
29
|
// $arg array: The array to copy
|
|
30
30
|
// $return: The array copy
|
|
31
|
-
'arrayCopy': ([array]) => (Array.isArray(array) ? [...array] :
|
|
31
|
+
'arrayCopy': ([array]) => (Array.isArray(array) ? [...array] : []),
|
|
32
32
|
|
|
33
33
|
// $function: arrayExtend
|
|
34
34
|
// $group: Array
|
|
@@ -37,10 +37,9 @@ export const scriptFunctions = {
|
|
|
37
37
|
// $arg array2: The array to extend with
|
|
38
38
|
// $return: The extended array
|
|
39
39
|
'arrayExtend': ([array, array2]) => {
|
|
40
|
-
if (
|
|
41
|
-
|
|
40
|
+
if (Array.isArray(array) && Array.isArray(array2)) {
|
|
41
|
+
array.push(...array2);
|
|
42
42
|
}
|
|
43
|
-
array.push(...array2);
|
|
44
43
|
return array;
|
|
45
44
|
},
|
|
46
45
|
|
|
@@ -67,7 +66,7 @@ export const scriptFunctions = {
|
|
|
67
66
|
// $arg array: The array
|
|
68
67
|
// $arg separator: The separator string
|
|
69
68
|
// $return: The joined string
|
|
70
|
-
'arrayJoin': ([array, separator]) => (Array.isArray(array) ? array.join(separator) :
|
|
69
|
+
'arrayJoin': ([array, separator]) => (Array.isArray(array) ? array.join(separator) : ''),
|
|
71
70
|
|
|
72
71
|
// $function: arrayLastIndexOf
|
|
73
72
|
// $group: Array
|
|
@@ -84,7 +83,7 @@ export const scriptFunctions = {
|
|
|
84
83
|
// $group: Array
|
|
85
84
|
// $doc: Get the length of an array
|
|
86
85
|
// $arg array: The array
|
|
87
|
-
// $return: The array's length
|
|
86
|
+
// $return: The array's length; null if not an array
|
|
88
87
|
'arrayLength': ([array]) => (Array.isArray(array) ? array.length : null),
|
|
89
88
|
|
|
90
89
|
// $function: arrayNew
|
|
@@ -114,8 +113,13 @@ export const scriptFunctions = {
|
|
|
114
113
|
// $doc: Add one or more values to the end of the array
|
|
115
114
|
// $arg array: The array
|
|
116
115
|
// $arg values: The values to add to the end of the array
|
|
117
|
-
// $return: The
|
|
118
|
-
'arrayPush': ([array, ...values]) =>
|
|
116
|
+
// $return: The array
|
|
117
|
+
'arrayPush': ([array, ...values]) => {
|
|
118
|
+
if (Array.isArray(array)) {
|
|
119
|
+
array.push(...values);
|
|
120
|
+
}
|
|
121
|
+
return array;
|
|
122
|
+
},
|
|
119
123
|
|
|
120
124
|
// $function: arraySet
|
|
121
125
|
// $group: Array
|
|
@@ -127,9 +131,8 @@ export const scriptFunctions = {
|
|
|
127
131
|
'arraySet': ([array, index, value]) => {
|
|
128
132
|
if (Array.isArray(array)) {
|
|
129
133
|
array[index] = value;
|
|
130
|
-
return value;
|
|
131
134
|
}
|
|
132
|
-
return
|
|
135
|
+
return value;
|
|
133
136
|
},
|
|
134
137
|
|
|
135
138
|
// $function: arraySlice
|
|
@@ -568,9 +571,9 @@ export const scriptFunctions = {
|
|
|
568
571
|
'objectAssign': ([object, object2]) => {
|
|
569
572
|
if (object !== null && typeof object === 'object' && !Array.isArray(object) &&
|
|
570
573
|
object2 !== null && typeof object2 === 'object' && !Array.isArray(object2)) {
|
|
571
|
-
|
|
574
|
+
Object.assign(object, object2);
|
|
572
575
|
}
|
|
573
|
-
return
|
|
576
|
+
return object;
|
|
574
577
|
},
|
|
575
578
|
|
|
576
579
|
// $function: objectCopy
|
|
@@ -578,7 +581,7 @@ export const scriptFunctions = {
|
|
|
578
581
|
// $doc: Create a copy of an object
|
|
579
582
|
// $arg object: The object to copy
|
|
580
583
|
// $return: The object copy
|
|
581
|
-
'objectCopy': ([object]) => (object !== null && typeof object === 'object' && !Array.isArray(object) ? {...object} :
|
|
584
|
+
'objectCopy': ([object]) => (object !== null && typeof object === 'object' && !Array.isArray(object) ? {...object} : {}),
|
|
582
585
|
|
|
583
586
|
// $function: objectDelete
|
|
584
587
|
// $group: Object
|
|
@@ -614,7 +617,7 @@ export const scriptFunctions = {
|
|
|
614
617
|
// $group: Object
|
|
615
618
|
// $doc: Get an object's keys
|
|
616
619
|
// $arg object: The object
|
|
617
|
-
// $return: The array of keys
|
|
620
|
+
// $return: The array of keys; null if not an object
|
|
618
621
|
'objectKeys': ([object]) => (object !== null && typeof object === 'object' && !Array.isArray(object) ? Object.keys(object) : null),
|
|
619
622
|
|
|
620
623
|
// $function: objectNew
|
|
@@ -640,9 +643,8 @@ export const scriptFunctions = {
|
|
|
640
643
|
'objectSet': ([object, key, value]) => {
|
|
641
644
|
if (object !== null && typeof object === 'object' && !Array.isArray(object)) {
|
|
642
645
|
object[key] = value;
|
|
643
|
-
return value;
|
|
644
646
|
}
|
|
645
|
-
return
|
|
647
|
+
return value;
|
|
646
648
|
},
|
|
647
649
|
|
|
648
650
|
|
|
@@ -789,7 +791,7 @@ export const scriptFunctions = {
|
|
|
789
791
|
// $group: String
|
|
790
792
|
// $doc: Get the length of a string
|
|
791
793
|
// $arg string: The string
|
|
792
|
-
// $return: The string's length
|
|
794
|
+
// $return: The string's length; null if not a string
|
|
793
795
|
'stringLength': ([string]) => (typeof string === 'string' ? string.length : null),
|
|
794
796
|
|
|
795
797
|
// $function: stringLower
|