@twin.org/ts-to-schema 0.0.1-next.20 → 0.0.1-next.22

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.
@@ -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 type of config.types) {
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(modelDirWildcards, types, outputWorkingDir) {
112
+ async function generateSchemas(typeSource, type, outputWorkingDir) {
111
113
  const allSchemas = {};
112
- const arraySingularTypes = [];
113
- for (const type of types) {
114
- if (type.endsWith("[]")) {
115
- const singularType = type.slice(0, -2);
116
- arraySingularTypes.push(singularType);
117
- if (!types.includes(singularType)) {
118
- types.push(singularType);
119
- }
120
- }
121
- }
122
- for (const files of modelDirWildcards) {
123
- cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.ts-to-schema.progress.models"), files.replace(/\\/g, "/"), 1);
124
- const generator = tsJsonSchemaGenerator.createGenerator({
125
- path: files.replace(/\\/g, "/"),
126
- type: "*",
127
- tsconfig: path.join(outputWorkingDir, "tsconfig.json"),
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, types, referencedSchemas);
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.20", // x-release-please-version
223
+ version: "0.0.1-next.22", // x-release-please-version
242
224
  icon: "⚙️ ",
243
225
  supportsEnvFiles: false,
244
226
  overrideOutputWidth: options?.overrideOutputWidth
@@ -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 type of config.types) {
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(modelDirWildcards, types, outputWorkingDir) {
109
+ async function generateSchemas(typeSource, type, outputWorkingDir) {
108
110
  const allSchemas = {};
109
- const arraySingularTypes = [];
110
- for (const type of types) {
111
- if (type.endsWith("[]")) {
112
- const singularType = type.slice(0, -2);
113
- arraySingularTypes.push(singularType);
114
- if (!types.includes(singularType)) {
115
- types.push(singularType);
116
- }
117
- }
118
- }
119
- for (const files of modelDirWildcards) {
120
- CLIDisplay.value(I18n.formatMessage("commands.ts-to-schema.progress.models"), files.replace(/\\/g, "/"), 1);
121
- const generator = createGenerator({
122
- path: files.replace(/\\/g, "/"),
123
- type: "*",
124
- tsconfig: path.join(outputWorkingDir, "tsconfig.json"),
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, types, referencedSchemas);
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.20", // x-release-please-version
220
+ version: "0.0.1-next.22", // x-release-please-version
239
221
  icon: "⚙️ ",
240
222
  supportsEnvFiles: false,
241
223
  overrideOutputWidth: options?.overrideOutputWidth
@@ -249,8 +249,7 @@
249
249
  "progress": {
250
250
  "loadingConfigJson": "Loading Config JSON",
251
251
  "creatingWorkingDir": "Creating Working Directory",
252
- "generatingSchemas": "Generating Schemas",
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 list of glob sources that can be used to generate the schemas.
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.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)
4
+
5
+
6
+ ### Features
7
+
8
+ * generate schemas as individual entities ([9f372ab](https://github.com/twinfoundation/tools/commit/9f372abdfc27aba93b303c7b214991919c0c18c3))
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * remove debugging ([4def3d1](https://github.com/twinfoundation/tools/commit/4def3d1ef6a41a3b3358f864214e6a7ec3f9c638))
14
+
15
+
16
+ ### Dependencies
17
+
18
+ * The following workspace dependencies were updated
19
+ * dependencies
20
+ * @twin.org/nameof bumped from 0.0.1-next.21 to 0.0.1-next.22
21
+ * devDependencies
22
+ * @twin.org/merge-locales bumped from 0.0.1-next.21 to 0.0.1-next.22
23
+ * @twin.org/nameof-transformer bumped from 0.0.1-next.21 to 0.0.1-next.22
24
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.1-next.21 to 0.0.1-next.22
25
+
26
+ ## [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)
27
+
28
+
29
+ ### Features
30
+
31
+ * use shared store mechanism ([#31](https://github.com/twinfoundation/tools/issues/31)) ([d9fe68b](https://github.com/twinfoundation/tools/commit/d9fe68b903d1268c7cb3c64772df5cb78fd63667))
32
+
33
+
34
+ ### Dependencies
35
+
36
+ * The following workspace dependencies were updated
37
+ * dependencies
38
+ * @twin.org/nameof bumped from 0.0.1-next.20 to 0.0.1-next.21
39
+ * devDependencies
40
+ * @twin.org/merge-locales bumped from 0.0.1-next.20 to 0.0.1-next.21
41
+ * @twin.org/nameof-transformer bumped from 0.0.1-next.20 to 0.0.1-next.21
42
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.1-next.20 to 0.0.1-next.21
43
+
3
44
  ## [0.0.1-next.20](https://github.com/twinfoundation/tools/compare/ts-to-schema-v0.0.1-next.19...ts-to-schema-v0.0.1-next.20) (2025-03-28)
4
45
 
5
46
 
@@ -8,13 +8,13 @@ The main entry point for the CLI.
8
8
 
9
9
  ## Constructors
10
10
 
11
- ### new CLI()
11
+ ### Constructor
12
12
 
13
- > **new CLI**(): [`CLI`](CLI.md)
13
+ > **new CLI**(): `CLI`
14
14
 
15
15
  #### Returns
16
16
 
17
- [`CLI`](CLI.md)
17
+ `CLI`
18
18
 
19
19
  #### Inherited from
20
20
 
@@ -24,7 +24,7 @@ The main entry point for the CLI.
24
24
 
25
25
  ### run()
26
26
 
27
- > **run**(`argv`, `localesDirectory`?, `options`?): `Promise`\<`number`\>
27
+ > **run**(`argv`, `localesDirectory?`, `options?`): `Promise`\<`number`\>
28
28
 
29
29
  Run the app.
30
30
 
@@ -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 list of types to generate.
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
- "generatingSchemas": "Generating Schemas",
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.20",
3
+ "version": "0.0.1-next.22",
4
4
  "description": "Tool to convert TypeScript definitions to JSON schemas",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,11 +16,11 @@
16
16
  "dependencies": {
17
17
  "@twin.org/cli-core": "next",
18
18
  "@twin.org/core": "next",
19
- "@twin.org/nameof": "0.0.1-next.20",
19
+ "@twin.org/nameof": "0.0.1-next.22",
20
20
  "commander": "13.1.0",
21
21
  "glob": "11.0.1",
22
22
  "jsonschema": "1.5.0",
23
- "ts-json-schema-generator": "2.4.0-next.1"
23
+ "ts-json-schema-generator": "2.4.0"
24
24
  },
25
25
  "main": "./dist/cjs/index.cjs",
26
26
  "module": "./dist/esm/index.mjs",