Zum Inhalt

scripts/build-standalone.js

#!/usr/bin/env node
/**
 * scripts/build-standalone.js — one-file bundle for embedding.
 *
 * Concatenates the four runtime scripts (in load order) into
 * `dist/perlin-noise.js`, so a third party can embed with a single
 * <script> tag plus a <perlin-noise> element instead of four includes.
 *
 * No bundler — plain concatenation. Each source guards its own `window`
 * global (and its IIFE keeps its locals private), so load order is the
 * only thing that matters. In the spirit of the other scripts/ tools.
 *
 * Run:   node scripts/build-standalone.js
 */
"use strict";

const fs = require("fs");
const path = require("path");

const root = path.join(__dirname, "..");
const files = ["perlin.js", "perlin-presets.js", "perlin-engine.js", "perlin-element.js"];

const header =
  "/* perlin-noise standalone bundle — generated by scripts/build-standalone.js.\n" +
  "   Do not edit; run the script to regenerate. @license AGPL-3.0-or-later */\n";

const body = files
  .map((f) => `\n/* ===== ${f} ===== */\n` + fs.readFileSync(path.join(root, f), "utf8"))
  .join("\n");

fs.mkdirSync(path.join(root, "dist"), { recursive: true });
fs.writeFileSync(path.join(root, "dist", "perlin-noise.js"), header + body);
console.log("wrote dist/perlin-noise.js (" + files.length + " sources concatenated)");