@tsed/cli-core 3.25.0 → 3.26.1

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.
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CliLoadFile = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const di_1 = require("@tsed/di");
6
+ const path_1 = require("path");
7
+ const ajv_1 = tslib_1.__importDefault(require("ajv"));
8
+ const CliYaml_1 = require("./CliYaml");
9
+ const CliFs_1 = require("./CliFs");
10
+ let CliLoadFile = class CliLoadFile {
11
+ cliYaml;
12
+ cliFs;
13
+ #ajv;
14
+ constructor() {
15
+ const options = {
16
+ verbose: false,
17
+ coerceTypes: true,
18
+ strict: false
19
+ };
20
+ this.#ajv = new ajv_1.default(options);
21
+ }
22
+ /**
23
+ * Load a configuration file from yaml, json
24
+ */
25
+ async loadFile(path, schema) {
26
+ let config;
27
+ const ext = (0, path_1.extname)(path);
28
+ if ([".yml", ".yaml"].includes(ext)) {
29
+ config = await this.cliYaml.read(path);
30
+ }
31
+ else if ([".json"].includes(ext)) {
32
+ config = await JSON.parse(await this.cliFs.readFile(path, "utf8"));
33
+ }
34
+ else if (!config) {
35
+ throw new Error("Unsupported format file");
36
+ }
37
+ if (schema) {
38
+ const validate = this.#ajv.compile(schema);
39
+ const isValid = validate(config);
40
+ if (!isValid) {
41
+ const [error] = validate.errors;
42
+ throw new Error([
43
+ `${error.instancePath.replace(/\//gi, ".")} `,
44
+ error.message,
45
+ error.params?.allowedValues && `. Allowed values: ${error.params?.allowedValues}`
46
+ ]
47
+ .filter(Boolean)
48
+ .join(""));
49
+ }
50
+ }
51
+ return config;
52
+ }
53
+ };
54
+ tslib_1.__decorate([
55
+ (0, di_1.Inject)(),
56
+ tslib_1.__metadata("design:type", CliYaml_1.CliYaml)
57
+ ], CliLoadFile.prototype, "cliYaml", void 0);
58
+ tslib_1.__decorate([
59
+ (0, di_1.Inject)(),
60
+ tslib_1.__metadata("design:type", CliFs_1.CliFs)
61
+ ], CliLoadFile.prototype, "cliFs", void 0);
62
+ CliLoadFile = tslib_1.__decorate([
63
+ (0, di_1.Injectable)(),
64
+ tslib_1.__metadata("design:paramtypes", [])
65
+ ], CliLoadFile);
66
+ exports.CliLoadFile = CliLoadFile;
67
+ //# sourceMappingURL=CliLoadFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CliLoadFile.js","sourceRoot":"","sources":["../../../src/services/CliLoadFile.ts"],"names":[],"mappings":";;;;AAAA,iCAA4C;AAC5C,+BAA6B;AAC7B,sDAAgC;AAChC,uCAAkC;AAClC,mCAA8B;AAG9B,IAAa,WAAW,GAAxB,MAAa,WAAW;IAEZ,OAAO,CAAU;IAGjB,KAAK,CAAQ;IAEvB,IAAI,CAAM;IAEV;QACE,MAAM,OAAO,GAAG;YACd,OAAO,EAAE,KAAK;YACd,WAAW,EAAE,IAAI;YACjB,MAAM,EAAE,KAAK;SACd,CAAC;QAEF,IAAI,CAAC,IAAI,GAAG,IAAI,aAAG,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,QAAQ,CAAc,IAAY,EAAE,MAAe;QACvD,IAAI,MAAW,CAAC;QAChB,MAAM,GAAG,GAAG,IAAA,cAAO,EAAC,IAAI,CAAC,CAAC;QAE1B,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YACnC,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SACxC;aAAM,IAAI,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YAClC,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;SACpE;aAAM,IAAI,CAAC,MAAM,EAAE;YAClB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;SAC5C;QAED,IAAI,MAAM,EAAE;YACV,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAE3C,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;YAEjC,IAAI,CAAC,OAAO,EAAE;gBACZ,MAAM,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC,MAAO,CAAC;gBAEjC,MAAM,IAAI,KAAK,CACb;oBACE,GAAG,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG;oBAC7C,KAAK,CAAC,OAAO;oBACb,KAAK,CAAC,MAAM,EAAE,aAAa,IAAI,qBAAqB,KAAK,CAAC,MAAM,EAAE,aAAa,EAAE;iBAClF;qBACE,MAAM,CAAC,OAAO,CAAC;qBACf,IAAI,CAAC,EAAE,CAAC,CACZ,CAAC;aACH;SACF;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF,CAAA;AAtDC;IADC,IAAA,WAAM,GAAE;sCACU,iBAAO;4CAAC;AAG3B;IADC,IAAA,WAAM,GAAE;sCACQ,aAAK;0CAAC;AALZ,WAAW;IADvB,IAAA,eAAU,GAAE;;GACA,WAAW,CAwDvB;AAxDY,kCAAW","sourcesContent":["import {Inject, Injectable} from \"@tsed/di\";\nimport {extname} from \"path\";\nimport Ajv, {Schema} from \"ajv\";\nimport {CliYaml} from \"./CliYaml\";\nimport {CliFs} from \"./CliFs\";\n\n@Injectable()\nexport class CliLoadFile {\n @Inject()\n protected cliYaml: CliYaml;\n\n @Inject()\n protected cliFs: CliFs;\n\n #ajv: Ajv;\n\n constructor() {\n const options = {\n verbose: false,\n coerceTypes: true,\n strict: false\n };\n\n this.#ajv = new Ajv(options);\n }\n\n /**\n * Load a configuration file from yaml, json\n */\n async loadFile<Model = any>(path: string, schema?: Schema): Promise<Model> {\n let config: any;\n const ext = extname(path);\n\n if ([\".yml\", \".yaml\"].includes(ext)) {\n config = await this.cliYaml.read(path);\n } else if ([\".json\"].includes(ext)) {\n config = await JSON.parse(await this.cliFs.readFile(path, \"utf8\"));\n } else if (!config) {\n throw new Error(\"Unsupported format file\");\n }\n\n if (schema) {\n const validate = this.#ajv.compile(schema);\n\n const isValid = validate(config);\n\n if (!isValid) {\n const [error] = validate.errors!;\n\n throw new Error(\n [\n `${error.instancePath.replace(/\\//gi, \".\")} `,\n error.message,\n error.params?.allowedValues && `. Allowed values: ${error.params?.allowedValues}`\n ]\n .filter(Boolean)\n .join(\"\")\n );\n }\n }\n\n return config;\n }\n}\n"]}
@@ -11,6 +11,7 @@ tslib_1.__exportStar(require("./CliFs"), exports);
11
11
  tslib_1.__exportStar(require("./ProjectPackageJson"), exports);
