@goast/typescript 0.2.5 → 0.2.6

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.
@@ -9,7 +9,6 @@ const file_generator_1 = require("../../file-generator");
9
9
  class DefaultTypeScriptFetchClientGenerator extends file_generator_1.TypeScriptFileGenerator {
10
10
  generate(ctx) {
11
11
  const result = {};
12
- let builder;
13
12
  if (this.shouldGenerateInterface(ctx)) {
14
13
  const filePath = this.getInterfaceFilePath(ctx);
15
14
  const name = this.getInterfaceName(ctx);
@@ -19,7 +18,7 @@ class DefaultTypeScriptFetchClientGenerator extends file_generator_1.TypeScriptF
19
18
  options: ctx.config,
20
19
  generator: (b) => b.append(this.getInterfaceFileContent(ctx)),
21
20
  });
22
- result.interface = { filePath, component: name, imports: [{ kind: 'file', name, modulePath: filePath }] };
21
+ result.interface = { filePath, component: name };
23
22
  }
24
23
  if (this.shouldGenerateClass(ctx)) {
25
24
  const filePath = this.getClassFilePath(ctx);
@@ -30,7 +29,7 @@ class DefaultTypeScriptFetchClientGenerator extends file_generator_1.TypeScriptF
30
29
  options: ctx.config,
31
30
  generator: (b) => b.append(this.getClassFileContent(ctx)),
32
31
  });
33
- result.class = { filePath, component: name, imports: [{ kind: 'file', name, modulePath: filePath }] };
32
+ result.class = { filePath, component: name };
34
33
  }
35
34
  return result;
36
35
  }
@@ -7,8 +7,8 @@ const core_1 = require("@goast/core");
7
7
  const fetch_client_generator_1 = require("./fetch-client-generator");
8
8
  const models_1 = require("./models");
9
9
  const refs_1 = require("./refs");
10
+ const ast_1 = require("../../../ast");
10
11
  const file_builder_1 = require("../../../file-builder");
11
- const import_collection_1 = require("../../../import-collection");
12
12
  class TypeScriptClientsGenerator extends core_1.OpenApiServicesGenerationProviderBase {
13
13
  constructor(clientGeneratorFactory) {
14
14
  super();
@@ -43,37 +43,23 @@ class TypeScriptClientsGenerator extends core_1.OpenApiServicesGenerationProvide
43
43
  ctx.output.clients[service.id] = result;
44
44
  }
45
45
  generateIndexFile(ctx) {
46
- if (!this.shouldGenerateIndexFile(ctx)) {
47
- return undefined;
48
- }
49
46
  const filePath = this.getIndexFilePath(ctx);
50
- console.log(`Generating index file to ${filePath}...`);
51
- (0, fs_extra_1.ensureDirSync)((0, path_1.dirname)(filePath));
52
- const builder = new file_builder_1.TypeScriptFileBuilder(filePath, ctx.config);
53
- this.generateIndexFileContent(ctx, builder);
54
- (0, fs_extra_1.writeFileSync)(filePath, builder.toString());
47
+ file_builder_1.TypeScriptFileBuilder.tryGenerate({
48
+ logName: 'clients index file',
49
+ filePath,
50
+ options: ctx.config,
51
+ generator: (b) => b.append(this.getIndexFileContent(ctx)),
52
+ });
55
53
  return filePath;
56
54
  }
57
55
  getIndexFilePath(ctx) {
58
- var _a;
59
- return (0, path_1.resolve)(ctx.config.outputDir, (_a = ctx.config.indexFilePath) !== null && _a !== void 0 ? _a : 'clients.ts');
56
+ return ctx.config.indexFilePath ? (0, path_1.resolve)(ctx.config.outputDir, ctx.config.indexFilePath) : null;
60
57
  }
61
- shouldGenerateIndexFile(ctx) {
62
- return ctx.config.indexFilePath !== null;
63
- }
64
- generateIndexFileContent(ctx, builder) {
65
- var _a, _b;
66
- const exports = new import_collection_1.ImportExportCollection();
67
- for (const clientId in ctx.output.clients) {
68
- const client = ctx.output.clients[clientId];
69
- if ((_a = client.class) === null || _a === void 0 ? void 0 : _a.filePath) {
70
- exports.addExport(client.class.component, client.class.filePath);
71
- }
72
- if ((_b = client.interface) === null || _b === void 0 ? void 0 : _b.filePath) {
73
- exports.addExport(client.interface.component, client.interface.filePath);
74
- }
75
- }
76
- exports.writeTo(builder);
58
+ getIndexFileContent(ctx) {
59
+ return (0, core_1.appendValueGroup)(Object.values(ctx.output.clients)
60
+ .flatMap((c) => [c.class, c.interface])
61
+ .filter(core_1.notNullish)
62
+ .map((x) => ast_1.ts.export(x.component, x.filePath)));
77
63
  }
78
64
  copyUtilsFiles(ctx) {
79
65
  const sourceDir = (0, path_1.resolve)((0, path_1.dirname)(require.resolve('@goast/typescript')), '../assets/client/fetch');
@@ -6,7 +6,6 @@ import { TypeScriptFileGenerator } from '../../file-generator';
6
6
  export class DefaultTypeScriptFetchClientGenerator extends TypeScriptFileGenerator {
7
7
  generate(ctx) {
8
8
  const result = {};
9
- let builder;
10
9
  if (this.shouldGenerateInterface(ctx)) {
11
10
  const filePath = this.getInterfaceFilePath(ctx);
12
11
  const name = this.getInterfaceName(ctx);
@@ -16,7 +15,7 @@ export class DefaultTypeScriptFetchClientGenerator extends TypeScriptFileGenerat
16
15
  options: ctx.config,
17
16
  generator: (b) => b.append(this.getInterfaceFileContent(ctx)),
18
17
  });
19
- result.interface = { filePath, component: name, imports: [{ kind: 'file', name, modulePath: filePath }] };
18
+ result.interface = { filePath, component: name };
20
19
  }
21
20
  if (this.shouldGenerateClass(ctx)) {
22
21
  const filePath = this.getClassFilePath(ctx);
@@ -27,7 +26,7 @@ export class DefaultTypeScriptFetchClientGenerator extends TypeScriptFileGenerat
27
26
  options: ctx.config,
28
27
  generator: (b) => b.append(this.getClassFileContent(ctx)),
29
28
  });
30
- result.class = { filePath, component: name, imports: [{ kind: 'file', name, modulePath: filePath }] };
29
+ result.class = { filePath, component: name };
31
30
  }
32
31
  return result;
33
32
  }
