From 9c2fdfc574fc60ef5a8a908280540c623fa237e6 Mon Sep 17 00:00:00 2001 From: murashit Date: Sat, 30 May 2026 11:00:08 +0900 Subject: [PATCH] Simplify plugin build scripts --- esbuild.config.mjs | 19 ++++++------------- package.json | 6 +++--- scripts/check.mjs | 6 +++--- tests/scripts/development-scripts.test.ts | 15 ++++++++++++++- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/esbuild.config.mjs b/esbuild.config.mjs index 9c080204..20768bae 100644 --- a/esbuild.config.mjs +++ b/esbuild.config.mjs @@ -1,9 +1,10 @@ import esbuild from "esbuild"; -const production = process.argv.includes("--production"); -const watch = process.argv.includes("--watch"); +import { buildStyles } from "./scripts/build-styles.mjs"; -const context = await esbuild.context({ +await buildStyles(); + +await esbuild.build({ entryPoints: ["src/main.ts"], bundle: true, external: ["obsidian"], @@ -12,15 +13,7 @@ const context = await esbuild.context({ target: "es2022", jsx: "automatic", outfile: "main.js", - sourcemap: production ? false : "inline", - minify: production, + sourcemap: false, + minify: true, logLevel: "info", }); - -if (watch) { - await context.watch(); - console.log("Watching Codex Panel plugin..."); -} else { - await context.rebuild(); - await context.dispose(); -} diff --git a/package.json b/package.json index e3ae27c3..75e25003 100644 --- a/package.json +++ b/package.json @@ -14,9 +14,9 @@ }, "homepage": "https://github.com/murashit/codex-panel#readme", "scripts": { + "build:styles": "node scripts/build-styles.mjs", + "build:styles:check": "node scripts/build-styles.mjs --check", "build": "node esbuild.config.mjs", - "build:prod": "node esbuild.config.mjs --production", - "dev": "node esbuild.config.mjs --watch", "format": "node scripts/format.mjs", "format:check": "node scripts/format.mjs --check --cache", "format:check:ci": "node scripts/format.mjs --check", @@ -24,7 +24,7 @@ "api:baseline:check": "node scripts/api-baseline.mjs --check", "generate:app-server-types": "node scripts/generate-app-server-types.mjs", "lint": "node scripts/run-parallel.mjs lint:ts lint:css", - "lint:css": "stylelint \"*.css\" \"src/**/*.css\" --max-warnings=0", + "lint:css": "stylelint \"src/**/*.css\" --max-warnings=0", "lint:ts": "eslint src tests scripts \"*.config.ts\" \"*.config.mjs\" --max-warnings=0 --cache --cache-location node_modules/.cache/eslint/ --cache-strategy content", "lint:ts:ci": "eslint src tests scripts \"*.config.ts\" \"*.config.mjs\" --max-warnings=0", "release:check": "node scripts/release/check.mjs", diff --git a/scripts/check.mjs b/scripts/check.mjs index 764cc77a..32512bcd 100644 --- a/scripts/check.mjs +++ b/scripts/check.mjs @@ -11,12 +11,12 @@ for (const arg of args) { } if (args.has("--ci")) { - for (const script of ["typecheck:ci", "test:ci", "lint:ts:ci", "lint:css", "format:check:ci", "build:prod"]) { + for (const script of ["typecheck:ci", "test:ci", "lint:ts:ci", "lint:css", "format:check:ci", "build:styles:check", "build"]) { run(npmCommand, ["run", script]); } } else { - run("node", ["scripts/run-parallel.mjs", "typecheck", "test", "lint:ts", "lint:css", "format:check"]); - run(npmCommand, ["run", "build:prod"]); + run("node", ["scripts/run-parallel.mjs", "typecheck", "test", "lint:ts", "lint:css", "format:check", "build:styles:check"]); + run(npmCommand, ["run", "build"]); } function run(command, args) { diff --git a/tests/scripts/development-scripts.test.ts b/tests/scripts/development-scripts.test.ts index 38d9e07a..e9eb6431 100644 --- a/tests/scripts/development-scripts.test.ts +++ b/tests/scripts/development-scripts.test.ts @@ -17,7 +17,7 @@ describe("development scripts", () => { "lint:ts:ci": 'node -e "process.exit(0)"', "lint:css": 'node -e "process.exit(0)"', "format:check:ci": 'node -e "process.exit(0)"', - "build:prod": 'node -e "process.exit(0)"', + build: 'node -e "process.exit(0)"', }, }); @@ -26,6 +26,19 @@ describe("development scripts", () => { expect(result.status).toBe(7); }); + it("fails style builds when CSS files are missing from the style manifest", async () => { + const cwd = await tempWorkspace(); + await mkdir(path.join(cwd, "src", "styles"), { recursive: true }); + await writeJson(path.join(cwd, "src", "styles", "manifest.json"), ["00-tokens.css"]); + await writeFile(path.join(cwd, "src", "styles", "00-tokens.css"), ".codex-panel { color: var(--text-normal); }\n"); + await writeFile(path.join(cwd, "src", "styles", "10-unlisted.css"), ".codex-panel__extra { display: block; }\n"); + + const result = runNodeScript("scripts/build-styles.mjs", ["--check"], cwd); + + expect(result.status).toBe(1); + expect(result.stderr).toContain("CSS files missing from src/styles/manifest.json: 10-unlisted.css"); + }); + it("passes the expected codex generate-ts arguments", async () => { const cwd = await tempWorkspace(); const binDir = path.join(cwd, "bin");