@goast/typescript 0.2.19 → 0.2.20

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.
@@ -11,13 +11,22 @@ class DefaultTypeScriptModelGenerator extends file_generator_1.TypeScriptFileGen
11
11
  if (this.shouldGenerateTypeDeclaration(ctx, ctx.schema)) {
12
12
  const name = this.getDeclarationTypeName(ctx, ctx.schema);
13
13
  const filePath = this.getFilePath(ctx, ctx.schema);
14
+ const fileContent = this.getFileContent(ctx);
14
15
  file_builder_1.TypeScriptFileBuilder.generate({
15
16
  logName: `model ${name}`,
16
17
  filePath,
17
18
  options: ctx.config,
18
- generator: (b) => b.append(this.getFileContent(ctx)),
19
+ generator: (b) => b.append(fileContent),
19
20
  });
20
- return { component: name, filePath, imports: [{ kind: 'file', name, modulePath: filePath }] };
21
+ return {
22
+ component: name,
23
+ filePath,
24
+ imports: [{ kind: 'file', name, modulePath: filePath }],
25
+ additionalExports: fileContent.values
26
+ .filter((x) => typeof x === 'object' && x !== null && 'export' in x && x.export === true && 'name' in x)
27
+ .filter((x) => x.name !== name)
28
+ .map((x) => x.name),
29
+ };
21
30
  }
22
31
  else {
23
32
  const builder = new file_builder_1.TypeScriptFileBuilder(undefined, ctx.config);
@@ -47,7 +47,13 @@ class TypeScriptModelsGenerator extends core_1.OpenApiSchemasGenerationProviderB
47
47
  return ctx.config.indexFilePath ? (0, path_1.resolve)(ctx.config.outputDir, ctx.config.indexFilePath) : null;
48
48
  }
49
49
  getIndexFileContent(ctx) {
50
- return (0, core_1.appendValueGroup)(Object.values(ctx.output.models).map((x) => (x.filePath ? ast_1.ts.export(x.component, x.filePath) : null)));
50
+ return (0, core_1.appendValueGroup)(Object.values(ctx.output.models).flatMap((x) => {
51
+ var _a, _b;
52
+ const { filePath } = x;
53
+ if (!filePath)
54
+ return [];
55
+ return [ast_1.ts.export(x.component, filePath), ...((_b = (_a = x.additionalExports) === null || _a === void 0 ? void 0 : _a.map((e) => ast_1.ts.export(e, filePath))) !== null && _b !== void 0 ? _b : [])];
56
+ }));
51
57
  }
52
58
  }
53
59
  exports.TypeScriptModelsGenerator = TypeScriptModelsGenerator;
@@ -8,13 +8,22 @@ export class DefaultTypeScriptModelGenerator extends TypeScriptFileGenerator {
8
8
  if (this.shouldGenerateTypeDeclaration(ctx, ctx.schema)) {
9
9
  const name = this.getDeclarationTypeName(ctx, ctx.schema);
10
10
  const filePath = this.getFilePath(ctx, ctx.schema);
11
+ const fileContent = this.getFileContent(ctx);
11
12
  TypeScriptFileBuilder.generate({
12
13
  logName: `model ${name}`,
13
14
  filePath,
14
15
  options: ctx.config,
15
- generator: (b) => b.append(this.getFileContent(ctx)),
16
+ generator: (b) => b.append(fileContent),
16
17
  });
17
- return { component: name, filePath, imports: [{ kind: 'file', name, modulePath: filePath }] };
18
+ return {
19
+ component: name,
20
+ filePath,
21
+ imports: [{ kind: 'file', name, modulePath: filePath }],
22
+ additionalExports: fileContent.values
23
+ .filter((x) => typeof x === 'object' && x !== null && 'export' in x && x.export === true && 'name' in x)
24
+ .filter((x) => x.name !== name)
25
+ .map((x) => x.name),
26
+ };
18
27
  }
19
28
  else {
20
29
  const builder = new TypeScriptFileBuilder(undefined, ctx.config);
@@ -44,6 +44,12 @@ export class TypeScriptModelsGenerator extends OpenApiSchemasGenerationProviderB
44
44
  return ctx.config.indexFilePath ? resolve(ctx.config.outputDir, ctx.config.indexFilePath) : null;
45
45
  }
46
46
  getIndexFileContent(ctx) {
47
- return appendValueGroup(Object.values(ctx.output.models).map((x) => (x.filePath ? ts.export(x.component, x.filePath) : null)));
47
+ return appendValueGroup(Object.values(ctx.output.models).flatMap((x) => {
48
+ var _a, _b;
49
+ const { filePath } = x;
50
+ if (!filePath)
51
+ return [];
52
+ return [ts.export(x.component, filePath), ...((_b = (_a = x.additionalExports) === null || _a === void 0 ? void 0 : _a.map((e) => ts.export(e, filePath))) !== null && _b !== void 0 ? _b : [])];
53
+ }));
48
54
  }
49
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goast/typescript",
3
- "version": "0.2.19",
3
+ "version": "0.2.20",
4
4
  "repository": "https://github.com/MaSch0212/goast.git",
5
5
  "author": {
6
6
  "name": "Marc Schmidt (MaSch0212)",
@@ -9,7 +9,11 @@
9
9
  "license": "MIT",
10
10
  "type": "module",
11
11
  "dependencies": {
12
- "@goast/core": "0.2.2"
12
+ "fs-extra": "^11.2.0",
13
+ "node-fetch": "^2.7.0",
14
+ "yaml": "^2.4.1",
15
+ "@goast/core": "0.2.2",
16
+ "tslib": "2.6.2"
13
17
  },
14
18
  "module": "./esm/index.js",
15
19
  "main": "./cjs/index.js",
@@ -2,6 +2,7 @@ export type TypeScriptComponentOutput = {
2
2
  component: string;
3
3
  filePath?: string;
4
4
  imports: TypeScriptImport[];
5
+ additionalExports?: string[];
5
6
  };
6
7
  export type TypeScriptExportOutput = {
7
8
  component: string;