@promptbook/legacy-documents 0.72.0-32 → 0.72.0-34

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.
@@ -4,7 +4,7 @@ import type { string_executable_path } from '../../types/typeAliases';
4
4
  *
5
5
  * @private within the repository
6
6
  */
7
- export declare function locateLibreoffice(): Promise<string_executable_path>;
7
+ export declare function locateLibreoffice(): Promise<string_executable_path | null>;
8
8
  /**
9
9
  * TODO: [🧠][♿] Maybe export through `@promptbook/node` OR `@promptbook/legacy-documents`
10
10
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
@@ -4,7 +4,7 @@ import type { string_executable_path } from '../../types/typeAliases';
4
4
  *
5
5
  * @private within the repository
6
6
  */
7
- export declare function locatePandoc(): Promise<string_executable_path>;
7
+ export declare function locatePandoc(): Promise<string_executable_path | null>;
8
8
  /**
9
9
  * TODO: [🧠][♿] Maybe export through `@promptbook/node` OR `@promptbook/documents`
10
10
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
@@ -26,7 +26,7 @@ export interface LocateAppOptions {
26
26
  *
27
27
  * @private within the repository
28
28
  */
29
- export declare function locateApp(options: RequireAtLeastOne<LocateAppOptions, 'linuxWhich' | 'windowsSuffix' | 'macOsName'>): Promise<string_executable_path>;
29
+ export declare function locateApp(options: RequireAtLeastOne<LocateAppOptions, 'linuxWhich' | 'windowsSuffix' | 'macOsName'>): Promise<string_executable_path | null>;
30
30
  /**
31
31
  * TODO: [🧠][♿] Maybe export through `@promptbook/node`
32
32
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
@@ -1,11 +1,11 @@
1
- import type { LocateAppOptions } from '../locateApp';
2
1
  import type { string_executable_path } from '../../types/typeAliases';
2
+ import type { LocateAppOptions } from '../locateApp';
3
3
  /**
4
4
  * @@@
5
5
  *
6
6
  * @private within the repository
7
7
  */
8
- export declare function locateAppOnLinux({ appName, linuxWhich, }: Pick<Required<LocateAppOptions>, 'appName' | 'linuxWhich'>): Promise<string_executable_path>;
8
+ export declare function locateAppOnLinux({ appName, linuxWhich, }: Pick<Required<LocateAppOptions>, 'appName' | 'linuxWhich'>): Promise<string_executable_path | null>;
9
9
  /**
10
10
  * TODO: [🧠][♿] Maybe export through `@promptbook/node`
11
11
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
@@ -5,7 +5,7 @@ import type { LocateAppOptions } from '../locateApp';
5
5
  *
6
6
  * @private within the repository
7
7
  */
8
- export declare function locateAppOnMacOs({ appName, macOsName, }: Pick<Required<LocateAppOptions>, 'appName' | 'macOsName'>): Promise<string_executable_path>;
8
+ export declare function locateAppOnMacOs({ appName, macOsName, }: Pick<Required<LocateAppOptions>, 'appName' | 'macOsName'>): Promise<string_executable_path | null>;
9
9
  /**
10
10
  * TODO: [🧠][♿] Maybe export through `@promptbook/node`
11
11
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
@@ -5,7 +5,7 @@ import type { LocateAppOptions } from '../locateApp';
5
5
  *
6
6
  * @private within the repository
7
7
  */
8
- export declare function locateAppOnWindows({ appName, windowsSuffix, }: Pick<Required<LocateAppOptions>, 'appName' | 'windowsSuffix'>): Promise<string_executable_path>;
8
+ export declare function locateAppOnWindows({ appName, windowsSuffix, }: Pick<Required<LocateAppOptions>, 'appName' | 'windowsSuffix'>): Promise<string_executable_path | null>;
9
9
  /**
10
10
  * TODO: [🧠][♿] Maybe export through `@promptbook/node`
11
11
  * Note: [🟢] Code in this file should never be never released in packages that could be imported into browser environment
@@ -2,9 +2,11 @@ import type { ExecCommandOptions } from './ExecCommandOptions';
2
2
  /**
3
3
  * Run one command in a shell
4
4
  *
5
+ *
5
6
  * Note: There are 2 similar functions in the codebase:
6
7
  * - `$execCommand` which runs a single command
7
8
  * - `$execCommands` which runs multiple commands
9
+ * Note: `$` is used to indicate that this function is not a pure function - it runs a command in a shell
8
10
  *
9
11
  * @public exported from `@promptbook/node`
10
12
  */
