codify-plugin-lib 1.0.5 → 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,15 +3,30 @@ 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
14
  try {
10
15
  const stdio = isDebug() ? 'inherit' : 'pipe';
11
- return await (0, promise_spawn_1.default)(cmd, args, { ...opts, stdio, stdioString: true }, extras);
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
+ };
12
24
  }
13
25
  catch (e) {
14
- return e;
26
+ return {
27
+ status: SpawnStatus.ERROR,
28
+ data: e,
29
+ };
15
30
  }
16
31
  }
17
32
  exports.codifySpawn = codifySpawn;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codify-plugin-lib",
3
- "version": "1.0.5",
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 = {
@@ -21,14 +24,26 @@ export async function codifySpawn(
21
24
  ): Promise<SpawnResult> {
22
25
  try {
23
26
  const stdio = isDebug() ? 'inherit' : 'pipe';
24
- return await promiseSpawn(
27
+ const result = await promiseSpawn(
25
28
  cmd,
26
29
  args,
27
- { ...opts, stdio, stdioString: true },
30
+ { ...opts, stdio, stdioString: true, shell: true },
28
31
  extras
29
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
+ }
30
42
  } catch (e) {
31
- return e as any;
43
+ return {
44
+ status: SpawnStatus.ERROR,
45
+ data: e as string,
46
+ }
32
47
  }
33
48
  }
34
49