Skip to content

Commit

Permalink
Update esbuild.js
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermewerner committed Jan 25, 2024
1 parent 861eac0 commit d135a62
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions scripts/esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import { build } from "esbuild";
import { nodeExternalsPlugin } from "esbuild-node-externals";
import * as fs from "fs/promises";

const baseConfig = {
entryPoints: ["src/index.ts"],
Expand All @@ -11,7 +12,7 @@ const baseConfig = {
bundle: true,
minify: false,
sourcemap: false,
legalComments: "linked",
legalComments: "none",
plugins: [nodeExternalsPlugin()],
};

Expand All @@ -27,5 +28,21 @@ const legacyConfig = {
format: "cjs",
};

build(moduleConfig).catch(() => process.exit(1));
build(legacyConfig).catch(() => process.exit(1));
async function addCopyrightHeader(filename) {
const header = `// Copyright (c) Tribufu. All Rights Reserved.\n// SPDX-License-Identifier: MIT\n\n`;
const content = await fs.readFile(filename, 'utf-8');
await fs.writeFile(filename, header + content);
};

async function buildAndAddHeader(config) {
try {
await build(config);
await addCopyrightHeader(config.outfile);
} catch (error) {
console.error(error);
process.exit(1);
}
};

await buildAndAddHeader(moduleConfig);
await buildAndAddHeader(legacyConfig);

0 comments on commit d135a62

Please sign in to comment.