From d135a62300d133fb719648fe4b16555dec32bfbb Mon Sep 17 00:00:00 2001 From: Guilherme Werner Date: Wed, 24 Jan 2024 21:01:02 -0300 Subject: [PATCH] Update esbuild.js --- scripts/esbuild.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/scripts/esbuild.js b/scripts/esbuild.js index f2974cb..ea28cd6 100644 --- a/scripts/esbuild.js +++ b/scripts/esbuild.js @@ -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"], @@ -11,7 +12,7 @@ const baseConfig = { bundle: true, minify: false, sourcemap: false, - legalComments: "linked", + legalComments: "none", plugins: [nodeExternalsPlugin()], }; @@ -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);