-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
/
generate-available-frameworks.js
35 lines (29 loc) · 1.37 KB
/
generate-available-frameworks.js
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
31
32
33
34
35
// read ./code/frameworks subfolders and generate a list of available frameworks
// save this list into ./code/lib/cli/src/frameworks.ts and export it as a union type. The name of the type is `SupportedFrameworks`. Add additionally 'qwik' and `solid` to that list.
import { readdir, writeFile } from 'node:fs/promises';
import path from 'node:path';
import prettier from 'prettier';
import dedent from 'ts-dedent';
const thirdPartyFrameworks = ['qwik', 'solid', 'nuxt'];
const run = async () => {
const frameworks = await readdir(path.join(__dirname, '..', '..', '..', 'frameworks'));
const supportedFrameworks = frameworks.map((framework) => `'${framework}'`).join(' | ');
const fileContent = dedent`
// auto generated file, do not edit
// the file gets generated by the script ./code/lib/types/scripts/generate-available-frameworks.js
export type SupportedFrameworks = ${supportedFrameworks} | ${thirdPartyFrameworks
.map((framework) => `'${framework}'`)
.join(' | ')};
`;
const frameworksFile = path.join(__dirname, '..', 'src', 'modules', 'frameworks.ts');
const prettierConfig = await prettier.resolveConfig(frameworksFile);
const formattedFileContent = await prettier.format(fileContent, {
...prettierConfig,
parser: 'typescript',
});
await writeFile(frameworksFile, formattedFileContent);
};
run().catch((e) => {
console.error(e);
process.exit(1);
});