@oclif/plugin-command-snapshot 3.3.3 → 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.
- package/lib/commands/schema/compare.js +2 -1
- package/lib/commands/schema/generate.js +3 -2
- package/lib/util.d.ts +12 -0
- package/lib/util.js +24 -0
- package/oclif.manifest.json +1 -1
- package/package.json +3 -3
- package/yarn.lock +0 -5969
|
@@ -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(
|
|
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
|
}
|
|
@@ -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 =
|
|
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 =
|
|
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}"`);
|
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;
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oclif/plugin-command-snapshot",
|
|
3
3
|
"description": "generates and compares OCLIF plugins snapshot files",
|
|
4
|
-
"version": "3.3.
|
|
4
|
+
"version": "3.3.4",
|
|
5
5
|
"author": "Salesforce",
|
|
6
6
|
"bugs": "https://github.com/oclif/plugin-command-snapshot/issues",
|
|
7
7
|
"dependencies": {
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"husky": "6",
|
|
30
30
|
"mocha": "^8",
|
|
31
31
|
"nyc": "^15",
|
|
32
|
-
"oclif": "^3.6.
|
|
32
|
+
"oclif": "^3.6.2",
|
|
33
33
|
"sinon": "^11.1.2",
|
|
34
34
|
"ts-node": "^10",
|
|
35
|
-
"typescript": "^4.9.
|
|
35
|
+
"typescript": "^4.9.5"
|
|
36
36
|
},
|
|
37
37
|
"engines": {
|
|
38
38
|
"node": ">=12.0.0"
|