// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors
// SPDX-License-Identifier: Apache-2.0
/* global process */
/* global console */
/*eslint no-process-exit: "off"*/
import botLayer from '@medplum/bot-layer/package.json' with { type: 'json' };
import esbuild from 'esbuild';
import fastGlob from 'fast-glob';
// Find all TypeScript files in your source directory
const entryPoints = fastGlob.sync('./src/**/*.ts').filter((file) => !file.endsWith('test.ts'));
const botLayerDeps = Object.keys(botLayer.dependencies);
// Define the esbuild options
const esbuildOptions = {
entryPoints: entryPoints,
bundle: true, // Bundle imported functions
outdir: './dist', // Output directory for compiled files
platform: 'node',
loader: {
'.ts': 'ts', // Load TypeScript files
},
resolveExtensions: ['.ts'],
external: botLayerDeps,
format: 'esm',
target: 'es2020', // Set the target ECMAScript version
tsconfig: 'tsconfig.json',
};
// Build using esbuild
esbuild
.build(esbuildOptions)
.then(() => {
console.log('Build completed successfully!');
})
.catch((error) => {
console.error('Build failed:', JSON.stringify(error, null, 2));
process.exit(1);
});