@@ -3,8 +3,10 @@ import type { ExecCommandOptionsAdvanced } from './ExecCommandOptions';
3
3
  /**
4
4
  * Normalize options for `execCommand` and `execCommands`
5
5
  *
6
+ * Note: `$` is used to indicate that this function behaves differently according to `process.platform`
7
+ *
6
8
  * @private internal utility of `execCommand` and `execCommands`
7
9
  */
8
- export declare function execCommandNormalizeOptions(options: ExecCommandOptions): Pick<ExecCommandOptionsAdvanced, 'command' | 'args' | 'cwd' | 'crashOnError' | 'timeout'> & {
10
+ export declare function $execCommandNormalizeOptions(options: ExecCommandOptions): Pick<ExecCommandOptionsAdvanced, 'command' | 'args' | 'cwd' | 'crashOnError' | 'timeout' | 'isVerbose'> & {
9
11
  humanReadableCommand: string;
10
12
  };
@@ -4,6 +4,7 @@
4
4
  * Note: There are 2 similar functions in the codebase:
5
5
  * - `$execCommand` which runs a single command
6
6
  * - `$execCommands` which runs multiple commands
7
+ * Note: `$` is used to indicate that this function is not a pure function - it runs a commands in a shell
7
8
  *
8
9
  * @public exported from `@promptbook/node`
9
10
  */
@@ -5,15 +5,41 @@ type RequiredAndOptional<TBase, TRequired extends keyof TBase, TOptional extends
5
5
  /**
6
6
  * Simple options for `execCommand`
7
7
  */
8
- export type ExecCommandOptions = string | RequiredAndOptional<ExecCommandOptionsAdvanced, 'command', 'args' | 'cwd' | 'crashOnError' | 'timeout'>;
8
+ export type ExecCommandOptions = string | RequiredAndOptional<ExecCommandOptionsAdvanced, 'command', 'args' | 'cwd' | 'crashOnError' | 'timeout' | 'isVerbose'>;
9
9
  /**
10
10
  * Advanced options for `execCommand`
11
11
  */
12
12
  export type ExecCommandOptionsAdvanced = {
13
+ /**
14
+ * Command to run
15
+ */
13
16
  readonly command: string;
17
+ /**
18
+ * Arguments for the command
19
+ */
14
20
  readonly args: string[];
21
+ /**
22
+ * Current working directory
23
+ *
24
+ * @default process.cwd()
25
+ */
15
26
  readonly cwd: string;
27
+ /**
28
+ * If `true` then the command will throw an error if the return code is not `0`
29
+ */
16
30
  readonly crashOnError: boolean;
31
+ /**
32
+ * Timeout in milliseconds
33
+ */
17
34
  readonly timeout: number;
35
+ /**
36
+ * If `true` then the command and entire CLI output will be logged to the console
37
+ *
38
+ * @default false
39
+ */
40
+ readonly isVerbose?: boolean;
18
41
  };
19
42
  export {};
43
+ /**
44
+ * TODO: [⏳] Make DEFAULT_TIMEOUT_MS as global constant
45
+ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/legacy-documents",
3
- "version": "0.72.0-32",
3
+ "version": "0.72.0-34",
4
4
  "description": "Supercharge your use of large language models",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -52,7 +52,7 @@
52
52
  "module": "./esm/index.es.js",
53
53
  "typings": "./esm/typings/src/_packages/legacy-documents.index.d.ts",
54
54
  "peerDependencies": {
55
- "@promptbook/core": "0.72.0-32"
55
+ "@promptbook/core": "0.72.0-34"
56
56
  },
57
57
  "dependencies": {
58
58
  "colors": "1.4.0",
package/umd/index.umd.js CHANGED
@@ -15,7 +15,7 @@
15
15
  /**
16
16
  * The version of the Promptbook library
17
17
  */
18
- var PROMPTBOOK_VERSION = '0.72.0-31';
18
+ var PROMPTBOOK_VERSION = '0.72.0-33';
19
19
  // TODO: [main] !!!! List here all the versions and annotate + put into script
20
20
 
21
21
  /*! *****************************************************************************
@@ -515,22 +515,26 @@
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 @@
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 @@
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 @@
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
  waitasecond.forTime(timeout).then(function () {
@@ -599,24 +609,26 @@
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__default["default"].yellow(cwd) + ' ' + colors__default["default"].green(command) + ' ' + colors__default["default"].blue(args.join(' ')));
604
614
  }
605
- // !!!!!! Verbose mode - to all consoles
606
- console.info(colors__default["default"].yellow(cwd) + ' ' + colors__default["default"].green(command) + ' ' + colors__default["default"].blue(args.join(' ')));
607
615
  try {
608
616
  var commandProcess = child_process.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 @@
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.spaceTrim(output_1.join('\n')));
632
646
  }
633
647
  }
@@ -646,7 +660,9 @@
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.spaceTrim(output_1.join('\n')));
651
667
  }
652
668
  });