@@ -1,11 +1,11 @@
1
1
  import { dirname, resolve } from 'path';
2
- import { ensureDirSync, writeFileSync, copyFileSync, readdirSync } from 'fs-extra';
3
- import { OpenApiServicesGenerationProviderBase, Factory } from '@goast/core';
2
+ import { ensureDirSync, copyFileSync, readdirSync } from 'fs-extra';
3
+ import { OpenApiServicesGenerationProviderBase, Factory, appendValueGroup, notNullish, } from '@goast/core';
4
4
  import { DefaultTypeScriptFetchClientGenerator } from './fetch-client-generator';
5
5
  import { defaultTypeScriptFetchClientsGeneratorConfig, } from './models';
6
6
  import { getReferenceFactories } from './refs';
7
+ import { ts } from '../../../ast';
7
8
  import { TypeScriptFileBuilder } from '../../../file-builder';
8
- import { ImportExportCollection } from '../../../import-collection';
9
9
  export class TypeScriptClientsGenerator extends OpenApiServicesGenerationProviderBase {
10
10
  constructor(clientGeneratorFactory) {
11
11
  super();
@@ -40,37 +40,23 @@ export class TypeScriptClientsGenerator extends OpenApiServicesGenerationProvide
40
40
  ctx.output.clients[service.id] = result;
41
41
  }
42
42
  generateIndexFile(ctx) {
43
- if (!this.shouldGenerateIndexFile(ctx)) {
44
- return undefined;
45
- }
46
43
  const filePath = this.getIndexFilePath(ctx);
47
- console.log(`Generating index file to ${filePath}...`);
48
- ensureDirSync(dirname(filePath));
49
- const builder = new TypeScriptFileBuilder(filePath, ctx.config);
50
- this.generateIndexFileContent(ctx, builder);
51
- writeFileSync(filePath, builder.toString());
44
+ TypeScriptFileBuilder.tryGenerate({
45
+ logName: 'clients index file',
46
+ filePath,
47
+ options: ctx.config,
48
+ generator: (b) => b.append(this.getIndexFileContent(ctx)),
49
+ });
52
50
  return filePath;
53
51
  }
54
52
  getIndexFilePath(ctx) {
55
- var _a;
56
- return resolve(ctx.config.outputDir, (_a = ctx.config.indexFilePath) !== null && _a !== void 0 ? _a : 'clients.ts');
53
+ return ctx.config.indexFilePath ? resolve(ctx.config.outputDir, ctx.config.indexFilePath) : null;
57
54
  }
58
- shouldGenerateIndexFile(ctx) {
59
- return ctx.config.indexFilePath !== null;
60
- }
61
- generateIndexFileContent(ctx, builder) {
62
- var _a, _b;
63
- const exports = new ImportExportCollection();
64
- for (const clientId in ctx.output.clients) {
65
- const client = ctx.output.clients[clientId];
66
- if ((_a = client.class) === null || _a === void 0 ? void 0 : _a.filePath) {
67
- exports.addExport(client.class.component, client.class.filePath);
68
- }
69
- if ((_b = client.interface) === null || _b === void 0 ? void 0 : _b.filePath) {
70
- exports.addExport(client.interface.component, client.interface.filePath);
71
- }
72
- }
73
- exports.writeTo(builder);
55
+ getIndexFileContent(ctx) {
56
+ return appendValueGroup(Object.values(ctx.output.clients)
57
+ .flatMap((c) => [c.class, c.interface])
58
+ .filter(notNullish)
59
+ .map((x) => ts.export(x.component, x.filePath)));
74
60
  }
75
61
  copyUtilsFiles(ctx) {
76
62
  const sourceDir = resolve(dirname(require.resolve('@goast/typescript')), '../assets/client/fetch');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goast/typescript",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "repository": "https://github.com/MaSch0212/goast.git",
5
5
  "author": {
6
6
  "name": "Marc Schmidt (MaSch0212)",
@@ -1,4 +1,4 @@
1
- import { ApiService, OpenApiGeneratorContext, OpenApiServicesGenerationProviderBase, Factory } from '@goast/core';
1
+ import { ApiService, OpenApiGeneratorContext, OpenApiServicesGenerationProviderBase, Factory, AppendValueGroup } from '@goast/core';
2
2
  import { TypeScriptFetchClientGenerator } from './fetch-client-generator';
3
3
  import { TypeScriptFetchClientGeneratorOutput, TypeScriptFetchClientsGeneratorConfig, TypeScriptFetchClientsGeneratorContext, TypeScriptFetchClientsGeneratorInput, TypeScriptFetchClientsGeneratorOutput } from './models';
4
4
  import { TypeScriptFileBuilder } from '../../../file-builder';
@@ -15,10 +15,9 @@ export declare class TypeScriptClientsGenerator extends OpenApiServicesGeneratio
15
15
  onGenerate(ctx: Context): Output;
16
16
  protected generateService(ctx: Context, service: ApiService): ServiceOutput;
17
17
  protected addServiceResult(ctx: Context, service: ApiService, result: ServiceOutput): void;
18
- protected generateIndexFile(ctx: Context): string | undefined;
19
- protected getIndexFilePath(ctx: Context): string;
20
- protected shouldGenerateIndexFile(ctx: Context): boolean;
21
- protected generateIndexFileContent(ctx: Context, builder: TypeScriptFileBuilder): void;
18
+ protected generateIndexFile(ctx: Context): string | null;
19
+ protected getIndexFilePath(ctx: Context): string | null;
20
+ protected getIndexFileContent(ctx: Context): AppendValueGroup<TypeScriptFileBuilder>;
22
21
  private copyUtilsFiles;
23
22
  }
24
23
  export {};
@@ -1,6 +1,6 @@
1
1
  import { ApiService, DefaultGenerationProviderConfig, OpenApiServicesGenerationProviderContext, StringCasing, StringCasingWithOptions, Nullable } from '@goast/core';
2
2
  import { getReferenceFactories } from './refs';
3
- import { TypeScriptComponentOutput } from '../../../common-results';
3
+ import { TypeScriptExportOutput } from '../../../common-results';
4
4
  import { TypeScriptGeneratorConfig } from '../../../config';
5
5
  import { TypeScriptModelsGeneratorOutput } from '../../models/models';
6
6
  export type TypeScriptFetchClientsGeneratorConfig = TypeScriptGeneratorConfig & {
@@ -27,8 +27,8 @@ export type TypeScriptFetchClientsGeneratorOutput = {
27
27
  };
28
28
  };
29
29
  export type TypeScriptFetchClientGeneratorOutput = {
30
- class?: Omit<TypeScriptComponentOutput, 'additionalImports'>;
31
- interface?: Omit<TypeScriptComponentOutput, 'additionalImports'>;
30
+ class?: TypeScriptExportOutput;
31
+ interface?: TypeScriptExportOutput;
32
32
  };
33
33
  export type TypeScriptFetchClientsGeneratorContext = OpenApiServicesGenerationProviderContext<TypeScriptFetchClientsGeneratorInput, TypeScriptFetchClientsGeneratorOutput, TypeScriptFetchClientsGeneratorConfig, TypeScriptFetchClientGeneratorOutput> & {
34
34
  refs: ReturnType<typeof getReferenceFactories>;