codify-plugin-lib 1.0.4 → 1.0.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.
@@ -1,11 +1,12 @@
1
1
  /// <reference types="node" />
2
- /// <reference types="node" />
3
2
  import { SpawnOptions } from 'child_process';
3
+ export declare enum SpawnStatus {
4
+ SUCCESS = 0,
5
+ ERROR = 1
6
+ }
4
7
  export interface SpawnResult {
5
- code: number;
6
- signal: NodeJS.Signals | null;
7
- stdout: string;
8
- stderr: string;
8
+ status: SpawnStatus;
9
+ data: string;
9
10
  }
10
11
  type CodifySpawnOptions = {
11
12
  cwd?: string;
@@ -3,11 +3,31 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.isDebug = exports.codifySpawn = void 0;
6
+ exports.isDebug = exports.codifySpawn = exports.SpawnStatus = void 0;
7
7
  const promise_spawn_1 = __importDefault(require("@npmcli/promise-spawn"));
8
+ var SpawnStatus;
9
+ (function (SpawnStatus) {
10
+ SpawnStatus[SpawnStatus["SUCCESS"] = 0] = "SUCCESS";
11
+ SpawnStatus[SpawnStatus["ERROR"] = 1] = "ERROR";
12
+ })(SpawnStatus || (exports.SpawnStatus = SpawnStatus = {}));
8
13
  async function codifySpawn(cmd, args, opts, extras) {
9
- const stdio = isDebug() ? 'inherit' : 'pipe';
10
- return (0, promise_spawn_1.default)(cmd, args, { ...opts, stdio, stdioString: true }, extras);
14
+ try {
15
+ const stdio = isDebug() ? 'inherit' : 'pipe';
16
+ const result = await (0, promise_spawn_1.default)(cmd, args, { ...opts, stdio, stdioString: true, shell: true }, extras);
17
+ const status = (result.code === 0 && !result.stderr)
18
+ ? SpawnStatus.SUCCESS
19
+ : SpawnStatus.ERROR;
20
+ return {
21
+ status,
22
+ data: status === SpawnStatus.SUCCESS ? result.stdout : result.stderr
23
+ };
24
+ }
25
+ catch (e) {
26
+ return {
27
+ status: SpawnStatus.ERROR,
28
+ data: e,
29
+ };
30
+ }
11
31
  }
12
32
  exports.codifySpawn = codifySpawn;
13
33
  function isDebug() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codify-plugin-lib",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -1,11 +1,14 @@
1
1
  import promiseSpawn from '@npmcli/promise-spawn';
2
2
  import { SpawnOptions } from 'child_process';
3
3
 
4
+ export enum SpawnStatus {
5
+ SUCCESS,
6
+ ERROR,
7
+ }
8
+
4
9
  export interface SpawnResult {
5
- code: number;
6
- signal: NodeJS.Signals | null;
7
- stdout: string;
8
- stderr: string;
10
+ status: SpawnStatus,
11
+ data: string;
9
12
  }
10
13
 
11
14
  type CodifySpawnOptions = {
@@ -19,13 +22,29 @@ export async function codifySpawn(
19
22
  opts?: CodifySpawnOptions,
20
23
  extras?: Record<any, any>,
21
24
  ): Promise<SpawnResult> {
22
- const stdio = isDebug() ? 'inherit' : 'pipe';
23
- return promiseSpawn(
24
- cmd,
25
- args,
26
- { ...opts, stdio, stdioString: true },
27
- extras
28
- );
25
+ try {
26
+ const stdio = isDebug() ? 'inherit' : 'pipe';
27
+ const result = await promiseSpawn(
28
+ cmd,
29
+ args,
30
+ { ...opts, stdio, stdioString: true, shell: true },
31
+ extras
32
+ );
33
+
34
+ const status = (result.code === 0 && !result.stderr)
35
+ ? SpawnStatus.SUCCESS
36
+ : SpawnStatus.ERROR;
37
+
38
+ return {
39
+ status,
40
+ data: status === SpawnStatus.SUCCESS ? result.stdout : result.stderr
41
+ }
42
+ } catch (e) {
43
+ return {
44
+ status: SpawnStatus.ERROR,
45
+ data: e as string,
46
+ }
47
+ }
29
48
  }
30
49
 
31
50
  export function isDebug(): boolean {