diff --git a/.gitignore b/.gitignore index bbcb557..cd9141d 100644 --- a/.gitignore +++ b/.gitignore @@ -35,4 +35,5 @@ urls.json lh-config.js # TSC Output -dist \ No newline at end of file +dist +bin diff --git a/build.js b/build.js index 55a2f2a..3efff20 100644 --- a/build.js +++ b/build.js @@ -1,15 +1,72 @@ -import { build } from 'tsup'; +import { build as tsupBuild } from 'tsup'; +import yargs from 'yargs'; -await build({ - entry: { - index: 'src/core/index.ts', - createDashboard: 'src/scripts/createDashboard.ts', - updateDatadogMetricMetadata: 'src/scripts/updateDatadogMetricMetadata.ts', +const CORE_DIR = 'dist'; +const SCRIPTS_DIR = 'bin'; + +const argv = yargs(process.argv.slice(2)).options({ + target: { + alias: 't', + type: 'string', + description: 'Build target', + choices: ['all', 'core', 'scripts'], + default: 'all' + }, + silent: { + alias: 's', + type: 'boolean', + description: 'Silent mode', + default: false }, + clean: { + alias: 'c', + type: 'boolean', + description: 'Clean out files before build', + default: false + }, +}).strict().parseSync(); + +const config = { splitting: false, // don't split code into chunks - clean: true, platform: 'node', // environment to build for target: 'node20', - outDir: 'dist', format: 'esm', -}); \ No newline at end of file + silent: argv.silent, + clean: argv.clean, +} + +const CORE_BUILD = { + ...config, + outDir: CORE_DIR, + entry: { + index: 'src/core/index.ts', + }, +} + +const SCRIPTS_BUILD = { + ...config, + outDir: SCRIPTS_DIR, + entry: ['src/scripts/*'], +} + +async function build(buildConfig, buildTarget) { + try { + await tsupBuild(buildConfig); + } catch (e) { + console.error(`Failed to build ${buildTarget}:`, e); + process.exit(1); + } +} + +switch(argv.target) { + case 'all': + await build(CORE_BUILD, 'core'); + await build(SCRIPTS_BUILD, 'scripts'); + break; + case 'core': + await build(CORE_BUILD, 'core'); + break; + case 'scripts': + await build(SCRIPTS_BUILD, 'scripts'); + break; +}