bare-script 2.2.4 → 2.2.6
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 +17 -4
- package/lib/library.js +9 -0
- package/package.json +1 -1
package/lib/bare.js
CHANGED
|
@@ -20,6 +20,7 @@ options:
|
|
|
20
20
|
-h, --help show this help message and exit
|
|
21
21
|
-c, --code CODE execute the BareScript code
|
|
22
22
|
-d, --debug enable debug mode
|
|
23
|
+
-s, --static perform static analysis
|
|
23
24
|
-v, --var VAR EXPR set a global variable to an expression value`;
|
|
24
25
|
|
|
25
26
|
|
|
@@ -86,9 +87,9 @@ export async function main(options) {
|
|
|
86
87
|
currentFile = file;
|
|
87
88
|
|
|
88
89
|
// Run the bare-script linter?
|
|
89
|
-
if (args.debug) {
|
|
90
|
+
if (args.static || args.debug) {
|
|
90
91
|
const warnings = lintScript(script);
|
|
91
|
-
const warningPrefix = `BareScript: Static analysis...`;
|
|
92
|
+
const warningPrefix = `BareScript: Static analysis "${file}" ...`;
|
|
92
93
|
if (warnings.length === 0) {
|
|
93
94
|
options.logFn(`${warningPrefix} OK`);
|
|
94
95
|
} else {
|
|
@@ -96,6 +97,14 @@ export async function main(options) {
|
|
|
96
97
|
for (const warning of warnings) {
|
|
97
98
|
options.logFn(`BareScript: ${warning}`);
|
|
98
99
|
}
|
|
100
|
+
if (args.static) {
|
|
101
|
+
throw Error('Static analysis failed');
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Skip code execution if linter requested
|
|
106
|
+
if (args.static) {
|
|
107
|
+
continue;
|
|
99
108
|
}
|
|
100
109
|
}
|
|
101
110
|
|
|
@@ -125,8 +134,10 @@ export async function main(options) {
|
|
|
125
134
|
}
|
|
126
135
|
}
|
|
127
136
|
} catch ({message}) {
|
|
128
|
-
|
|
129
|
-
|
|
137
|
+
if (currentFile !== null) {
|
|
138
|
+
options.logFn(`${currentFile}:`);
|
|
139
|
+
}
|
|
140
|
+
options.logFn(message);
|
|
130
141
|
statusCode = 1;
|
|
131
142
|
}
|
|
132
143
|
|
|
@@ -161,6 +172,8 @@ export function parseArgs(argv) {
|
|
|
161
172
|
args.debug = true;
|
|
162
173
|
} else if (arg === '-h' || arg === '--help') {
|
|
163
174
|
args.help = true;
|
|
175
|
+
} else if (arg === '-s' || arg === '--static') {
|
|
176
|
+
args.static = true;
|
|
164
177
|
} else if (arg === '-v' || arg === '--var') {
|
|
165
178
|
if (iArg + 2 >= argv.length) {
|
|
166
179
|
throw new Error(`Missing values for ${arg}`);
|
package/lib/library.js
CHANGED
|
@@ -961,6 +961,15 @@ export const scriptFunctions = {
|
|
|
961
961
|
}
|
|
962
962
|
},
|
|
963
963
|
|
|
964
|
+
// $function: systemPartial
|
|
965
|
+
// $group: System
|
|
966
|
+
// $doc: Return a new function which behaves like "func" called with "args".
|
|
967
|
+
// $doc: If additional arguments are passed to the returned function, they are appended to "args".
|
|
968
|
+
// $arg func: The function
|
|
969
|
+
// $arg args: The function arguments
|
|
970
|
+
// $return: The new function called with "args"
|
|
971
|
+
'systemPartial': ([func, ...args]) => (argsExtra, options) => func([...args, ...argsExtra], options),
|
|
972
|
+
|
|
964
973
|
|
|
965
974
|
//
|
|
966
975
|
// URL functions
|