@promptbook/node 0.72.0-31 → 0.72.0-33
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/esm/index.es.js +34 -17
- package/esm/index.es.js.map +1 -1
- package/esm/typings/src/utils/execCommand/$execCommand.d.ts +2 -0
- package/esm/typings/src/utils/execCommand/{execCommandNormalizeOptions.d.ts → $execCommandNormalizeOptions.d.ts} +3 -1
- package/esm/typings/src/utils/execCommand/$execCommands.d.ts +1 -0
- package/esm/typings/src/utils/execCommand/ExecCommandOptions.d.ts +27 -1
- package/package.json +2 -2
- package/umd/index.umd.js +34 -17
- package/umd/index.umd.js.map +1 -1
package/esm/index.es.js
CHANGED
|
@@ -18,7 +18,7 @@ import sha256 from 'crypto-js/sha256';
|
|
|
18
18
|
/**
|
|
19
19
|
* The version of the Promptbook library
|
|
20
20
|
*/
|
|
21
|
-
var PROMPTBOOK_VERSION = '0.72.0-
|
|
21
|
+
var PROMPTBOOK_VERSION = '0.72.0-32';
|
|
22
22
|
// TODO: [main] !!!! List here all the versions and annotate + put into script
|
|
23
23
|
|
|
24
24
|
/*! *****************************************************************************
|
|
@@ -9850,22 +9850,26 @@ var FileCacheStorage = /** @class */ (function () {
|
|
|
9850
9850
|
/**
|
|
9851
9851
|
* Normalize options for `execCommand` and `execCommands`
|
|
9852
9852
|
*
|
|
9853
|
+
* Note: `$` is used to indicate that this function behaves differently according to `process.platform`
|
|
9854
|
+
*
|
|
9853
9855
|
* @private internal utility of `execCommand` and `execCommands`
|
|
9854
9856
|
*/
|
|
9855
|
-
function execCommandNormalizeOptions(options) {
|
|
9857
|
+
function $execCommandNormalizeOptions(options) {
|
|
9856
9858
|
var _a;
|
|
9857
|
-
var _b, _c, _d;
|
|
9859
|
+
var _b, _c, _d, _e;
|
|
9858
9860
|
var command;
|
|
9859
9861
|
var cwd;
|
|
9860
9862
|
var crashOnError;
|
|
9861
9863
|
var args = [];
|
|
9862
9864
|
var timeout;
|
|
9865
|
+
var isVerbose;
|
|
9863
9866
|
if (typeof options === 'string') {
|
|
9864
9867
|
// TODO: [1] DRY default values
|
|
9865
9868
|
command = options;
|
|
9866
9869
|
cwd = process.cwd();
|
|
9867
9870
|
crashOnError = true;
|
|
9868
|
-
timeout = Infinity;
|
|
9871
|
+
timeout = Infinity; // <- TODO: [⏳]
|
|
9872
|
+
isVerbose = DEFAULT_IS_VERBOSE;
|
|
9869
9873
|
}
|
|
9870
9874
|
else {
|
|
9871
9875
|
/*
|
|
@@ -9881,6 +9885,7 @@ function execCommandNormalizeOptions(options) {
|
|
|
9881
9885
|
cwd = (_b = options.cwd) !== null && _b !== void 0 ? _b : process.cwd();
|
|
9882
9886
|
crashOnError = (_c = options.crashOnError) !== null && _c !== void 0 ? _c : true;
|
|
9883
9887
|
timeout = (_d = options.timeout) !== null && _d !== void 0 ? _d : Infinity;
|
|
9888
|
+
isVerbose = (_e = options.isVerbose) !== null && _e !== void 0 ? _e : DEFAULT_IS_VERBOSE;
|
|
9884
9889
|
}
|
|
9885
9890
|
// TODO: /(-[a-zA-Z0-9-]+\s+[^\s]*)|[^\s]*/g
|
|
9886
9891
|
var _ = Array.from(command.matchAll(/(".*")|([^\s]*)/g))
|
|
@@ -9902,16 +9907,21 @@ function execCommandNormalizeOptions(options) {
|
|
|
9902
9907
|
if (['ts-node'].includes(humanReadableCommand)) {
|
|
9903
9908
|
humanReadableCommand += " ".concat(args[1]);
|
|
9904
9909
|
}
|
|
9905
|
-
|
|
9910
|
+
if (/^win/.test(process.platform) && ['npm', 'npx'].includes(command)) {
|
|
9911
|
+
command = "".concat(command, ".cmd");
|
|
9912
|
+
}
|
|
9913
|
+
return { command: command, humanReadableCommand: humanReadableCommand, args: args, cwd: cwd, crashOnError: crashOnError, timeout: timeout, isVerbose: isVerbose };
|
|
9906
9914
|
}
|
|
9907
9915
|
// TODO: This should show type error> execCommandNormalizeOptions({ command: '', commands: [''] });
|
|
9908
9916
|
|
|
9909
9917
|
/**
|
|
9910
9918
|
* Run one command in a shell
|
|
9911
9919
|
*
|
|
9920
|
+
*
|
|
9912
9921
|
* Note: There are 2 similar functions in the codebase:
|
|
9913
9922
|
* - `$execCommand` which runs a single command
|
|
9914
9923
|
* - `$execCommands` which runs multiple commands
|
|
9924
|
+
* Note: `$` is used to indicate that this function is not a pure function - it runs a command in a shell
|
|
9915
9925
|
*
|
|
9916
9926
|
* @public exported from `@promptbook/node`
|
|
9917
9927
|
*/
|
|
@@ -9921,7 +9931,7 @@ function $execCommand(options) {
|
|
|
9921
9931
|
}
|
|
9922
9932
|
return new Promise(function (resolve, reject) {
|
|
9923
9933
|
// eslint-disable-next-line prefer-const
|
|
9924
|
-
var _a = execCommandNormalizeOptions(options), command = _a.command, humanReadableCommand = _a.humanReadableCommand, args = _a.args, cwd = _a.cwd, crashOnError = _a.crashOnError, timeout = _a.timeout;
|
|
9934
|
+
var _a = $execCommandNormalizeOptions(options), command = _a.command, humanReadableCommand = _a.humanReadableCommand, args = _a.args, cwd = _a.cwd, crashOnError = _a.crashOnError, timeout = _a.timeout, _b = _a.isVerbose, isVerbose = _b === void 0 ? DEFAULT_IS_VERBOSE : _b;
|
|
9925
9935
|
if (timeout !== Infinity) {
|
|
9926
9936
|
// TODO: In waitasecond forTime(Infinity) should be equivalent to forEver()
|
|
9927
9937
|
forTime(timeout).then(function () {
|
|
@@ -9934,24 +9944,26 @@ function $execCommand(options) {
|
|
|
9934
9944
|
}
|
|
9935
9945
|
});
|
|
9936
9946
|
}
|
|
9937
|
-
if (
|
|
9938
|
-
|
|
9947
|
+
if (isVerbose) {
|
|
9948
|
+
console.info(colors.yellow(cwd) + ' ' + colors.green(command) + ' ' + colors.blue(args.join(' ')));
|
|
9939
9949
|
}
|
|
9940
|
-
// !!!!!! Verbose mode - to all consoles
|
|
9941
|
-
console.info(colors.yellow(cwd) + ' ' + colors.green(command) + ' ' + colors.blue(args.join(' ')));
|
|
9942
9950
|
try {
|
|
9943
9951
|
var commandProcess = spawn(command, args, { cwd: cwd, shell: true });
|
|
9944
|
-
|
|
9945
|
-
|
|
9946
|
-
|
|
9952
|
+
if (isVerbose) {
|
|
9953
|
+
commandProcess.on('message', function (message) {
|
|
9954
|
+
console.info({ message: message });
|
|
9955
|
+
});
|
|
9956
|
+
}
|
|
9947
9957
|
var output_1 = [];
|
|
9948
9958
|
commandProcess.stdout.on('data', function (stdout) {
|
|
9949
9959
|
output_1.push(stdout.toString());
|
|
9950
|
-
|
|
9960
|
+
if (isVerbose) {
|
|
9961
|
+
console.info(stdout.toString());
|
|
9962
|
+
}
|
|
9951
9963
|
});
|
|
9952
9964
|
commandProcess.stderr.on('data', function (stderr) {
|
|
9953
9965
|
output_1.push(stderr.toString());
|
|
9954
|
-
if (stderr.toString().trim()) {
|
|
9966
|
+
if (isVerbose && stderr.toString().trim()) {
|
|
9955
9967
|
console.warn(stderr.toString());
|
|
9956
9968
|
}
|
|
9957
9969
|
});
|
|
@@ -9962,7 +9974,9 @@ function $execCommand(options) {
|
|
|
9962
9974
|
"Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code)));
|
|
9963
9975
|
}
|
|
9964
9976
|
else {
|
|
9965
|
-
|
|
9977
|
+
if (isVerbose) {
|
|
9978
|
+
console.warn("Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code));
|
|
9979
|
+
}
|
|
9966
9980
|
resolve(spaceTrim(output_1.join('\n')));
|
|
9967
9981
|
}
|
|
9968
9982
|
}
|
|
@@ -9981,7 +9995,9 @@ function $execCommand(options) {
|
|
|
9981
9995
|
reject(new Error("Command \"".concat(humanReadableCommand, "\" failed: \n").concat(error.message)));
|
|
9982
9996
|
}
|
|
9983
9997
|
else {
|
|
9984
|
-
|
|
9998
|
+
if (isVerbose) {
|
|
9999
|
+
console.warn(error);
|
|
10000
|
+
}
|
|
9985
10001
|
resolve(spaceTrim(output_1.join('\n')));
|
|
9986
10002
|
}
|
|
9987
10003
|
});
|
|
@@ -10002,6 +10018,7 @@ function $execCommand(options) {
|
|
|
10002
10018
|
* Note: There are 2 similar functions in the codebase:
|
|
10003
10019
|
* - `$execCommand` which runs a single command
|
|
10004
10020
|
* - `$execCommands` which runs multiple commands
|
|
10021
|
+
* Note: `$` is used to indicate that this function is not a pure function - it runs a commands in a shell
|
|
10005
10022
|
*
|
|
10006
10023
|
* @public exported from `@promptbook/node`
|
|
10007
10024
|
*/
|