ts-runtime-validation 1.6.8 → 1.6.9
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/package.json +1 -1
- package/src/ICommandOptions.ts +8 -0
- package/src/SchemaGenerator.test.ts +2 -2
- package/src/SchemaGenerator.ts +9 -8
- package/src/getPosixPath.ts +6 -0
- package/src/index.ts +1 -9
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
|
-
import { ICommandOptions } from "./
|
|
3
|
+
import { ICommandOptions } from "./ICommandOptions";
|
|
4
4
|
import { SchemaGenerator } from "./SchemaGenerator";
|
|
5
5
|
|
|
6
6
|
const cleanupTestOutput = () => {
|
|
7
|
-
const outputDir = path.resolve(__dirname, "./test/output");
|
|
7
|
+
const outputDir = path.posix.resolve(__dirname, "./test/output");
|
|
8
8
|
const doesDirectoryExist = fs.existsSync(outputDir);
|
|
9
9
|
if (doesDirectoryExist) {
|
|
10
10
|
fs.rmSync(outputDir, { recursive: true });
|
package/src/SchemaGenerator.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { fdir } from "fdir";
|
|
2
|
-
import { ICommandOptions } from "./
|
|
2
|
+
import { ICommandOptions } from "./ICommandOptions";
|
|
3
3
|
import fs from "fs";
|
|
4
4
|
import picomatch from "picomatch";
|
|
5
5
|
import path from "path";
|
|
@@ -18,6 +18,7 @@ import * as tsj from "ts-json-schema-generator";
|
|
|
18
18
|
import { Config, Schema } from "ts-json-schema-generator";
|
|
19
19
|
import assert from "assert";
|
|
20
20
|
import { writeLine } from "./writeLine";
|
|
21
|
+
import { getPosixPath } from "./getPosixPath";
|
|
21
22
|
|
|
22
23
|
const defaultTsMorphProjectSettings: ProjectOptions = {
|
|
23
24
|
manipulationSettings: {
|
|
@@ -74,7 +75,7 @@ export class SchemaGenerator {
|
|
|
74
75
|
|
|
75
76
|
private getMatchingFiles = async () => {
|
|
76
77
|
const { glob, rootPath } = this.options;
|
|
77
|
-
const api = new fdir(
|
|
78
|
+
const api = new fdir({
|
|
78
79
|
includeBasePath: true,
|
|
79
80
|
includeDirs: false,
|
|
80
81
|
filters: [
|
|
@@ -82,8 +83,8 @@ export class SchemaGenerator {
|
|
|
82
83
|
return picomatch.isMatch(path, glob, { contains: true });
|
|
83
84
|
},
|
|
84
85
|
],
|
|
85
|
-
});
|
|
86
|
-
return api.withPromise()
|
|
86
|
+
}).crawl(rootPath);
|
|
87
|
+
return api.withPromise();
|
|
87
88
|
};
|
|
88
89
|
|
|
89
90
|
private getJsonSchemasForFiles = async (filesList: Array<string>) => {
|
|
@@ -163,7 +164,7 @@ export class SchemaGenerator {
|
|
|
163
164
|
const dir = path.dirname(filePath);
|
|
164
165
|
const fileWithoutExtension = path.parse(filePath).name;
|
|
165
166
|
const relativeFilePath = path.relative(this.outputPath, dir);
|
|
166
|
-
const
|
|
167
|
+
const relativeImportPath = `${relativeFilePath}/${fileWithoutExtension}`;
|
|
167
168
|
const defs = schema.definitions ?? {};
|
|
168
169
|
|
|
169
170
|
const readerSourceFile = readerProject.addSourceFileAtPath(filePath);
|
|
@@ -173,9 +174,9 @@ export class SchemaGenerator {
|
|
|
173
174
|
const typeInterface = readerSourceFile.getInterface(symbol);
|
|
174
175
|
const hasTypeOrInterface = (typeAlias ?? typeInterface) !== undefined;
|
|
175
176
|
if (hasTypeOrInterface) {
|
|
176
|
-
const namedImports = importMap.get(
|
|
177
|
+
const namedImports = importMap.get(relativeImportPath) ?? [];
|
|
177
178
|
namedImports.push(symbol);
|
|
178
|
-
importMap.set(
|
|
179
|
+
importMap.set(relativeImportPath, namedImports);
|
|
179
180
|
symbols.push(symbol);
|
|
180
181
|
}
|
|
181
182
|
});
|
|
@@ -184,7 +185,7 @@ export class SchemaGenerator {
|
|
|
184
185
|
const sourceFile = project.createSourceFile(this.tsSchemaDefinitionOutputFile, {}, defaultCreateFileOptions);
|
|
185
186
|
|
|
186
187
|
importMap.forEach((namedImports, importPath) => {
|
|
187
|
-
sourceFile.addImportDeclaration({ namedImports, moduleSpecifier: importPath });
|
|
188
|
+
sourceFile.addImportDeclaration({ namedImports, moduleSpecifier: getPosixPath(importPath) });
|
|
188
189
|
});
|
|
189
190
|
|
|
190
191
|
sourceFile.addVariableStatement({
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
import { ICommandOptions } from "./ICommandOptions";
|
|
3
4
|
import { SchemaGenerator } from "./SchemaGenerator";
|
|
4
5
|
import { program } from "commander";
|
|
5
6
|
|
|
@@ -9,15 +10,6 @@ const defaultRootPath = "./src";
|
|
|
9
10
|
const defaultOutputFolder = "./.ts-runtime-validation";
|
|
10
11
|
const defaultTsconfig = "";
|
|
11
12
|
|
|
12
|
-
export interface ICommandOptions {
|
|
13
|
-
readonly glob: string;
|
|
14
|
-
readonly rootPath: string;
|
|
15
|
-
readonly output: string;
|
|
16
|
-
readonly helpers: boolean;
|
|
17
|
-
readonly additionalProperties: boolean;
|
|
18
|
-
readonly tsconfigPath: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
13
|
program.option(
|
|
22
14
|
"--glob",
|
|
23
15
|
`Glob file path of typescript files to generate ts-interface -> json-schema validations - default: ${defaultGlobPattern}`,
|