@oclif/plugin-command-snapshot 3.3.2 → 3.3.4

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.
@@ -7,7 +7,7 @@ export type SchemaComparison = Array<{
7
7
  }>;
8
8
  export default class SchemaCompare extends SnapshotCommand {
9
9
  static flags: {
10
- filepath: import("@oclif/core/lib/interfaces").OptionFlag<string, Record<string, unknown>>;
10
+ filepath: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
11
11
  };
12
12
  run(): Promise<SchemaComparison>;
13
13
  private readExistingSchema;
@@ -9,6 +9,7 @@ const core_1 = require("@oclif/core");
9
9
  const snapshot_command_1 = require("../../snapshot-command");
10
10
  const generate_1 = require("./generate");
11
11
  const chalk_1 = require("chalk");
12
+ const util_1 = require("../../util");
12
13
  function isNumber(n) {
13
14
  return Number.isInteger(Number(n));
14
15
  }
@@ -98,7 +99,7 @@ class SchemaCompare extends snapshot_command_1.SnapshotCommand {
98
99
  else {
99
100
  for (const file of schemaFiles) {
100
101
  const schema = JSON.parse(fs.readFileSync(file).toString('utf8'));
101
- const key = path.basename(file.replace(/-/g, ':')).replace('.json', '');
102
+ const key = path.basename((0, util_1.getKeyNameFromFilename)(file));
102
103
  if (file.split(path.sep).includes('hooks')) {
103
104
  schemas.hooks[key] = schema;
104
105
  }
@@ -37,7 +37,7 @@ export declare class SchemaGenerator {
37
37
  }
38
38
  export default class SchemaGenerate extends SnapshotCommand {
39
39
  static flags: {
40
- filepath: import("@oclif/core/lib/interfaces").OptionFlag<string, Record<string, unknown>>;
40
+ filepath: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
41
41
  singlefile: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
42
42
  ignorevoid: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
43
43
  };
@@ -7,6 +7,7 @@ const core_1 = require("@oclif/core");
7
7
  const ts_json_schema_generator_1 = require("ts-json-schema-generator");
8
8
  const snapshot_command_1 = require("../../snapshot-command");
9
9
  const chalk_1 = require("chalk");
10
+ const util_1 = require("../../util");
10
11
  function getAllFiles(dirPath, ext, allFiles = []) {
11
12
  let files = [];
12
13
  try {
@@ -180,7 +181,7 @@ class SchemaGenerate extends snapshot_command_1.SnapshotCommand {
180
181
  }
181
182
  else {
182
183
  for (const [cmdId, schema] of Object.entries(schemas.commands)) {
183
- const fileName = `${cmdId.replace(/:/g, '-')}.json`;
184
+ const fileName = (0, util_1.getSchemaFileName)(cmdId);
184
185
  const filePath = path.join(directory, fileName);
185
186
  fs.writeFileSync(filePath, JSON.stringify(schema, null, 2));
186
187
  this.log(`Generated JSON schema file "${filePath}"`);
@@ -190,7 +191,7 @@ class SchemaGenerate extends snapshot_command_1.SnapshotCommand {
190
191
  const hooksDir = path.join(directory, 'hooks');
191
192
  fs.mkdirSync(hooksDir, { recursive: true });
192
193
  for (const [hookId, schema] of Object.entries(schemas.hooks)) {
193
- const fileName = `${hookId.replace(/:/g, '-')}.json`;
194
+ const fileName = (0, util_1.getSchemaFileName)(hookId);
194
195
  const filePath = path.join(hooksDir, fileName);
195
196
  fs.writeFileSync(filePath, JSON.stringify(schema, null, 2));
196
197
  this.log(`Generated JSON schema file "${filePath}"`);
@@ -17,7 +17,7 @@ export type CompareResponse = {
17
17
  };
18
18
  export default class Compare extends SnapshotCommand {
19
19
  static flags: {
20
- filepath: import("@oclif/core/lib/interfaces").OptionFlag<string, Record<string, unknown>>;
20
+ filepath: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
21
21
  };
22
22
  /**
23
23
  * Compare a snapshot with the current commands
@@ -2,7 +2,7 @@ import { SnapshotCommand, SnapshotEntry } from '../../snapshot-command';
2
2
  export type Snapshots = SnapshotEntry[];
3
3
  export default class Generate extends SnapshotCommand {
4
4
  static flags: {
5
- filepath: import("@oclif/core/lib/interfaces").OptionFlag<string, Record<string, unknown>>;
5
+ filepath: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
6
6
  };
7
7
  run(): Promise<Snapshots>;
8
8
  }
package/lib/util.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Get the file name for a given command ID replacing "-" with "__" and ":" with "-"
3
+ * @param cmdId - command ID
4
+ * @returns {string} - file name
5
+ */
6
+ export declare const getSchemaFileName: (cmdId: string) => string;
7
+ /**
8
+ * Get the command ID from a given file name replacing "-" with ":" and "__" with "-"
9
+ * @param file - file name
10
+ * @returns {string} - command ID
11
+ */
12
+ export declare const getKeyNameFromFilename: (file: string) => string;
package/lib/util.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getKeyNameFromFilename = exports.getSchemaFileName = void 0;
4
+ /**
5
+ * Get the file name for a given command ID replacing "-" with "__" and ":" with "-"
6
+ * @param cmdId - command ID
7
+ * @returns {string} - file name
8
+ */
9
+ const getSchemaFileName = (cmdId) => {
10
+ const baseName = cmdId.replace(/-/g, '__').replace(/:/g, '-');
11
+ return `${baseName}.json`;
12
+ };
13
+ exports.getSchemaFileName = getSchemaFileName;
14
+ /**
15
+ * Get the command ID from a given file name replacing "-" with ":" and "__" with "-"
16
+ * @param file - file name
17
+ * @returns {string} - command ID
18
+ */
19
+ const getKeyNameFromFilename = (file) => {
20
+ return file.replace(/-/g, ':')
21
+ .replace(/__/g, '-')
22
+ .replace('.json', '');
23
+ };
24
+ exports.getKeyNameFromFilename = getKeyNameFromFilename;
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "3.3.2",
2
+ "version": "3.3.4",
3
3
  "commands": {
4
4
  "schema:compare": {
5
5
  "id": "schema:compare",
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@oclif/plugin-command-snapshot",
3
3
  "description": "generates and compares OCLIF plugins snapshot files",
4
- "version": "3.3.2",
4
+ "version": "3.3.4",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/plugin-command-snapshot/issues",
7
7
  "dependencies": {
8
- "@oclif/core": "^2.0.3",
8
+ "@oclif/core": "^2.0.8",
9
9
  "chalk": "^4.1.2",
10
10
  "just-diff": "^5.2.0",
11
11
  "lodash": "^4.17.21",
@@ -15,8 +15,8 @@
15
15
  },
16
16
  "devDependencies": {
17
17
  "@commitlint/config-conventional": "^12.1.4",
18
- "@oclif/plugin-help": "^5.1.22",
19
- "@oclif/test": "^2.3.0",
18
+ "@oclif/plugin-help": "^5.2.2",
19
+ "@oclif/test": "^2.3.4",
20
20
  "@types/chai": "^4.3.4",
21
21
  "@types/mocha": "^8",
22
22
  "@types/node": "^15",
@@ -29,10 +29,10 @@
29
29
  "husky": "6",
30
30
  "mocha": "^8",
31
31
  "nyc": "^15",
32
- "oclif": "^3.6.0",
32
+ "oclif": "^3.6.2",
33
33
  "sinon": "^11.1.2",
34
34
  "ts-node": "^10",
35
- "typescript": "^4.9.4"
35
+ "typescript": "^4.9.5"
36
36
  },
37
37
  "engines": {
38
38
  "node": ">=12.0.0"