@promptbook/legacy-documents 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 CHANGED
@@ -15,7 +15,7 @@ import { unparse, parse } from 'papaparse';
15
15
  /**
16
16
  * The version of the Promptbook library
17
17
  */
18
- var PROMPTBOOK_VERSION = '0.72.0-30';
18
+ var PROMPTBOOK_VERSION = '0.72.0-32';
19
19
  // TODO: [main] !!!! List here all the versions and annotate + put into script
20
20
 
21
21
  /*! *****************************************************************************
@@ -515,22 +515,26 @@ var $isRunningInNode = new Function("\n try {\n return this === global
515
515
  /**
516
516
  * Normalize options for `execCommand` and `execCommands`
517
517
  *
518
+ * Note: `$` is used to indicate that this function behaves differently according to `process.platform`
519
+ *
518
520
  * @private internal utility of `execCommand` and `execCommands`
519
521
  */
520
- function execCommandNormalizeOptions(options) {
522
+ function $execCommandNormalizeOptions(options) {
521
523
  var _a;
522
- var _b, _c, _d;
524
+ var _b, _c, _d, _e;
523
525
  var command;
524
526
  var cwd;
525
527
  var crashOnError;
526
528
  var args = [];
527
529
  var timeout;
530
+ var isVerbose;
528
531
  if (typeof options === 'string') {
529
532
  // TODO: [1] DRY default values
530
533
  command = options;
531
534
  cwd = process.cwd();
532
535
  crashOnError = true;
533
- timeout = Infinity;
536
+ timeout = Infinity; // <- TODO: [⏳]
537
+ isVerbose = DEFAULT_IS_VERBOSE;
534
538
  }
535
539
  else {
536
540
  /*
@@ -546,6 +550,7 @@ function execCommandNormalizeOptions(options) {
546
550
  cwd = (_b = options.cwd) !== null && _b !== void 0 ? _b : process.cwd();
547
551
  crashOnError = (_c = options.crashOnError) !== null && _c !== void 0 ? _c : true;
548
552
  timeout = (_d = options.timeout) !== null && _d !== void 0 ? _d : Infinity;
553
+ isVerbose = (_e = options.isVerbose) !== null && _e !== void 0 ? _e : DEFAULT_IS_VERBOSE;
549
554
  }
550
555
  // TODO: /(-[a-zA-Z0-9-]+\s+[^\s]*)|[^\s]*/g
551
556
  var _ = Array.from(command.matchAll(/(".*")|([^\s]*)/g))
@@ -567,16 +572,21 @@ function execCommandNormalizeOptions(options) {
567
572
  if (['ts-node'].includes(humanReadableCommand)) {
568
573
  humanReadableCommand += " ".concat(args[1]);
569
574
  }
570
- return { command: command, humanReadableCommand: humanReadableCommand, args: args, cwd: cwd, crashOnError: crashOnError, timeout: timeout };
575
+ if (/^win/.test(process.platform) && ['npm', 'npx'].includes(command)) {
576
+ command = "".concat(command, ".cmd");
577
+ }
578
+ return { command: command, humanReadableCommand: humanReadableCommand, args: args, cwd: cwd, crashOnError: crashOnError, timeout: timeout, isVerbose: isVerbose };
571
579
  }
572
580
  // TODO: This should show type error> execCommandNormalizeOptions({ command: '', commands: [''] });
573
581
 
574
582
  /**
575
583
  * Run one command in a shell
576
584
  *
585
+ *
577
586
  * Note: There are 2 similar functions in the codebase:
578
587
  * - `$execCommand` which runs a single command
579
588
  * - `$execCommands` which runs multiple commands
589
+ * Note: `$` is used to indicate that this function is not a pure function - it runs a command in a shell
580
590
  *
581
591
  * @public exported from `@promptbook/node`
582
592
  */
@@ -586,7 +596,7 @@ function $execCommand(options) {
586
596
  }
587
597
  return new Promise(function (resolve, reject) {
588
598
  // eslint-disable-next-line prefer-const
589
- var _a = execCommandNormalizeOptions(options), command = _a.command, humanReadableCommand = _a.humanReadableCommand, args = _a.args, cwd = _a.cwd, crashOnError = _a.crashOnError, timeout = _a.timeout;
599
+ 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;
590
600
  if (timeout !== Infinity) {
591
601
  // TODO: In waitasecond forTime(Infinity) should be equivalent to forEver()
592
602
  forTime(timeout).then(function () {
@@ -599,24 +609,26 @@ function $execCommand(options) {
599
609
  }
600
610
  });
601
611
  }
602
- if (/^win/.test(process.platform) && ['npm', 'npx'].includes(command)) {
603
- command = "".concat(command, ".cmd");
612
+ if (isVerbose) {
613
+ console.info(colors.yellow(cwd) + ' ' + colors.green(command) + ' ' + colors.blue(args.join(' ')));
604
614
  }
605
- // !!!!!! Verbose mode - to all consoles
606
- console.info(colors.yellow(cwd) + ' ' + colors.green(command) + ' ' + colors.blue(args.join(' ')));
607
615
  try {
608
616
  var commandProcess = spawn(command, args, { cwd: cwd, shell: true });
609
- commandProcess.on('message', function (message) {
610
- console.info({ message: message });
611
- });
617
+ if (isVerbose) {
618
+ commandProcess.on('message', function (message) {
619
+ console.info({ message: message });
620
+ });
621
+ }
612
622
  var output_1 = [];
613
623
  commandProcess.stdout.on('data', function (stdout) {
614
624
  output_1.push(stdout.toString());
615
- console.info(stdout.toString());
625
+ if (isVerbose) {
626
+ console.info(stdout.toString());
627
+ }
616
628
  });
617
629
  commandProcess.stderr.on('data', function (stderr) {
618
630
  output_1.push(stderr.toString());
619
- if (stderr.toString().trim()) {
631
+ if (isVerbose && stderr.toString().trim()) {
620
632
  console.warn(stderr.toString());
621
633
  }
622
634
  });
@@ -627,7 +639,9 @@ function $execCommand(options) {
627
639
  "Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code)));
628
640
  }
629
641
  else {
630
- console.warn("Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code));
642
+ if (isVerbose) {
643
+ console.warn("Command \"".concat(humanReadableCommand, "\" exited with code ").concat(code));
644
+ }
631
645
  resolve(spaceTrim(output_1.join('\n')));
632
646
  }
633
647
  }
@@ -646,7 +660,9 @@ function $execCommand(options) {
646
660
  reject(new Error("Command \"".concat(humanReadableCommand, "\" failed: \n").concat(error.message)));
647
661
  }
648
662
  else {
649
- console.warn(error);
663
+ if (isVerbose) {
664
+ console.warn(error);
665
+ }
650
666
  resolve(spaceTrim(output_1.join('\n')));
651
667
  }
652
668
  });