12
12
  tslib_1.__exportStar(require("./Renderer"), exports);
13
13
  tslib_1.__exportStar(require("./CliExeca"), exports);
14
+ tslib_1.__exportStar(require("./CliLoadFile"), exports);
14
15
  tslib_1.__exportStar(require("./CliYaml"), exports);
15
16
  tslib_1.__exportStar(require("./CliDockerComposeYaml"), exports);
16
17
  tslib_1.__exportStar(require("./NpmRegistryClient"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/index.ts"],"names":[],"mappings":";;;AAAA,6DAAmC;AACnC,uDAA6B;AAC7B,2DAAiC;AACjC,0DAAgC;AAChC,uDAA6B;AAC7B,yDAA+B;AAC/B,kDAAwB;AACxB,+DAAqC;AACrC,qDAA2B;AAC3B,qDAA2B;AAC3B,oDAA0B;AAC1B,iEAAuC;AACvC,8DAAoC","sourcesContent":["export * from \"./CliConfiguration\";\nexport * from \"./CliService\";\nexport * from \"./CliPackageJson\";\nexport * from \"./CliHttpClient\";\nexport * from \"./CliPlugins\";\nexport * from \"./CliRunScript\";\nexport * from \"./CliFs\";\nexport * from \"./ProjectPackageJson\";\nexport * from \"./Renderer\";\nexport * from \"./CliExeca\";\nexport * from \"./CliYaml\";\nexport * from \"./CliDockerComposeYaml\";\nexport * from \"./NpmRegistryClient\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/index.ts"],"names":[],"mappings":";;;AAAA,6DAAmC;AACnC,uDAA6B;AAC7B,2DAAiC;AACjC,0DAAgC;AAChC,uDAA6B;AAC7B,yDAA+B;AAC/B,kDAAwB;AACxB,+DAAqC;AACrC,qDAA2B;AAC3B,qDAA2B;AAC3B,wDAA8B;AAC9B,oDAA0B;AAC1B,iEAAuC;AACvC,8DAAoC","sourcesContent":["export * from \"./CliConfiguration\";\nexport * from \"./CliService\";\nexport * from \"./CliPackageJson\";\nexport * from \"./CliHttpClient\";\nexport * from \"./CliPlugins\";\nexport * from \"./CliRunScript\";\nexport * from \"./CliFs\";\nexport * from \"./ProjectPackageJson\";\nexport * from \"./Renderer\";\nexport * from \"./CliExeca\";\nexport * from \"./CliLoadFile\";\nexport * from \"./CliYaml\";\nexport * from \"./CliDockerComposeYaml\";\nexport * from \"./NpmRegistryClient\";\n"]}
