mirror of
https://github.com/jaronpate/unicord.git
synced 2026-10-18 21:47:40 +00:00
Added some stuff for beta release. Toying with a build script.
This commit is contained in:
+15
-6
@@ -4,19 +4,28 @@
|
||||
"module": "src/index.ts",
|
||||
"type": "module",
|
||||
"main": "out/index.js",
|
||||
"types": "out/index.d.ts",
|
||||
"files": [
|
||||
"out"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "bun run testing/demo.test.ts",
|
||||
"test:inspect": "bun --inspect testing/demo.test.ts",
|
||||
"build": "bun run build:types && bun build src/index.ts --outdir out",
|
||||
"build:packages": "bun run build:types && bun build src/index.ts --packages external --outdir out",
|
||||
"build:nocheck": "bun run build:types:nocheck && bun build src/index.ts --outdir out --noCheck",
|
||||
|
||||
"build": "bun run build:types && bun run build:core",
|
||||
"build:packages": "bun run build:types && bun run build:core -- --packages external",
|
||||
"build:nocheck": "bun run build:types:nocheck && bun run build:core",
|
||||
|
||||
"build:core": "bun build src/index.ts --outdir out --drop=console,debugger",
|
||||
"build:types": "tsc --emitDeclarationOnly --project tsconfig.json",
|
||||
"build:types:nocheck": "tsc --emitDeclarationOnly --project tsconfig.json --noCheck",
|
||||
"build:watch": "concurrently \"tsc --emitDeclarationOnly --project tsconfig.json --watch\" \"bun build src/index.ts --outdir out --watch\"",
|
||||
"build:packages:watch": "concurrently \"tsc --emitDeclarationOnly --project tsconfig.json --watch\" \"bun build src/index.ts --packages external --outdir out --watch\""
|
||||
"build:types:nocheck": "bun run build:types -- --noCheck",
|
||||
|
||||
"build:watch": "concurrently \"bun run build:types -- --watch\" \"bun run build:core -- --watch\"",
|
||||
"build:packages:watch": "concurrently \"bun run build:types -- --watch\" \"bun run build:core -- --packages external --watch\""
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bun": "latest",
|
||||
"commander": "^13.0.0",
|
||||
"concurrently": "^9.1.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
#!/usr/bin/env bun
|
||||
/**
|
||||
* Not used at the moment, was just playing around with the idea of using the bun JavaScript API to build the project.
|
||||
*/
|
||||
import { Command } from 'commander';
|
||||
import { build, type BuildConfig } from 'bun';
|
||||
import concurrently from 'concurrently';
|
||||
|
||||
// Initialize Commander to handle CLI commands and options
|
||||
const program = new Command();
|
||||
|
||||
// Paths and base TypeScript compilation command
|
||||
const srcFile = 'src/index.ts';
|
||||
const outDir = 'out';
|
||||
const tscBaseCmd = 'tsc --emitDeclarationOnly --project tsconfig.json';
|
||||
|
||||
/**
|
||||
* Handles the build process with optional watch and type emission.
|
||||
*
|
||||
* @param options - Object containing flags for watch, packages, noCheck, and typesOnly.
|
||||
*/
|
||||
async function runBuild(options: {
|
||||
watch?: boolean;
|
||||
packages?: boolean;
|
||||
noCheck?: boolean;
|
||||
typesOnly?: boolean;
|
||||
}) {
|
||||
// Handle TypeScript-only builds (e.g., for emitting declaration files without bundling)
|
||||
if (options.typesOnly) {
|
||||
// Construct the TypeScript command dynamically based on flags
|
||||
const tscCmd = `${tscBaseCmd}${options.noCheck ? ' --noCheck' : ''}${options.watch ? ' --watch' : ''}`;
|
||||
|
||||
// Run TypeScript compilation (watch mode if specified)
|
||||
await Bun.spawn(tscCmd.split(' ')).exited;
|
||||
return; // Exit early since no Bun build is needed for types-only mode
|
||||
}
|
||||
|
||||
// Define options for the Bun build process
|
||||
const buildOptions: BuildConfig = {
|
||||
entrypoints: [srcFile],
|
||||
outdir: outDir,
|
||||
drop: ['console', 'debugger'], // Strip console and debugger statements
|
||||
packages: options.packages ? 'external' : undefined
|
||||
};
|
||||
|
||||
// Handle watch mode: run both TypeScript and Bun build concurrently
|
||||
if (options.watch) {
|
||||
concurrently([
|
||||
{
|
||||
// Run TypeScript watch for continuous type emission
|
||||
command: `${tscBaseCmd} --watch${options.noCheck ? ' --noCheck' : ''}`,
|
||||
name: 'tsc', // Label the TypeScript process for logging
|
||||
},
|
||||
{
|
||||
// Run Bun build in watch mode
|
||||
command: `bun build ${srcFile} --outdir ${outDir} ${
|
||||
options.packages ? '--packages external' : ''
|
||||
} ${options.noCheck ? '--noCheck' : ''} --watch`,
|
||||
name: 'bun', // Label the Bun process for logging
|
||||
},
|
||||
], {
|
||||
|
||||
});
|
||||
} else {
|
||||
// Non-watch mode: Run TypeScript once, then trigger Bun build
|
||||
await Bun.spawn(tscBaseCmd.split(' ')).exited;
|
||||
|
||||
// Perform a standard Bun build
|
||||
await build(buildOptions);
|
||||
console.log(`Build completed.`);
|
||||
}
|
||||
}
|
||||
|
||||
// Register the build command and attach optional flags
|
||||
program
|
||||
.command('build')
|
||||
.description('Build project with options')
|
||||
.option('--watch', 'Watch for changes and rebuild')
|
||||
.option('--packages', 'Bundle external packages')
|
||||
.option('--nocheck', 'Skip type checking')
|
||||
.option('--types-only', 'Emit types without compiling the project')
|
||||
.action((opts) => {
|
||||
runBuild({
|
||||
watch: opts.watch,
|
||||
packages: opts.packages,
|
||||
noCheck: opts.nocheck,
|
||||
typesOnly: opts.typesOnly,
|
||||
});
|
||||
});
|
||||
|
||||
// Parse and execute CLI input
|
||||
program.parse();
|
||||
Reference in New Issue
Block a user