fastify-flux-cli 2.19.0
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/LICENSE +19 -0
- package/cli.js +13 -0
- package/dist/commands/build.d.ts +3 -0
- package/dist/commands/build.d.ts.map +1 -0
- package/dist/commands/build.js +18 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/new.d.ts +1 -0
- package/dist/commands/new.d.ts.map +1 -0
- package/dist/commands/new.js +2 -0
- package/dist/commands/new.js.map +1 -0
- package/dist/commands/sdk.d.ts +3 -0
- package/dist/commands/sdk.d.ts.map +1 -0
- package/dist/commands/sdk.js +16 -0
- package/dist/commands/sdk.js.map +1 -0
- package/dist/commands/start.d.ts +3 -0
- package/dist/commands/start.d.ts.map +1 -0
- package/dist/commands/start.js +128 -0
- package/dist/commands/start.js.map +1 -0
- package/dist/helper/api-sdk.js +16 -0
- package/dist/helper/api-sdk.js.map +1 -0
- package/dist/helper/config.d.ts +3 -0
- package/dist/helper/config.d.ts.map +1 -0
- package/dist/helper/config.js +31 -0
- package/dist/helper/config.js.map +1 -0
- package/dist/helper/esbuild.d.ts +2 -0
- package/dist/helper/esbuild.d.ts.map +1 -0
- package/dist/helper/esbuild.js +43 -0
- package/dist/helper/esbuild.js.map +1 -0
- package/dist/helper/generateMeta.d.ts +2 -0
- package/dist/helper/generateMeta.d.ts.map +1 -0
- package/dist/helper/generateMeta.js +27 -0
- package/dist/helper/generateMeta.js.map +1 -0
- package/dist/helper/generateSchema.d.ts +13 -0
- package/dist/helper/generateSchema.d.ts.map +1 -0
- package/dist/helper/generateSchema.js +63 -0
- package/dist/helper/generateSchema.js.map +1 -0
- package/dist/helper/generateSdk.d.ts +3 -0
- package/dist/helper/generateSdk.d.ts.map +1 -0
- package/dist/helper/generateSdk.js +35 -0
- package/dist/helper/generateSdk.js.map +1 -0
- package/dist/helper/getControllerFunctions.d.ts +7 -0
- package/dist/helper/getControllerFunctions.d.ts.map +1 -0
- package/dist/helper/getControllerFunctions.js +62 -0
- package/dist/helper/getControllerFunctions.js.map +1 -0
- package/dist/helper/index.d.ts +5 -0
- package/dist/helper/index.d.ts.map +1 -0
- package/dist/helper/index.js +24 -0
- package/dist/helper/index.js.map +1 -0
- package/dist/helper/killProcess.d.ts +2 -0
- package/dist/helper/killProcess.d.ts.map +1 -0
- package/dist/helper/killProcess.js +11 -0
- package/dist/helper/killProcess.js.map +1 -0
- package/dist/helper/prettify.d.ts +1 -0
- package/dist/helper/prettify.d.ts.map +1 -0
- package/dist/helper/prettify.js +2 -0
- package/dist/helper/prettify.js.map +1 -0
- package/dist/helper/writeFile.d.ts +2 -0
- package/dist/helper/writeFile.d.ts.map +1 -0
- package/dist/helper/writeFile.js +12 -0
- package/dist/helper/writeFile.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/log.d.ts +9 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +24 -0
- package/dist/log.js.map +1 -0
- package/dist/piscina/index.d.ts +9 -0
- package/dist/piscina/index.d.ts.map +1 -0
- package/dist/piscina/index.js +24 -0
- package/dist/piscina/index.js.map +1 -0
- package/dist/piscina/worker.d.ts +8 -0
- package/dist/piscina/worker.d.ts.map +1 -0
- package/dist/piscina/worker.js +35 -0
- package/dist/piscina/worker.js.map +1 -0
- package/dist/schema/__tests__/emptObject.test.d.ts +2 -0
- package/dist/schema/__tests__/emptObject.test.d.ts.map +1 -0
- package/dist/schema/__tests__/emptObject.test.js +27 -0
- package/dist/schema/__tests__/emptObject.test.js.map +1 -0
- package/dist/schema/__tests__/nullableSchema.test.d.ts +2 -0
- package/dist/schema/__tests__/nullableSchema.test.d.ts.map +1 -0
- package/dist/schema/__tests__/nullableSchema.test.js +141 -0
- package/dist/schema/__tests__/nullableSchema.test.js.map +1 -0
- package/dist/schema/convertNullToNullable.d.ts +3 -0
- package/dist/schema/convertNullToNullable.d.ts.map +1 -0
- package/dist/schema/convertNullToNullable.js +23 -0
- package/dist/schema/convertNullToNullable.js.map +1 -0
- package/dist/schema/generateSchema.d.ts +13 -0
- package/dist/schema/generateSchema.d.ts.map +1 -0
- package/dist/schema/generateSchema.js +66 -0
- package/dist/schema/generateSchema.js.map +1 -0
- package/dist/schema/helper/add-properties.d.ts +2 -0
- package/dist/schema/helper/add-properties.d.ts.map +1 -0
- package/dist/schema/helper/add-properties.js +11 -0
- package/dist/schema/helper/add-properties.js.map +1 -0
- package/dist/schema/helper/convertEmptyObject.d.ts +2 -0
- package/dist/schema/helper/convertEmptyObject.d.ts.map +1 -0
- package/dist/schema/helper/convertEmptyObject.js +9 -0
- package/dist/schema/helper/convertEmptyObject.js.map +1 -0
- package/dist/schema/helper/convertNullToNullable.d.ts +2 -0
- package/dist/schema/helper/convertNullToNullable.d.ts.map +1 -0
- package/dist/schema/helper/convertNullToNullable.js +33 -0
- package/dist/schema/helper/convertNullToNullable.js.map +1 -0
- package/dist/schema/nullableSchema.test.d.ts +2 -0
- package/dist/schema/nullableSchema.test.d.ts.map +1 -0
- package/dist/schema/nullableSchema.test.js +93 -0
- package/dist/schema/nullableSchema.test.js.map +1 -0
- package/dist/types.d.ts +13 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +57 -0
- package/sdk-templates/api.eta +65 -0
- package/sdk-templates/axios-http-client.eta +133 -0
- package/sdk-templates/http-client.eta +3 -0
- package/sdk-templates/procedure-call.eta +99 -0
- package/sdk-templates/route-types.eta +28 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2021 Jakob Niggel
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
package/cli.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
import { readFileSync } from 'node:fs';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
import sourceMapSupport from 'source-map-support';
|
|
7
|
+
sourceMapSupport.install();
|
|
8
|
+
|
|
9
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
const { version } = JSON.parse(readFileSync(join(__dirname, 'package.json')));
|
|
11
|
+
process.env.version = version;
|
|
12
|
+
|
|
13
|
+
import './dist/index.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAqBpC,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,QAK/C"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { runWorkerControllerGeneration, runWorkerEsbuild, runWorkerSchemaGeneration, runWorkerTypecheck, } from '../piscina/index.js';
|
|
2
|
+
async function handler(options) {
|
|
3
|
+
if (options.typecheck) {
|
|
4
|
+
await runWorkerTypecheck();
|
|
5
|
+
}
|
|
6
|
+
await Promise.all([
|
|
7
|
+
runWorkerEsbuild(),
|
|
8
|
+
runWorkerControllerGeneration(),
|
|
9
|
+
runWorkerSchemaGeneration(),
|
|
10
|
+
]);
|
|
11
|
+
}
|
|
12
|
+
export function addBuildCommand(program) {
|
|
13
|
+
program
|
|
14
|
+
.command('build')
|
|
15
|
+
.option('--typecheck', 'Run typecheck before building the project.')
|
|
16
|
+
.action(handler);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,6BAA6B,EAC7B,gBAAgB,EAChB,yBAAyB,EACzB,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAE7B,KAAK,UAAU,OAAO,CAAC,OAA4B;IACjD,IAAI,OAAO,CAAC,SAAS,EAAE;QACrB,MAAM,kBAAkB,EAAE,CAAC;KAC5B;IAED,MAAM,OAAO,CAAC,GAAG,CAAC;QAChB,gBAAgB,EAAE;QAClB,6BAA6B,EAAE;QAC/B,yBAAyB,EAAE;KAC5B,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,OAAgB;IAC9C,OAAO;SACJ,OAAO,CAAC,OAAO,CAAC;SAChB,MAAM,CAAC,aAAa,EAAE,4CAA4C,CAAC;SACnE,MAAM,CAAC,OAAO,CAAC,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=new.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"new.d.ts","sourceRoot":"","sources":["../../src/commands/new.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"new.js","sourceRoot":"","sources":["../../src/commands/new.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../src/commands/sdk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAiBpC,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,QAE7C"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import pMap from 'p-map';
|
|
2
|
+
import { getConfig } from '../helper/config.js';
|
|
3
|
+
import { runWorkerSdkGeneration } from '../piscina/index.js';
|
|
4
|
+
async function handler() {
|
|
5
|
+
const config = await getConfig();
|
|
6
|
+
await pMap(config.tasks, async (project) => {
|
|
7
|
+
if (!project.sdk) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
await runWorkerSdkGeneration(project.sdk);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
export function addSdkCommand(program) {
|
|
14
|
+
program.command('sdk').action(handler);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=sdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.js","sourceRoot":"","sources":["../../src/commands/sdk.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,OAAO,CAAC;AACzB,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,KAAK,UAAU,OAAO;IACpB,MAAM,MAAM,GAAG,MAAM,SAAS,EAAE,CAAC;IACjC,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;QACzC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE;YAChB,OAAO;SACR;QAED,MAAM,sBAAsB,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,OAAgB;IAC5C,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"start.d.ts","sourceRoot":"","sources":["../../src/commands/start.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAiKpC,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,QAQ/C"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { execa } from 'execa';
|
|
2
|
+
import chokidar from 'chokidar';
|
|
3
|
+
import pMap from 'p-map';
|
|
4
|
+
import _ from 'lodash';
|
|
5
|
+
import { runWorkerControllerGeneration, runWorkerEsbuild, runWorkerSchemaGeneration, runWorkerSdkGeneration, runWorkerTypecheck, } from '../piscina/index.js';
|
|
6
|
+
import { log } from '../log.js';
|
|
7
|
+
import { getConfig } from '../helper/config.js';
|
|
8
|
+
import { killProcess } from '../helper/killProcess.js';
|
|
9
|
+
import { existsSync, mkdirSync } from 'fs';
|
|
10
|
+
function startProcess(command, projectIndex) {
|
|
11
|
+
const [file, ...args] = command;
|
|
12
|
+
const subprocess = execa(file, args, {
|
|
13
|
+
env: { FLUX_PROJECT_INDEX: `${projectIndex}` },
|
|
14
|
+
});
|
|
15
|
+
if (subprocess.stdout) {
|
|
16
|
+
subprocess.stdout.on('data', (line) => {
|
|
17
|
+
log({ component: 'app', details: line.toString().trim() });
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
if (subprocess.stderr) {
|
|
21
|
+
subprocess.stderr.pipe(process.stdout);
|
|
22
|
+
}
|
|
23
|
+
return subprocess.pid;
|
|
24
|
+
}
|
|
25
|
+
async function createDistDir() {
|
|
26
|
+
const distDir = 'dist/';
|
|
27
|
+
const distExists = existsSync(distDir);
|
|
28
|
+
if (!distExists) {
|
|
29
|
+
mkdirSync(distDir);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
class ExecHandler {
|
|
33
|
+
constructor(config) {
|
|
34
|
+
this.config = config;
|
|
35
|
+
this.procs = [];
|
|
36
|
+
}
|
|
37
|
+
async cancelAll() {
|
|
38
|
+
await pMap(this.procs, async (pid) => {
|
|
39
|
+
await killProcess(pid);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
restartAll() {
|
|
43
|
+
this.cancelAll();
|
|
44
|
+
this.procs = this.config.map(startProcess);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
class WatchHandler {
|
|
48
|
+
constructor(options) {
|
|
49
|
+
this.options = options;
|
|
50
|
+
this.handleDebounced = _.debounce(this.handle, 100);
|
|
51
|
+
}
|
|
52
|
+
async setup() {
|
|
53
|
+
const config = await getConfig();
|
|
54
|
+
const { tasks } = config;
|
|
55
|
+
const commands = tasks.map((x) => x.run);
|
|
56
|
+
commands.forEach((x) => {
|
|
57
|
+
if (this.options.debug) {
|
|
58
|
+
x.push('--inspect');
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
this.excecHandler = new ExecHandler(commands);
|
|
62
|
+
chokidar
|
|
63
|
+
.watch(config.entry, {
|
|
64
|
+
disableGlobbing: true,
|
|
65
|
+
persistent: true,
|
|
66
|
+
ignoreInitial: true,
|
|
67
|
+
})
|
|
68
|
+
.on('add', this.handleDebounced.bind(this))
|
|
69
|
+
.on('change', this.handleDebounced.bind(this));
|
|
70
|
+
}
|
|
71
|
+
async build() {
|
|
72
|
+
this.excecHandler.cancelAll();
|
|
73
|
+
const esbuildSuccess = await runWorkerEsbuild();
|
|
74
|
+
if (!esbuildSuccess) {
|
|
75
|
+
log({ component: 'cli', warning: 'Skipping restart... esbuild failed.' });
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
await Promise.all([
|
|
79
|
+
runWorkerControllerGeneration(),
|
|
80
|
+
runWorkerSchemaGeneration(),
|
|
81
|
+
]);
|
|
82
|
+
this.excecHandler.restartAll();
|
|
83
|
+
}
|
|
84
|
+
async handle(change) {
|
|
85
|
+
log({ component: 'cli', success: 'App reload', details: change });
|
|
86
|
+
await this.build();
|
|
87
|
+
if (this.options.typecheck) {
|
|
88
|
+
runWorkerTypecheck();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async function startSdkWatch() {
|
|
93
|
+
const { tasks } = await getConfig();
|
|
94
|
+
tasks.forEach((project) => {
|
|
95
|
+
if (!project.sdk) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const { sdk } = project;
|
|
99
|
+
const handler = async () => await runWorkerSdkGeneration(sdk);
|
|
100
|
+
chokidar
|
|
101
|
+
.watch(sdk.input, {
|
|
102
|
+
disableGlobbing: true,
|
|
103
|
+
persistent: true,
|
|
104
|
+
ignoreInitial: true,
|
|
105
|
+
})
|
|
106
|
+
.on('add', handler)
|
|
107
|
+
.on('change', handler);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
async function handler(options) {
|
|
111
|
+
await createDistDir();
|
|
112
|
+
const instance = new WatchHandler(options);
|
|
113
|
+
await instance.setup();
|
|
114
|
+
await instance.build();
|
|
115
|
+
if (options.sdk) {
|
|
116
|
+
startSdkWatch();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
export function addStartCommand(program) {
|
|
120
|
+
program
|
|
121
|
+
.command('start')
|
|
122
|
+
.option('-w, --watch', 'Automatically restart on file changes.')
|
|
123
|
+
.option('-d, --debug', 'Run node with debug flag.')
|
|
124
|
+
.option('--typecheck', 'Runs a typecheck in a seperate thread.')
|
|
125
|
+
.option('--sdk', 'Generate client sdk.')
|
|
126
|
+
.action(handler);
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=start.js.map
|
|
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EAAE,EAAE;QACxB,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE;YAChB,OAAO;SACR;QAED,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;QAExB,MAAM,OAAO,GAAG,KAAK,IAAI,EAAE,CAAC,MAAM,sBAAsB,CAAC,GAAG,CAAC,CAAC;QAE9D,QAAQ;aACL,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE;YAChB,eAAe,EAAE,IAAI;YACrB,UAAU,EAAE,IAAI;YAChB,aAAa,EAAE,IAAI;SACpB,CAAC;aACD,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC;aAClB,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;AACL,CAAC;AAED,KAAK,UAAU,OAAO,CAAC,OAAgB;IACrC,MAAM,aAAa,EAAE,CAAC;IAEtB,MAAM,QAAQ,GAAG,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC;IAC3C,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAC;IACvB,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAC;IAEvB,IAAI,OAAO,CAAC,GAAG,EAAE;QACf,aAAa,EAAE,CAAC;KACjB;AACH,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,OAAgB;IAC9C,OAAO;SACJ,OAAO,CAAC,OAAO,CAAC;SAChB,MAAM,CAAC,aAAa,EAAE,wCAAwC,CAAC;SAC/D,MAAM,CAAC,aAAa,EAAE,2BAA2B,CAAC;SAClD,MAAM,CAAC,aAAa,EAAE,wCAAwC,CAAC;SAC/D,MAAM,CAAC,OAAO,EAAE,sBAAsB,CAAC;SACvC,MAAM,CAAC,OAAO,CAAC,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { dirname, join } from 'node:path';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import swagger from 'swagger-typescript-api';
|
|
4
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
5
|
+
export async function createApiSdk(file) {
|
|
6
|
+
const result = await swagger.generateApi({
|
|
7
|
+
name: 'Api.ts',
|
|
8
|
+
input: file,
|
|
9
|
+
templates: join(__dirname, '/../templates/api/'),
|
|
10
|
+
moduleNameIndex: 1,
|
|
11
|
+
httpClientType: 'axios',
|
|
12
|
+
defaultResponseType: 'any',
|
|
13
|
+
});
|
|
14
|
+
return result.files[0].content;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=api-sdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-sdk.js","sourceRoot":"","sources":["../../src/helper/api-sdk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,OAAO,MAAM,wBAAwB,CAAC;AAE7C,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAE1D,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,IAAY;IAC7C,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,WAAW,CAAC;QACvC,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,IAAI;QACX,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,oBAAoB,CAAC;QAChD,eAAe,EAAE,CAAC;QAClB,cAAc,EAAE,OAAO;QACvB,mBAAmB,EAAE,KAAK;KACpB,CAAC,CAAC;IAEV,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/helper/config.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAsB5C,wBAAsB,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,CAmBxD"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { getRootDir } from './index.js';
|
|
4
|
+
function getSdkDefaultConfig(projectIndex, outdir) {
|
|
5
|
+
const sdk = {
|
|
6
|
+
name: 'GeneratedApi.ts',
|
|
7
|
+
input: join(outdir, `/openapi-${projectIndex}.json`),
|
|
8
|
+
templates: join(getRootDir(), '/sdk-templates/'),
|
|
9
|
+
httpClientType: 'axios',
|
|
10
|
+
moduleNameIndex: 0,
|
|
11
|
+
};
|
|
12
|
+
return sdk;
|
|
13
|
+
}
|
|
14
|
+
async function readConfig() {
|
|
15
|
+
const config = (await import(join(process.cwd(), '/flux.config.js'))).default;
|
|
16
|
+
return _.cloneDeep(config);
|
|
17
|
+
}
|
|
18
|
+
export async function getConfig() {
|
|
19
|
+
const config = await readConfig();
|
|
20
|
+
config.outdir = join(process.cwd(), config.outdir);
|
|
21
|
+
config.tasks.forEach((project, index) => {
|
|
22
|
+
if (project.sdk) {
|
|
23
|
+
project.sdk = _.merge(getSdkDefaultConfig(index, config.outdir), project.sdk);
|
|
24
|
+
if (project.sdk.output && project.sdk.output.startsWith('.')) {
|
|
25
|
+
project.sdk.output = join(process.cwd(), project.sdk.output);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return config;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/helper/config.ts"],"names":[],"mappings":"AAAA,OAAO,CAAiB,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAGxC,SAAS,mBAAmB,CAAC,YAAoB,EAAE,MAAc;IAC/D,MAAM,GAAG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,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"esbuild.d.ts","sourceRoot":"","sources":["../../src/helper/esbuild.ts"],"names":[],"mappings":"AAiBA,wBAAsB,aAAa,IAAI,OAAO,CAAC,OAAO,CAAC,CA8BtD"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { build } from 'esbuild';
|
|
2
|
+
import fg from 'fast-glob';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { getConfig } from './config.js';
|
|
5
|
+
const makeAllPackagesExternalPlugin = () => ({
|
|
6
|
+
name: 'make-all-packages-external',
|
|
7
|
+
setup(build) {
|
|
8
|
+
build.onResolve({ filter: /.*/ }, (args) => {
|
|
9
|
+
if (args.resolveDir.includes('node_modules')) {
|
|
10
|
+
return { path: args.path, external: true };
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
export async function esbuildHelper() {
|
|
16
|
+
const config = await getConfig();
|
|
17
|
+
const files = await fg(join(config.entry, '/**/*.ts'), {
|
|
18
|
+
absolute: true,
|
|
19
|
+
markDirectories: true,
|
|
20
|
+
});
|
|
21
|
+
const esbuildConfig = {
|
|
22
|
+
platform: 'node',
|
|
23
|
+
target: 'node16',
|
|
24
|
+
format: 'cjs',
|
|
25
|
+
entryPoints: files,
|
|
26
|
+
outdir: config.outdir,
|
|
27
|
+
outbase: config.entry,
|
|
28
|
+
bundle: false,
|
|
29
|
+
sourcemap: true,
|
|
30
|
+
plugins: [makeAllPackagesExternalPlugin()],
|
|
31
|
+
};
|
|
32
|
+
if (config.esbuild) {
|
|
33
|
+
Object.assign(esbuildConfig, config.esbuild);
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
await build(esbuildConfig);
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=esbuild.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AC3C,CAAC;IAEF,IAAI,MAAM,CAAC,OAAO,EAAE;QAClB,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;KAC9C;IACD,IAAI;QACF,MAAM,KAAK,CAAC,aAAa,CAAC,CAAC;QAE3B,OAAO,IAAI,CAAC;KACb;IAAC,OAAO,GAAQ,EAAE;QACjB,OAAO,KAAK,CAAC;KACd;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateMeta.d.ts","sourceRoot":"","sources":["../../src/helper/generateMeta.ts"],"names":[],"mappings":"AAMA,wBAAsB,YAAY,oBA8BjC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import fg from 'fast-glob';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import pMap from 'p-map';
|
|
4
|
+
import { getConfig } from './config.js';
|
|
5
|
+
import { getControllerFunctions } from './getControllerFunctions.js';
|
|
6
|
+
export async function generateMeta() {
|
|
7
|
+
const config = await getConfig();
|
|
8
|
+
const controllers = await fg(join(config.entry, '/**/*[cC]ontroller.ts'), {
|
|
9
|
+
absolute: true,
|
|
10
|
+
markDirectories: true,
|
|
11
|
+
});
|
|
12
|
+
const results = await pMap(controllers, async (file) => {
|
|
13
|
+
const definitions = await getControllerFunctions(file);
|
|
14
|
+
return definitions;
|
|
15
|
+
}, { concurrency: 2 });
|
|
16
|
+
const functions = [];
|
|
17
|
+
results.forEach((x) => {
|
|
18
|
+
Object.keys(x.functions).forEach((method) => functions.push({
|
|
19
|
+
className: x.className,
|
|
20
|
+
functionName: method,
|
|
21
|
+
params: x.functions[method].params,
|
|
22
|
+
returnType: x.functions[method].returnType,
|
|
23
|
+
}));
|
|
24
|
+
});
|
|
25
|
+
return JSON.stringify(functions, null, 2);
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=generateMeta.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateMeta.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C,SAAS,CAAC,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AAC5C,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
interface GenerateSchemaOptions {
|
|
2
|
+
removeDateTime: boolean;
|
|
3
|
+
}
|
|
4
|
+
export declare class GenerateGlobalSchema {
|
|
5
|
+
private base;
|
|
6
|
+
private params;
|
|
7
|
+
constructor(base: string, params: GenerateSchemaOptions);
|
|
8
|
+
getSchema(): Promise<string>;
|
|
9
|
+
handle(): Promise<string>;
|
|
10
|
+
}
|
|
11
|
+
export declare function generateSchema(path: string, options: GenerateSchemaOptions): Promise<string>;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=generateSchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateSchema.d.ts","sourceRoot":"","sources":["../../src/helper/generateSchema.ts"],"names":[],"mappings":"AAGA,UAAU,qBAAqB;IAC7B,cAAc,EAAE,OAAO,CAAC;CACzB;AAUD,qBAAa,oBAAoB;IACnB,OAAO,CAAC,IAAI;IAAU,OAAO,CAAC,MAAM;gBAA5B,IAAI,EAAE,MAAM,EAAU,MAAM,EAAE,qBAAqB;IAEjE,SAAS;IAyCT,MAAM;CAcb;AAED,wBAAsB,cAAc,CAClC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,qBAAqB,mBAK/B"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import $RefParser from '@apidevtools/json-schema-ref-parser';
|
|
2
|
+
import * as ts from 'ts-json-schema-generator';
|
|
3
|
+
import { log } from '../log.js';
|
|
4
|
+
function addId(schema) {
|
|
5
|
+
return Object.fromEntries(Object.entries(schema).map(([key, value]) => {
|
|
6
|
+
return [key, { ...value, $id: `${key}` }];
|
|
7
|
+
}));
|
|
8
|
+
}
|
|
9
|
+
export class GenerateGlobalSchema {
|
|
10
|
+
constructor(base, params) {
|
|
11
|
+
this.base = base;
|
|
12
|
+
this.params = params;
|
|
13
|
+
}
|
|
14
|
+
async getSchema() {
|
|
15
|
+
const config = {
|
|
16
|
+
path: `${this.base}/**/*schema.ts`,
|
|
17
|
+
tsconfig: './tsconfig.json',
|
|
18
|
+
};
|
|
19
|
+
try {
|
|
20
|
+
const schema = ts.createGenerator(config).createSchema();
|
|
21
|
+
const removedReferences = await $RefParser.dereference(schema);
|
|
22
|
+
if (!removedReferences.definitions) {
|
|
23
|
+
throw new Error('definitions are missing');
|
|
24
|
+
}
|
|
25
|
+
const withIds = addId(removedReferences.definitions);
|
|
26
|
+
return JSON.stringify(withIds, null, 2);
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
if (e.message.includes('NoRootNamesError')) {
|
|
30
|
+
console.warn(`\nMissing interfaces for path: ${this.base}/controllers/*/interfaces.ts\n`);
|
|
31
|
+
return '';
|
|
32
|
+
}
|
|
33
|
+
if (e.diagnostics) {
|
|
34
|
+
e.diagnostics.forEach((element) => {
|
|
35
|
+
log({
|
|
36
|
+
component: 'cli',
|
|
37
|
+
warning: element.messageText,
|
|
38
|
+
details: element.file.fileName,
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
return '';
|
|
42
|
+
}
|
|
43
|
+
throw e;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async handle() {
|
|
47
|
+
let schema = await this.getSchema();
|
|
48
|
+
/*
|
|
49
|
+
schema = schema.replace(/, format: 'date-time'/g, '');
|
|
50
|
+
|
|
51
|
+
if (schema.includes('date-time')) {
|
|
52
|
+
console.warn(
|
|
53
|
+
`\ndate-time is used in schema. This causes issues with fastify serialization. Use string instead.\n`,
|
|
54
|
+
);
|
|
55
|
+
}*/
|
|
56
|
+
return schema;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export async function generateSchema(path, options) {
|
|
60
|
+
const instance = new GenerateGlobalSchema(path, options);
|
|
61
|
+
return instance.handle();
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=generateSchema.js.map
|
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,CAAC,CAAC,CAAC;SACzC;QAAC,OAAO,CAAM,EAAE;YACf,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE;gBAC1C,OAAO,CAAC,IAAI,CACV,kCAAkC,IAAI,CAAC,IAAI,gCAAgC,CAC5E,CAAC;gBACF,OAAO,EAAE,CAAC;aACX;YAED,IAAI,CAAC,CAAC,WAAW,EAAE;gBACjB,CAAC,CAAC,WAAW,CAAC,OAAO,CACnB,CAAC,OAA4D,EAAE,EAAE;oBAC/D,GAAG,CAAC;wBACF,SAAS,EAAE,KAAK;wBAChB,OAAO,EAAE,OAAO,CAAC,WAAW;wBAC5B,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,QAAQ;qBAC/B,CAAC,CAAC;gBACL,CAAC,CACF,CAAC;gBACF,OAAO,EAAE,CAAC;aACX;YAED,MAAM,CAAC,CAAC;SACT;IACH,CAAC;IACD,KAAK,CAAC,MAAM;QACV,IAAI,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC;QAEpC;;;;;;;WAOG;QAEH,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,IAAY,EACZ,OAA8B;IAE9B,MAAM,QAAQ,GAAG,IAAI,oBAAoB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAEzD,OAAO,QAAQ,CAAC,MAAM,EAAE,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateSdk.d.ts","sourceRoot":"","sources":["../../src/helper/generateSdk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAG3D,wBAAsB,WAAW,CAAC,GAAG,EAAE,iBAAiB,iBAmCvD"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { log } from '../log.js';
|
|
2
|
+
export async function generateSdk(sdk) {
|
|
3
|
+
const logFunction = console.log;
|
|
4
|
+
let warning = [''];
|
|
5
|
+
let error = [''];
|
|
6
|
+
console.log = () => { };
|
|
7
|
+
console.warn = (...message) => {
|
|
8
|
+
warning.push(message.join(' '));
|
|
9
|
+
};
|
|
10
|
+
console.error = (...message) => {
|
|
11
|
+
error.push(message.join(' '));
|
|
12
|
+
};
|
|
13
|
+
try {
|
|
14
|
+
const generator = await import('swagger-typescript-api');
|
|
15
|
+
await generator.default.generateApi(sdk);
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
console.error(err.message);
|
|
19
|
+
}
|
|
20
|
+
console.log = logFunction;
|
|
21
|
+
if (warning.length > 1) {
|
|
22
|
+
log({
|
|
23
|
+
component: 'cli',
|
|
24
|
+
warning: 'SDK warning',
|
|
25
|
+
details: warning.join('\n'),
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
if (error.length > 1) {
|
|
29
|
+
log({ component: 'cli', error: 'SDK error', details: error.join('\n') });
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
log({ component: 'cli', success: 'SDK written to', details: sdk.output });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=generateSdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateSdk.js","sourceRoot":"","sources":["../../src/helper/generateSdk.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAEhC,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,GAAsB;IACtD,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC;IAEhC,IAAI,OAAO,GAAG,CAAC,EAAE,CAAa,CAAC;IAC/B,IAAI,KAAK,GAAG,CAAC,EAAE,CAAa,CAAC;IAC7B,OAAO,CAAC,GAAG,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;IACvB,OAAO,CAAC,IAAI,GAAG,CAAC,GAAG,OAAO,EAAE,EAAE;QAC5B,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAClC,CAAC,CAAC;IACF,OAAO,CAAC,KAAK,GAAG,CAAC,GAAG,OAAO,EAAE,EAAE;QAC7B,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAChC,CAAC,CAAC;IAEF,IAAI;QACF,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,wBAAwB,CAAC,CAAC;QACzD,MAAM,SAAS,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;KAC1C;IAAC,OAAO,GAAQ,EAAE;QACjB,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;KAC5B;IAED,OAAO,CAAC,GAAG,GAAG,WAAW,CAAC;IAE1B,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE;QACtB,GAAG,CAAC;YACF,SAAS,EAAE,KAAK;YAChB,OAAO,EAAE,aAAa;YACtB,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;SAC5B,CAAC,CAAC;KACJ;IAED,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;QACpB,GAAG,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;KAC1E;SAAM;QACL,GAAG,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;KAC3E;AACH,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function cleanInterfaceName(name: string | undefined): string;
|
|
2
|
+
export declare function getControllerFunctions(file: string): {
|
|
3
|
+
className: string | undefined;
|
|
4
|
+
file: string;
|
|
5
|
+
functions: any;
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=getControllerFunctions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getControllerFunctions.d.ts","sourceRoot":"","sources":["../../src/helper/getControllerFunctions.ts"],"names":[],"mappings":"AAGA,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,UAW1D;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM;;;;EAwDlD"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Project, SyntaxKind } from 'ts-morph';
|
|
2
|
+
import { log } from '../log.js';
|
|
3
|
+
export function cleanInterfaceName(name) {
|
|
4
|
+
if (!name) {
|
|
5
|
+
return '';
|
|
6
|
+
}
|
|
7
|
+
return name
|
|
8
|
+
.replace('Promise<', '')
|
|
9
|
+
.replace('>', '')
|
|
10
|
+
.replace('void', '')
|
|
11
|
+
.split('.')
|
|
12
|
+
.slice(-1)[0];
|
|
13
|
+
}
|
|
14
|
+
export function getControllerFunctions(file) {
|
|
15
|
+
const project = new Project();
|
|
16
|
+
project.addSourceFileAtPath(file);
|
|
17
|
+
const parsed = project.getSourceFile(file);
|
|
18
|
+
if (!parsed) {
|
|
19
|
+
log({
|
|
20
|
+
component: 'cli',
|
|
21
|
+
error: 'File could not be parsed',
|
|
22
|
+
details: `${file}`,
|
|
23
|
+
});
|
|
24
|
+
throw new Error();
|
|
25
|
+
}
|
|
26
|
+
const classes = parsed.getDescendantsOfKind(SyntaxKind.ClassDeclaration);
|
|
27
|
+
if (!classes.length) {
|
|
28
|
+
log({
|
|
29
|
+
component: 'cli',
|
|
30
|
+
error: 'Controller file does not contain a class declaration',
|
|
31
|
+
details: `${file}`,
|
|
32
|
+
});
|
|
33
|
+
throw new Error();
|
|
34
|
+
}
|
|
35
|
+
if (classes.length > 1) {
|
|
36
|
+
log({
|
|
37
|
+
component: 'cli',
|
|
38
|
+
error: 'Controller must contain only one class declaration',
|
|
39
|
+
details: `${file}`,
|
|
40
|
+
});
|
|
41
|
+
throw new Error();
|
|
42
|
+
}
|
|
43
|
+
const className = classes[0].getName();
|
|
44
|
+
const declarations = classes[0].getInstanceMethods();
|
|
45
|
+
const mapped = declarations.reduce((acc, y) => {
|
|
46
|
+
const params = y.getParameters().map((x) => {
|
|
47
|
+
return {
|
|
48
|
+
name: x.getNameNode().getText(),
|
|
49
|
+
type: cleanInterfaceName(x.getTypeNode()?.getText()),
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
const name = y.getNameNode().getText();
|
|
53
|
+
const returnType = cleanInterfaceName(y.getReturnTypeNode()?.getText());
|
|
54
|
+
acc[name] = {
|
|
55
|
+
params,
|
|
56
|
+
returnType,
|
|
57
|
+
};
|
|
58
|
+
return acc;
|
|
59
|
+
}, {});
|
|
60
|
+
return { className, file, functions: mapped };
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=getControllerFunctions.js.map
|