-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.ts
More file actions
30 lines (26 loc) · 1.25 KB
/
app.ts
File metadata and controls
30 lines (26 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { join } from 'path';
import { writeFile } from '../../utils/writeFile.js';
import type { GeneratorOptions } from '../interface.js';
import { SourceFileBuilder } from '../../utils/sourceFileBuilder.js';
import { RouterMountBuilder } from '../../utils/templates.js';
export async function generateApp(outputDir: string, options: GeneratorOptions): Promise<void> {
const hasPanel = options.appExtensions.includes('custom-panel');
const hasModal = options.appExtensions.includes('custom-modal');
const mounts = new RouterMountBuilder()
.add('/oauth', 'oauthRouter')
.addIf(options.webhooks, '/webhooks', 'webhooksRouter')
.addIf(hasPanel, '/extensions/panel', 'panelRouter')
.addIf(hasModal, '/extensions/modal', 'modalRouter')
.build();
const content = new SourceFileBuilder()
.importDefault('express', 'express')
.importDefault('./oauth/index.js', 'oauthRouter')
.importDefaultIf(options.webhooks, './webhooks/index.js', 'webhooksRouter')
.importDefaultIf(hasPanel, './app-extensions/panel/index.js', 'panelRouter')
.importDefaultIf(hasModal, './app-extensions/modal/index.js', 'modalRouter')
.addBlock('const app = express();')
.addBlock(mounts)
.exportDefault('app')
.build();
await writeFile(join(outputDir, 'src/app.ts'), content);
}