refactor: Cleanup git state - commit all staged changes
Major refactoring cleanup: - Add new controller architecture (class-controller-*.php) - Add new settings-v2 UI (views/settings-v2/) - Add new CSS architecture (agentic-sidebar.css, tokens) - Add esbuild build pipeline (scripts/build.js, package.json) - Add composer dependencies (vendor/) - Add frontend src directory (assets/js/src/index.jsx) - Add documentation files - Remove old/obsolete files (class-settings.php, old CSS) This commits all pending changes from previous refactoring efforts.
This commit is contained in:
77
scripts/build.js
Normal file
77
scripts/build.js
Normal file
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Build script for WP Agentic Writer sidebar
|
||||
* Compiles index.jsx to dist/sidebar.js
|
||||
*/
|
||||
|
||||
const esbuild = require("esbuild");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
|
||||
const srcPath = path.join(__dirname, "..", "assets", "js", "src", "index.jsx");
|
||||
const distPath = path.join(
|
||||
__dirname,
|
||||
"..",
|
||||
"assets",
|
||||
"js",
|
||||
"dist",
|
||||
"sidebar.js",
|
||||
);
|
||||
|
||||
// Ensure dist directory exists
|
||||
const distDir = path.dirname(distPath);
|
||||
if (!fs.existsSync(distDir)) {
|
||||
fs.mkdirSync(distDir, { recursive: true });
|
||||
}
|
||||
|
||||
const isWatch = process.argv.includes("--watch");
|
||||
|
||||
const buildOptions = {
|
||||
entryPoints: [srcPath],
|
||||
bundle: true,
|
||||
outfile: distPath,
|
||||
// The source file is already a self-invoking IIFE: (function(wp){...})(window.wp).
|
||||
// Use anonymous IIFE wrapping WITHOUT a globalName so we never assign to (and
|
||||
// thereby clobber) the global `wp` that WordPress provides.
|
||||
format: "iife",
|
||||
target: ["es2019"],
|
||||
minify: !isWatch,
|
||||
sourcemap: isWatch,
|
||||
|
||||
// JSX settings - WordPress uses createElement
|
||||
jsx: "transform",
|
||||
jsxFactory: "wp.element.createElement",
|
||||
jsxFragment: "wp.element.Fragment",
|
||||
|
||||
// WordPress globals
|
||||
define: {
|
||||
"process.env.NODE_ENV": isWatch ? '"development"' : '"production"',
|
||||
},
|
||||
|
||||
// External dependencies (loaded by WordPress)
|
||||
external: [],
|
||||
|
||||
logLevel: "info",
|
||||
};
|
||||
|
||||
async function build() {
|
||||
if (isWatch) {
|
||||
const ctx = await esbuild.context(buildOptions);
|
||||
await ctx.watch();
|
||||
console.log("👀 Watching for changes...");
|
||||
|
||||
// Handle cleanup on exit
|
||||
process.on("SIGINT", async () => {
|
||||
console.log("\n✖ Stopping watcher...");
|
||||
await ctx.dispose();
|
||||
process.exit(0);
|
||||
});
|
||||
} else {
|
||||
const result = await esbuild.build(buildOptions);
|
||||
console.log("✅ Build complete!");
|
||||
}
|
||||
}
|
||||
|
||||
build().catch((err) => {
|
||||
console.error("❌ Build failed:", err);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user