Skip to content

Commit

Permalink
feat: add --config to the CLI (#440)
Browse files Browse the repository at this point in the history
Co-authored-by: Pooya Parsa <[email protected]>
  • Loading branch information
userquin and pi0 authored Oct 5, 2024
1 parent 2ea153a commit 7646e37
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ dist
types
.gen
.nyc_output
.idea/
7 changes: 5 additions & 2 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { createJiti } from "jiti";
export async function build(
rootDir: string,
stub: boolean,
inputConfig: BuildConfig = {},
inputConfig: BuildConfig & { config?: string } = {},
): Promise<void> {
// Determine rootDir
rootDir = resolve(process.cwd(), rootDir || ".");
Expand All @@ -31,7 +31,10 @@ export async function build(
const jiti = createJiti(rootDir);

const _buildConfig: BuildConfig | BuildConfig[] =
(await jiti.import("./build.config", { try: true, default: true })) || {};
(await jiti.import(inputConfig?.config || "./build.config", {
try: !inputConfig.config,
default: true,
})) || {};

const buildConfigs = (
Array.isArray(_buildConfig) ? _buildConfig : [_buildConfig]
Expand Down
9 changes: 9 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ const main = defineCommand({
description: "The directory to build",
required: false,
},
config: {
type: "string",
description: [
"The configuration file to use relative to the current working directory.",
" Unbuild tries to read `build.config` from the build `DIR` by default.",
"",
].join("\n"),
},
watch: {
type: "boolean",
description: "Watch the src dir and rebuild on change (experimental)",
Expand All @@ -38,6 +46,7 @@ const main = defineCommand({
const rootDir = resolve(process.cwd(), args.dir || ".");
await build(rootDir, args.stub, {
sourcemap: args.sourcemap,
config: args.config ? resolve(args.config) : undefined,
stub: args.stub,
watch: args.watch,
rollup: {
Expand Down

0 comments on commit 7646e37

Please sign in to comment.