36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
import { readdirSync } from "node:fs";
|
|
import path from "path";
|
|
|
|
const paths = [
|
|
'./src/functions/api/door'
|
|
];
|
|
|
|
const functionFiles = paths.map(path => readdirSync(path).map(file => path + "/" + file)).flat();
|
|
|
|
// for hot reload to work, we import all the files we want to build
|
|
const imports = functionFiles.forEach(file => require('./' + path.relative('src', file)));
|
|
|
|
console.log("functions to build:", functionFiles);
|
|
|
|
const bundledModules = ['dynabridge', 'zod_utilz'];
|
|
|
|
const externalModules = Object.keys(require('../package.json').dependencies)
|
|
.filter(dep => !bundledModules.includes(dep));
|
|
|
|
console.log("Explicitly bundling dependencies", bundledModules);
|
|
|
|
// console.log("external modules: ", externalModules);
|
|
|
|
console.log("Building functions...");
|
|
|
|
await Bun.build({
|
|
entrypoints: functionFiles,
|
|
outdir: './build/functions',
|
|
packages: 'bundle',
|
|
target: 'node',
|
|
// mark all deps as external EXCEPT for dynabridge, because we need to transpile it for CJS
|
|
external: externalModules,
|
|
root: './src/functions',
|
|
format: 'cjs',
|
|
});
|