@@ -0,0 +1,64 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { Inject, Injectable } from "@tsed/di";
3
+ import { extname } from "path";
4
+ import Ajv from "ajv";
5
+ import { CliYaml } from "./CliYaml.js";
6
+ import { CliFs } from "./CliFs.js";
7
+ let CliLoadFile = class CliLoadFile {
8
+ cliYaml;
9
+ cliFs;
10
+ #ajv;
11
+ constructor() {
12
+ const options = {
13
+ verbose: false,
14
+ coerceTypes: true,
15
+ strict: false
16
+ };
17
+ this.#ajv = new Ajv(options);
18
+ }
19
+ /**
20
+ * Load a configuration file from yaml, json
21
+ */
22
+ async loadFile(path, schema) {
23
+ let config;
24
+ const ext = extname(path);
25
+ if ([".yml", ".yaml"].includes(ext)) {
26
+ config = await this.cliYaml.read(path);
27
+ }
28
+ else if ([".json"].includes(ext)) {
29
+ config = await JSON.parse(await this.cliFs.readFile(path, "utf8"));
30
+ }
31
+ else if (!config) {
32
+ throw new Error("Unsupported format file");
33
+ }
34
+ if (schema) {
35
+ const validate = this.#ajv.compile(schema);
36
+ const isValid = validate(config);
37
+ if (!isValid) {
38
+ const [error] = validate.errors;
39
+ throw new Error([
40
+ `${error.instancePath.replace(/\//gi, ".")} `,
41
+ error.message,
42
+ error.params?.allowedValues && `. Allowed values: ${error.params?.allowedValues}`
43
+ ]
44
+ .filter(Boolean)
45
+ .join(""));
46
+ }
47
+ }
48
+ return config;
49
+ }
50
+ };
51
+ __decorate([
52
+ Inject(),
53
+ __metadata("design:type", CliYaml)
54
+ ], CliLoadFile.prototype, "cliYaml", void 0);
55
+ __decorate([
56
+ Inject(),
57
+ __metadata("design:type", CliFs)
58
+ ], CliLoadFile.prototype, "cliFs", void 0);
59
+ CliLoadFile = __decorate([
60
+ Injectable(),
61
+ __metadata("design:paramtypes", [])
62
+ ], CliLoadFile);
63
+ export { CliLoadFile };
64
+ //# sourceMappingURL=CliLoadFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CliLoadFile.js","sourceRoot":"","sources":["../../../src/services/CliLoadFile.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,MAAM,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAC,OAAO,EAAC,MAAM,MAAM,CAAC;AAC7B,OAAO,GAAa,MAAM,KAAK,CAAC;AAChC,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAClC,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAG9B,IAAa,WAAW,GAAxB,MAAa,WAAW;IAEZ,OAAO,CAAU;IAGjB,KAAK,CAAQ;IAEvB,IAAI,CAAM;IAEV;QACE,MAAM,OAAO,GAAG;YACd,OAAO,EAAE,KAAK;YACd,WAAW,EAAE,IAAI;YACjB,MAAM,EAAE,KAAK;SACd,CAAC;QAEF,IAAI,CAAC,IAAI,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;IAC/B,CAA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,OAAO;4CAAC;AAG3B;IADC,MAAM,EAAE;8BACQ,KAAK;0CAAC;AALZ,WAAW;IADvB,UAAU,EAAE;;GACA,WAAW,CAwDvB;SAxDY,WAAW","sourcesContent":["import {Inject, Injectable} from \"@tsed/di\";\nimport {extname} from \"path\";\nimport Ajv, {Schema} from \"ajv\";\nimport {CliYaml} from \"./CliYaml\";\nimport {CliFs} from \"./CliFs\";\n\n@Injectable()\nexport class CliLoadFile {\n @Inject()\n protected cliYaml: CliYaml;\n\n @Inject()\n protected cliFs: CliFs;\n\n #ajv: Ajv;\n\n constructor() {\n const options = {\n verbose: false,\n coerceTypes: true,\n strict: false\n };\n\n this.#ajv = new Ajv(options);\n }\n\n /**\n * Load a configuration file from yaml, json\n */\n async loadFile<Model = any>(path: string, schema?: Schema): Promise<Model> {\n let config: any;\n const ext = extname(path);\n\n if ([\".yml\", \".yaml\"].includes(ext)) {\n config = await this.cliYaml.read(path);\n } else if ([\".json\"].includes(ext)) {\n config = await JSON.parse(await this.cliFs.readFile(path, \"utf8\"));\n } else if (!config) {\n throw new Error(\"Unsupported format file\");\n }\n\n if (schema) {\n const validate = this.#ajv.compile(schema);\n\n const isValid = validate(config);\n\n if (!isValid) {\n const [error] = validate.errors!;\n\n throw new Error(\n [\n `${error.instancePath.replace(/\\//gi, \".\")} `,\n error.message,\n error.params?.allowedValues && `. Allowed values: ${error.params?.allowedValues}`\n ]\n .filter(Boolean)\n .join(\"\")\n );\n }\n }\n\n return config;\n }\n}\n"]}
@@ -8,6 +8,7 @@ export * from "./CliFs.js";
8
8
  export * from "./ProjectPackageJson.js";
