diff --git a/src/build/index.ts b/src/build/index.ts index 98b03fb3..b40ec594 100644 --- a/src/build/index.ts +++ b/src/build/index.ts @@ -1,6 +1,5 @@ import path from "node:path"; import process from "node:process"; -import fs from "node:fs/promises"; import { type RollupOptions, rollup } from "rollup"; import { JspmError, exists } from "../utils"; @@ -8,7 +7,7 @@ import type { Flags } from "../types"; import { RollupImportmapPlugin } from "./rollup-importmap-plugin"; export default async function build(entry: string, options: Flags) { - if (!entry && !options.buildConfig) { + if (!entry && !options.config) { throw new JspmError(`Please provide entry for the build`); } @@ -16,7 +15,7 @@ export default async function build(entry: string, options: Flags) { let outputOptions: RollupOptions["output"]; if (entry) { - if (!options.buildOutput) { + if (!options.output) { throw new JspmError(`Build output is required when entry is provided`); } @@ -30,12 +29,12 @@ export default async function build(entry: string, options: Flags) { }; outputOptions = { - file: path.join(process.cwd(), options.buildOutput), + dir: path.join(process.cwd(), options.output), }; } - if (options.buildConfig) { - const buildConfigPath = path.join(process.cwd(), options.buildConfig); + if (options.config) { + const buildConfigPath = path.join(process.cwd(), options.config); if ((await exists(buildConfigPath)) === false) { throw new JspmError( `Build config file does not exist: ${buildConfigPath}` @@ -61,11 +60,5 @@ export default async function build(entry: string, options: Flags) { } const builder = await rollup(buildConfig); - const result = await builder.generate({ format: "esm", ...outputOptions }); - - for (const file of result.output) { - const outputPath = path.join(process.cwd(), file.fileName); - const content = file.type === "asset" ? file.source : file.code; - await fs.writeFile(outputPath, content, "utf-8"); - } + await builder.write({ format: "esm", ...outputOptions }); } diff --git a/src/cli.ts b/src/cli.ts index 3ab893fd..667cc80f 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -92,13 +92,13 @@ const freezeOpt: opt = [ ]; const silentOpt: opt = ["--silent", "Silence all output", { default: false }]; const buildConfigOpt: opt = [ - "--build-config ", + "--config ", "Path to a rollup config file", {}, ]; const buildOutputOpt: opt = [ - "--build-output ", - "Path to the rollup output file", + "--output ", + "Path to the rollup output directory", {}, ]; diff --git a/src/types.ts b/src/types.ts index bd4f7820..69ce6198 100644 --- a/src/types.ts +++ b/src/types.ts @@ -19,7 +19,7 @@ export interface Flags extends BuildFlags { export interface BuildFlags { entry?: string; outdir?: string; - buildConfig?: string; + config: string; buildOutput?: string; }