forked from ferdikoomen/openapi-typescript-codegen
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbundle.js
executable file
·53 lines (49 loc) · 1.6 KB
/
bundle.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env node
const { configure } = require('esbd');
const fs = require('node:fs/promises');
const { precompile } = require('handlebars');
function hbs() {
return {
name: 'handlebars',
setup(build) {
const compileOptions = {
strict: true,
noEscape: true,
preventIndent: true,
knownHelpersOnly: true,
knownHelpers: {
ifdef: true,
equals: true,
notEquals: true,
containsSpaces: true,
union: true,
intersection: true,
enumerator: true,
escapeComment: true,
escapeDescription: true,
camelCase: true,
pascalCase: true,
},
};
build.onLoad({ filter: /\.hbs$/i }, async ({ path: filename }) => {
const source = await fs.readFile(filename, 'utf-8');
try {
const templateSpec = precompile(source.trim(), compileOptions);
return { contents: `export default ${templateSpec};`, loader: 'js' };
} catch (err) {
const esBuildError = { text: err.message };
return { errors: [esBuildError] };
}
});
},
};
}
configure({
entryPoints: { index: 'src/index.ts' },
outdir: 'dist',
platform: 'node',
external: ['commander'],
plugins: [hbs()],
sourcemap: false,
target: 'node16',
});