-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add CLI options for tsup with yargs
This update introduces yargs options to selectively build 'core' or 'scripts' files. This enhancement allows for targeted builds, saving time by avoiding unnecessary builds. Tsup's automatic handling of dependencies eliminates the need for direct transpilation of core files for script builds and verbose pathing to core and config files. This results in standalone output files, free from runtime external file dependencies. Furthermore, the script files are now output to a 'bin' directory, maintaining a clean 'dist' directory and indicating that the bin files are standalone scripts executable from the CLI and are not part of the main app.
- Loading branch information
Showing
2 changed files
with
68 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,4 +35,5 @@ urls.json | |
lh-config.js | ||
|
||
# TSC Output | ||
dist | ||
dist | ||
bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', | ||
}); | ||
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; | ||
} |