mirror of
https://github.com/yan-istart/IStart-Note-AI-Plugin.git
synced 2026-07-22 06:51:37 +00:00
Production builds now output version as '2.0.0+YYYYMMDDHHmm' in dist/manifest.json. Source manifest.json stays at '2.0.0'. This allows identifying exact builds without bumping the semver, useful during development and beta testing.
68 lines
1.8 KiB
JavaScript
68 lines
1.8 KiB
JavaScript
import esbuild from "esbuild";
|
|
import process from "process";
|
|
import { builtinModules } from "module";
|
|
import { copyFileSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
|
|
const banner = `/*
|
|
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
|
|
if you want to view the source, please visit the github repository of this plugin
|
|
*/
|
|
`;
|
|
|
|
const prod = process.argv[2] === "production";
|
|
|
|
const context = await esbuild.context({
|
|
banner: { js: banner },
|
|
entryPoints: ["src/main.ts"],
|
|
bundle: true,
|
|
external: [
|
|
"obsidian",
|
|
"electron",
|
|
"@codemirror/autocomplete",
|
|
"@codemirror/collab",
|
|
"@codemirror/commands",
|
|
"@codemirror/language",
|
|
"@codemirror/lint",
|
|
"@codemirror/search",
|
|
"@codemirror/state",
|
|
"@codemirror/view",
|
|
"@lezer/common",
|
|
"@lezer/highlight",
|
|
"@lezer/lr",
|
|
...builtinModules,
|
|
],
|
|
format: "cjs",
|
|
target: "es2018",
|
|
logLevel: "info",
|
|
sourcemap: prod ? false : "inline",
|
|
treeShaking: true,
|
|
outfile: "dist/main.js",
|
|
});
|
|
|
|
if (prod) {
|
|
await context.rebuild();
|
|
mkdirSync("dist", { recursive: true });
|
|
|
|
// Generate build number: version+YYYYMMDDHHmm
|
|
const manifest = JSON.parse(readFileSync("manifest.json", "utf8"));
|
|
const now = new Date();
|
|
const buildStamp = [
|
|
now.getFullYear(),
|
|
String(now.getMonth() + 1).padStart(2, "0"),
|
|
String(now.getDate()).padStart(2, "0"),
|
|
String(now.getHours()).padStart(2, "0"),
|
|
String(now.getMinutes()).padStart(2, "0"),
|
|
].join("");
|
|
const buildVersion = `${manifest.version}+${buildStamp}`;
|
|
|
|
// Write dist/manifest.json with build version
|
|
const distManifest = { ...manifest, version: buildVersion };
|
|
writeFileSync("dist/manifest.json", JSON.stringify(distManifest, null, 2) + "\n");
|
|
|
|
copyFileSync("styles.css", "dist/styles.css");
|
|
|
|
console.log(`Build complete: ${buildVersion}`);
|
|
process.exit(0);
|
|
} else {
|
|
await context.watch();
|
|
}
|