codify-plugin-lib 1.0.5 → 1.0.7

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.
@@ -20,7 +20,7 @@ const SupportedRequests = {
20
20
  },
21
21
  'apply': {
22
22
  requestValidator: codify_schemas_1.ApplyRequestDataSchema,
23
- responseValidator: codify_schemas_1.ApplyRequestDataSchema,
23
+ responseValidator: codify_schemas_1.ApplyResponseDataSchema,
24
24
  handler: async (plugin, data) => plugin.apply(data)
25
25
  }
26
26
  };
@@ -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.7",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -13,7 +13,7 @@
13
13
  "dependencies": {
14
14
  "ajv": "^8.12.0",
15
15
  "ajv-formats": "^2.1.1",
16
- "codify-schemas": "1.0.3",
16
+ "codify-schemas": "1.0.5",
17
17
  "@npmcli/promise-spawn": "^7.0.1"
18
18
  },
19
19
  "devDependencies": {
@@ -10,7 +10,7 @@ import {
10
10
  MessageStatus,
11
11
  PlanRequestDataSchema,
12
12
  PlanResponseDataSchema,
13
- ApplyRequestDataSchema
13
+ ApplyRequestDataSchema, ApplyResponseDataSchema
14
14
  } from 'codify-schemas';
15
15
 
16
16
  const SupportedRequests: Record<string, { requestValidator: SchemaObject; responseValidator: SchemaObject; handler: (plugin: Plugin, data: any) => Promise<unknown> }> = {
@@ -26,7 +26,7 @@ const SupportedRequests: Record<string, { requestValidator: SchemaObject; respon
26
26
  },
27
27
  'apply': {
28
28
  requestValidator: ApplyRequestDataSchema,
29
- responseValidator: ApplyRequestDataSchema, // Replace with response validator
29
+ responseValidator: ApplyResponseDataSchema, // Replace with response validator
30
30
  handler: async (plugin: Plugin, data: any) => plugin.apply(data)
31
31
  }
32
32
  }
@@ -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