← Files Sulekha EventsARCHIVED FILE

source/scripts/prepare-deploy.js

1.5 KB · Nov 30, 2026 · 07:53 UTC

↓ Download file

import { build } from "esbuild";
import { cp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
import { fileURLToPath } from "node:url";
import widgetHtml, { widgetScript, widgetScriptPath } from "../src/widget-resource.js";

const root = new URL("../", import.meta.url);
const target = new URL("deploy/", root);
const pkg = JSON.parse(await readFile(new URL("package.json", root), "utf8"));
await rm(target, { recursive: true, force: true });
await mkdir(target, { recursive: true });
await build({
  entryPoints: [fileURLToPath(new URL("server.js", root))],
  outfile: fileURLToPath(new URL("server.js", target)),
  bundle: true,
  platform: "node",
  format: "cjs",
  target: "node22",
  legalComments: "eof",
  plugins: [{
    name: "embed-widget",
    setup(builder) {
      builder.onLoad({ filter: /widget-resource\.js$/ }, () => ({
        contents: `export default ${JSON.stringify(widgetHtml)}; export const widgetScript = ${JSON.stringify(widgetScript)}; export const widgetScriptPath = ${JSON.stringify(widgetScriptPath)};`, loader: "js"
      }));
    }
  }]
});
await writeFile(new URL("package.json", target), JSON.stringify({
  name: pkg.name, version: pkg.version, private: true, type: "commonjs",
  scripts: { start: "node server.js" }, engines: pkg.engines
}, null, 2) + "\n");
await cp(new URL("web.config", root), new URL("web.config", target));
console.log(`Deployment ready: ${fileURLToPath(target)}`);
console.log("Three files. Dependencies and widget are embedded. No npm install needed on Azure.");

SHA-256: be91d14a4c0d4913245b55fe9fdcf41c8b32e7cc2fc381e036aab41e00f37d45