9
9
  export * from "./Renderer.js";
10
10
  export * from "./CliExeca.js";
11
+ export * from "./CliLoadFile.js";
11
12
  export * from "./CliYaml.js";
12
13
  export * from "./CliDockerComposeYaml.js";
13
14
  export * from "./NpmRegistryClient.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC","sourcesContent":["export * from \"./CliConfiguration\";\nexport * from \"./CliService\";\nexport * from \"./CliPackageJson\";\nexport * from \"./CliHttpClient\";\nexport * from \"./CliPlugins\";\nexport * from \"./CliRunScript\";\nexport * from \"./CliFs\";\nexport * from \"./ProjectPackageJson\";\nexport * from \"./Renderer\";\nexport * from \"./CliExeca\";\nexport * from \"./CliYaml\";\nexport * from \"./CliDockerComposeYaml\";\nexport * from \"./NpmRegistryClient\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC","sourcesContent":["export * from \"./CliConfiguration\";\nexport * from \"./CliService\";\nexport * from \"./CliPackageJson\";\nexport * from \"./CliHttpClient\";\nexport * from \"./CliPlugins\";\nexport * from \"./CliRunScript\";\nexport * from \"./CliFs\";\nexport * from \"./ProjectPackageJson\";\nexport * from \"./Renderer\";\nexport * from \"./CliExeca\";\nexport * from \"./CliLoadFile\";\nexport * from \"./CliYaml\";\nexport * from \"./CliDockerComposeYaml\";\nexport * from \"./NpmRegistryClient\";\n"]}
@@ -0,0 +1,13 @@
1
+ import { Schema } from "ajv";
2
+ import { CliYaml } from "./CliYaml";
3
+ import { CliFs } from "./CliFs";
4
+ export declare class CliLoadFile {
5
+ #private;
6
+ protected cliYaml: CliYaml;
7
+ protected cliFs: CliFs;
8
+ constructor();
9
+ /**
10
+ * Load a configuration file from yaml, json
11
+ */
12
+ loadFile<Model = any>(path: string, schema?: Schema): Promise<Model>;
13
+ }
@@ -8,6 +8,7 @@ export * from "./CliFs";
8
8
  export * from "./ProjectPackageJson";
9
9
  export * from "./Renderer";
10
10
  export * from "./CliExeca";
11
+ export * from "./CliLoadFile";
11
12
  export * from "./CliYaml";
12
13
  export * from "./CliDockerComposeYaml";
13
14
  export * from "./NpmRegistryClient";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/cli-core",
3
- "version": "3.25.0",
3
+ "version": "3.26.1",
4
4
  "description": "Build your CLI with TypeScript and Decorators",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./lib/cjs/index.js",
@@ -30,6 +30,7 @@
30
30
  "dependencies": {
31
31
  "@npmcli/run-script": "3.0.1",
32
32
  "@tsed/logger": ">=6.1.1",
33
+ "ajv": "8.11.0",
33
34
  "axios": "0.26.1",
34
35
  "chalk": "4.1.2",
35
36
  "change-case": "^4.1.2",
@@ -8,5 +8,7 @@
8
8
  "declaration": true,
9
9
  "declarationDir": "./lib/types"
10
10
  },
11
- "exclude": ["node_modules", "test", "lib", "coverage", ".nyc_output", "**/*.spec.ts", "jest.config.js"]
11
+ "exclude": ["node_modules", "test", "lib", "coverage", ".nyc_output", "**/*.spec.ts",
12
+ "jest.config.js"
13
+ ]
12
14
  }