@twin.org/ts-to-schema 0.0.1-next.21 → 0.0.1-next.23
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/dist/cjs/index.cjs +24 -42
- package/dist/esm/index.mjs +24 -42
- package/dist/locales/en.json +1 -2
- package/dist/types/models/ITsToSchemaConfig.d.ts +1 -5
- package/docs/changelog.md +41 -0
- package/docs/reference/interfaces/ITsToSchemaConfig.md +1 -9
- package/locales/en.json +1 -2
- package/package.json +2 -2
package/dist/cjs/index.cjs
CHANGED
|
@@ -76,11 +76,13 @@ async function tsToSchema(config, outputFolder, workingDirectory) {
|
|
|
76
76
|
await promises.writeFile(path.join(workingDirectory, "tsconfig.json"), JSON.stringify({
|
|
77
77
|
compilerOptions: {}
|
|
78
78
|
}, undefined, "\t"));
|
|
79
|
-
cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.ts-to-schema.progress.generatingSchemas"));
|
|
80
|
-
const schemas = await generateSchemas(config.sources, config.types, workingDirectory);
|
|
81
79
|
cliCore.CLIDisplay.break();
|
|
82
80
|
cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.ts-to-schema.progress.writingSchemas"));
|
|
83
|
-
for (const
|
|
81
|
+
for (const typeSource of config.types) {
|
|
82
|
+
cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.ts-to-schema.progress.generatingSchema"));
|
|
83
|
+
const typeSourceParts = typeSource.split("/");
|
|
84
|
+
const type = core.StringHelper.pascalCase(typeSourceParts[typeSourceParts.length - 1].replace(/(\.d)?\.ts$/, ""), false);
|
|
85
|
+
const schemas = await generateSchemas(typeSource, type, workingDirectory);
|
|
84
86
|
if (core.Is.empty(schemas[type])) {
|
|
85
87
|
throw new core.GeneralError("commands", "commands.ts-to-schema.schemaNotFound", { type });
|
|
86
88
|
}
|
|
@@ -107,48 +109,28 @@ async function tsToSchema(config, outputFolder, workingDirectory) {
|
|
|
107
109
|
* @returns Nothing.
|
|
108
110
|
* @internal
|
|
109
111
|
*/
|
|
110
|
-
async function generateSchemas(
|
|
112
|
+
async function generateSchemas(typeSource, type, outputWorkingDir) {
|
|
111
113
|
const allSchemas = {};
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
skipTypeCheck: true,
|
|
129
|
-
expose: "all"
|
|
130
|
-
});
|
|
131
|
-
const schema = generator.createSchema("*");
|
|
132
|
-
if (schema.definitions) {
|
|
133
|
-
for (const def in schema.definitions) {
|
|
134
|
-
// Remove the partial markers
|
|
135
|
-
let defSub = def.replace(/^Partial<(.*?)>/g, "$1");
|
|
136
|
-
// Cleanup the generic markers
|
|
137
|
-
defSub = defSub.replace(/</g, "%3C").replace(/>/g, "%3E");
|
|
138
|
-
allSchemas[defSub] = schema.definitions[def];
|
|
139
|
-
}
|
|
114
|
+
cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.ts-to-schema.progress.models"), typeSource, 1);
|
|
115
|
+
const generator = tsJsonSchemaGenerator.createGenerator({
|
|
116
|
+
path: typeSource,
|
|
117
|
+
type,
|
|
118
|
+
tsconfig: path.join(outputWorkingDir, "tsconfig.json"),
|
|
119
|
+
skipTypeCheck: true,
|
|
120
|
+
expose: "all"
|
|
121
|
+
});
|
|
122
|
+
const schema = generator.createSchema("*");
|
|
123
|
+
if (schema.definitions) {
|
|
124
|
+
for (const def in schema.definitions) {
|
|
125
|
+
// Remove the partial markers
|
|
126
|
+
let defSub = def.replace(/^Partial<(.*?)>/g, "$1");
|
|
127
|
+
// Cleanup the generic markers
|
|
128
|
+
defSub = defSub.replace(/</g, "%3C").replace(/>/g, "%3E");
|
|
129
|
+
allSchemas[defSub] = schema.definitions[def];
|
|
140
130
|
}
|
|
141
131
|
}
|
|
142
132
|
const referencedSchemas = {};
|
|
143
|
-
extractTypes(allSchemas,
|
|
144
|
-
for (const arraySingularType of arraySingularTypes) {
|
|
145
|
-
referencedSchemas[`${arraySingularType}[]`] = {
|
|
146
|
-
type: "array",
|
|
147
|
-
items: {
|
|
148
|
-
$ref: `#/components/schemas/${arraySingularType}`
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
}
|
|
133
|
+
extractTypes(allSchemas, [type], referencedSchemas);
|
|
152
134
|
return referencedSchemas;
|
|
153
135
|
}
|
|
154
136
|
/**
|
|
@@ -238,7 +220,7 @@ class CLI extends cliCore.CLIBase {
|
|
|
238
220
|
return this.execute({
|
|
239
221
|
title: "TWIN TypeScript To Schema",
|
|
240
222
|
appName: "ts-to-schema",
|
|
241
|
-
version: "0.0.1-next.
|
|
223
|
+
version: "0.0.1-next.23", // x-release-please-version
|
|
242
224
|
icon: "⚙️ ",
|
|
243
225
|
supportsEnvFiles: false,
|
|
244
226
|
overrideOutputWidth: options?.overrideOutputWidth
|
package/dist/esm/index.mjs
CHANGED
|
@@ -73,11 +73,13 @@ async function tsToSchema(config, outputFolder, workingDirectory) {
|
|
|
73
73
|
await writeFile(path.join(workingDirectory, "tsconfig.json"), JSON.stringify({
|
|
74
74
|
compilerOptions: {}
|
|
75
75
|
}, undefined, "\t"));
|
|
76
|
-
CLIDisplay.task(I18n.formatMessage("commands.ts-to-schema.progress.generatingSchemas"));
|
|
77
|
-
const schemas = await generateSchemas(config.sources, config.types, workingDirectory);
|
|
78
76
|
CLIDisplay.break();
|
|
79
77
|
CLIDisplay.task(I18n.formatMessage("commands.ts-to-schema.progress.writingSchemas"));
|
|
80
|
-
for (const
|
|
78
|
+
for (const typeSource of config.types) {
|
|
79
|
+
CLIDisplay.task(I18n.formatMessage("commands.ts-to-schema.progress.generatingSchema"));
|
|
80
|
+
const typeSourceParts = typeSource.split("/");
|
|
81
|
+
const type = StringHelper.pascalCase(typeSourceParts[typeSourceParts.length - 1].replace(/(\.d)?\.ts$/, ""), false);
|
|
82
|
+
const schemas = await generateSchemas(typeSource, type, workingDirectory);
|
|
81
83
|
if (Is.empty(schemas[type])) {
|
|
82
84
|
throw new GeneralError("commands", "commands.ts-to-schema.schemaNotFound", { type });
|
|
83
85
|
}
|
|
@@ -104,48 +106,28 @@ async function tsToSchema(config, outputFolder, workingDirectory) {
|
|
|
104
106
|
* @returns Nothing.
|
|
105
107
|
* @internal
|
|
106
108
|
*/
|
|
107
|
-
async function generateSchemas(
|
|
109
|
+
async function generateSchemas(typeSource, type, outputWorkingDir) {
|
|
108
110
|
const allSchemas = {};
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
skipTypeCheck: true,
|
|
126
|
-
expose: "all"
|
|
127
|
-
});
|
|
128
|
-
const schema = generator.createSchema("*");
|
|
129
|
-
if (schema.definitions) {
|
|
130
|
-
for (const def in schema.definitions) {
|
|
131
|
-
// Remove the partial markers
|
|
132
|
-
let defSub = def.replace(/^Partial<(.*?)>/g, "$1");
|
|
133
|
-
// Cleanup the generic markers
|
|
134
|
-
defSub = defSub.replace(/</g, "%3C").replace(/>/g, "%3E");
|
|
135
|
-
allSchemas[defSub] = schema.definitions[def];
|
|
136
|
-
}
|
|
111
|
+
CLIDisplay.value(I18n.formatMessage("commands.ts-to-schema.progress.models"), typeSource, 1);
|
|
112
|
+
const generator = createGenerator({
|
|
113
|
+
path: typeSource,
|
|
114
|
+
type,
|
|
115
|
+
tsconfig: path.join(outputWorkingDir, "tsconfig.json"),
|
|
116
|
+
skipTypeCheck: true,
|
|
117
|
+
expose: "all"
|
|
118
|
+
});
|
|
119
|
+
const schema = generator.createSchema("*");
|
|
120
|
+
if (schema.definitions) {
|
|
121
|
+
for (const def in schema.definitions) {
|
|
122
|
+
// Remove the partial markers
|
|
123
|
+
let defSub = def.replace(/^Partial<(.*?)>/g, "$1");
|
|
124
|
+
// Cleanup the generic markers
|
|
125
|
+
defSub = defSub.replace(/</g, "%3C").replace(/>/g, "%3E");
|
|
126
|
+
allSchemas[defSub] = schema.definitions[def];
|
|
137
127
|
}
|
|
138
128
|
}
|
|
139
129
|
const referencedSchemas = {};
|
|
140
|
-
extractTypes(allSchemas,
|
|
141
|
-
for (const arraySingularType of arraySingularTypes) {
|
|
142
|
-
referencedSchemas[`${arraySingularType}[]`] = {
|
|
143
|
-
type: "array",
|
|
144
|
-
items: {
|
|
145
|
-
$ref: `#/components/schemas/${arraySingularType}`
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
}
|
|
130
|
+
extractTypes(allSchemas, [type], referencedSchemas);
|
|
149
131
|
return referencedSchemas;
|
|
150
132
|
}
|
|
151
133
|
/**
|
|
@@ -235,7 +217,7 @@ class CLI extends CLIBase {
|
|
|
235
217
|
return this.execute({
|
|
236
218
|
title: "TWIN TypeScript To Schema",
|
|
237
219
|
appName: "ts-to-schema",
|
|
238
|
-
version: "0.0.1-next.
|
|
220
|
+
version: "0.0.1-next.23", // x-release-please-version
|
|
239
221
|
icon: "⚙️ ",
|
|
240
222
|
supportsEnvFiles: false,
|
|
241
223
|
overrideOutputWidth: options?.overrideOutputWidth
|
package/dist/locales/en.json
CHANGED
|
@@ -249,8 +249,7 @@
|
|
|
249
249
|
"progress": {
|
|
250
250
|
"loadingConfigJson": "Loading Config JSON",
|
|
251
251
|
"creatingWorkingDir": "Creating Working Directory",
|
|
252
|
-
"
|
|
253
|
-
"finalisingSchemas": "Finalising Schemas",
|
|
252
|
+
"generatingSchema": "Generating Schema",
|
|
254
253
|
"writingSchemas": "Writing Schemas",
|
|
255
254
|
"writingSchema": "Writing Schema",
|
|
256
255
|
"models": "Models"
|
|
@@ -7,11 +7,7 @@ export interface ITsToSchemaConfig {
|
|
|
7
7
|
*/
|
|
8
8
|
baseUrl: string;
|
|
9
9
|
/**
|
|
10
|
-
* The
|
|
11
|
-
*/
|
|
12
|
-
sources: string[];
|
|
13
|
-
/**
|
|
14
|
-
* The list of types to generate.
|
|
10
|
+
* The source files to generate the types from.
|
|
15
11
|
*/
|
|
16
12
|
types: string[];
|
|
17
13
|
/**
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
# @twin.org/ts-to-schema - Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.1-next.23](https://github.com/twinfoundation/tools/compare/ts-to-schema-v0.0.1-next.22...ts-to-schema-v0.0.1-next.23) (2025-06-03)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Miscellaneous Chores
|
|
7
|
+
|
|
8
|
+
* **ts-to-schema:** Synchronize repo versions
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @twin.org/nameof bumped from 0.0.1-next.22 to 0.0.1-next.23
|
|
16
|
+
* devDependencies
|
|
17
|
+
* @twin.org/merge-locales bumped from 0.0.1-next.22 to 0.0.1-next.23
|
|
18
|
+
* @twin.org/nameof-transformer bumped from 0.0.1-next.22 to 0.0.1-next.23
|
|
19
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.1-next.22 to 0.0.1-next.23
|
|
20
|
+
|
|
21
|
+
## [0.0.1-next.22](https://github.com/twinfoundation/tools/compare/ts-to-schema-v0.0.1-next.21...ts-to-schema-v0.0.1-next.22) (2025-06-03)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Features
|
|
25
|
+
|
|
26
|
+
* generate schemas as individual entities ([9f372ab](https://github.com/twinfoundation/tools/commit/9f372abdfc27aba93b303c7b214991919c0c18c3))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Bug Fixes
|
|
30
|
+
|
|
31
|
+
* remove debugging ([4def3d1](https://github.com/twinfoundation/tools/commit/4def3d1ef6a41a3b3358f864214e6a7ec3f9c638))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
### Dependencies
|
|
35
|
+
|
|
36
|
+
* The following workspace dependencies were updated
|
|
37
|
+
* dependencies
|
|
38
|
+
* @twin.org/nameof bumped from 0.0.1-next.21 to 0.0.1-next.22
|
|
39
|
+
* devDependencies
|
|
40
|
+
* @twin.org/merge-locales bumped from 0.0.1-next.21 to 0.0.1-next.22
|
|
41
|
+
* @twin.org/nameof-transformer bumped from 0.0.1-next.21 to 0.0.1-next.22
|
|
42
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.1-next.21 to 0.0.1-next.22
|
|
43
|
+
|
|
3
44
|
## [0.0.1-next.21](https://github.com/twinfoundation/tools/compare/ts-to-schema-v0.0.1-next.20...ts-to-schema-v0.0.1-next.21) (2025-04-17)
|
|
4
45
|
|
|
5
46
|
|
|
@@ -12,19 +12,11 @@ The base url for the type references e.g. https://schema.twindev.org/my-namespac
|
|
|
12
12
|
|
|
13
13
|
***
|
|
14
14
|
|
|
15
|
-
### sources
|
|
16
|
-
|
|
17
|
-
> **sources**: `string`[]
|
|
18
|
-
|
|
19
|
-
The list of glob sources that can be used to generate the schemas.
|
|
20
|
-
|
|
21
|
-
***
|
|
22
|
-
|
|
23
15
|
### types
|
|
24
16
|
|
|
25
17
|
> **types**: `string`[]
|
|
26
18
|
|
|
27
|
-
The
|
|
19
|
+
The source files to generate the types from.
|
|
28
20
|
|
|
29
21
|
***
|
|
30
22
|
|
package/locales/en.json
CHANGED
|
@@ -22,8 +22,7 @@
|
|
|
22
22
|
"progress": {
|
|
23
23
|
"loadingConfigJson": "Loading Config JSON",
|
|
24
24
|
"creatingWorkingDir": "Creating Working Directory",
|
|
25
|
-
"
|
|
26
|
-
"finalisingSchemas": "Finalising Schemas",
|
|
25
|
+
"generatingSchema": "Generating Schema",
|
|
27
26
|
"writingSchemas": "Writing Schemas",
|
|
28
27
|
"writingSchema": "Writing Schema",
|
|
29
28
|
"models": "Models"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/ts-to-schema",
|
|
3
|
-
"version": "0.0.1-next.
|
|
3
|
+
"version": "0.0.1-next.23",
|
|
4
4
|
"description": "Tool to convert TypeScript definitions to JSON schemas",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@twin.org/cli-core": "next",
|
|
18
18
|
"@twin.org/core": "next",
|
|
19
|
-
"@twin.org/nameof": "0.0.1-next.
|
|
19
|
+
"@twin.org/nameof": "0.0.1-next.23",
|
|
20
20
|
"commander": "13.1.0",
|
|
21
21
|
"glob": "11.0.1",
|
|
22
22
|
"jsonschema": "1.5.0",
|