From 29f30131f6a305ae9a25c21ab610c613b68fdcec Mon Sep 17 00:00:00 2001 From: CodexNexor Date: Mon, 4 May 2026 13:11:14 +0530 Subject: [PATCH] Fix Windows build compatibility in package scripts --- packages/browser-bundle/package.json | 2 +- packages/browser-bundle/scripts/prepare-dist.mjs | 9 +++++++++ packages/openui-cli/package.json | 2 +- packages/openui-cli/scripts/build-templates.mjs | 13 +++++++++++++ packages/react-ui/cp-css.js | 3 ++- packages/react-ui/package.json | 2 +- packages/react-ui/scripts/clean-dist.mjs | 8 ++++++++ 7 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 packages/browser-bundle/scripts/prepare-dist.mjs create mode 100644 packages/openui-cli/scripts/build-templates.mjs create mode 100644 packages/react-ui/scripts/clean-dist.mjs diff --git a/packages/browser-bundle/package.json b/packages/browser-bundle/package.json index 8d58eacfe..358964fed 100644 --- a/packages/browser-bundle/package.json +++ b/packages/browser-bundle/package.json @@ -15,7 +15,7 @@ "./package.json": "./package.json" }, "scripts": { - "build": "rm -rf dist && mkdir -p dist && esbuild src/entry.js --bundle --format=iife --minify --outfile=dist/openui-bundle.min.js '--define:process.env.NODE_ENV=\"production\"' --target=es2020 && node scripts/concat-css.mjs", + "build": "node scripts/prepare-dist.mjs && esbuild src/entry.js --bundle --format=iife --minify --outfile=dist/openui-bundle.min.js '--define:process.env.NODE_ENV=\"production\"' --target=es2020 && node scripts/concat-css.mjs", "typecheck": "echo \"(no types to check — IIFE bundle)\"", "lint:check": "eslint ./src", "lint:fix": "eslint ./src --fix", diff --git a/packages/browser-bundle/scripts/prepare-dist.mjs b/packages/browser-bundle/scripts/prepare-dist.mjs new file mode 100644 index 000000000..f0de9d778 --- /dev/null +++ b/packages/browser-bundle/scripts/prepare-dist.mjs @@ -0,0 +1,9 @@ +import { mkdir, rm } from "node:fs/promises"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; + +const dirname = path.dirname(fileURLToPath(import.meta.url)); +const distDir = path.resolve(dirname, "..", "dist"); + +await rm(distDir, { force: true, recursive: true }); +await mkdir(distDir, { recursive: true }); diff --git a/packages/openui-cli/package.json b/packages/openui-cli/package.json index b1b4ba98e..fdeac0532 100644 --- a/packages/openui-cli/package.json +++ b/packages/openui-cli/package.json @@ -11,7 +11,7 @@ ], "scripts": { "build:cli": "tsc -p .", - "build:templates": "rm -rf dist/templates/openui-chat && mkdir -p dist/templates && cp -R src/templates/openui-chat dist/templates/openui-chat", + "build:templates": "node scripts/build-templates.mjs", "build": "pnpm run build:cli && pnpm run build:templates", "build:exec": "node dist/index.js", "lint:check": "eslint ./src --ignore-pattern 'src/templates/**'", diff --git a/packages/openui-cli/scripts/build-templates.mjs b/packages/openui-cli/scripts/build-templates.mjs new file mode 100644 index 000000000..28da3ffb2 --- /dev/null +++ b/packages/openui-cli/scripts/build-templates.mjs @@ -0,0 +1,13 @@ +import { cp, mkdir, rm } from "node:fs/promises"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; + +const dirname = path.dirname(fileURLToPath(import.meta.url)); +const packageDir = path.resolve(dirname, ".."); +const sourceDir = path.join(packageDir, "src", "templates", "openui-chat"); +const templatesDir = path.join(packageDir, "dist", "templates"); +const targetDir = path.join(templatesDir, "openui-chat"); + +await rm(targetDir, { force: true, recursive: true }); +await mkdir(templatesDir, { recursive: true }); +await cp(sourceDir, targetDir, { recursive: true }); diff --git a/packages/react-ui/cp-css.js b/packages/react-ui/cp-css.js index 52d1087d7..720948642 100644 --- a/packages/react-ui/cp-css.js +++ b/packages/react-ui/cp-css.js @@ -1,8 +1,9 @@ import fs from "fs"; import { camelCase } from "lodash-es"; import path from "path"; +import { fileURLToPath } from "url"; -const dirname = path.dirname(new URL(import.meta.url).pathname); +const dirname = path.dirname(fileURLToPath(import.meta.url)); // Create directories if they don't exist function ensureDirectoryExists(dirPath) { diff --git a/packages/react-ui/package.json b/packages/react-ui/package.json index 45f2c69ab..b9ca9aaea 100644 --- a/packages/react-ui/package.json +++ b/packages/react-ui/package.json @@ -64,7 +64,7 @@ "copy-css": "node cp-css.js", "generate-scss-index": "node src/scripts/scss-import.js", "generate:css-utils": "tsx src/scripts/generate-css-utils.ts", - "build": "rm -rf dist && pnpm generate:css-utils && pnpm build:scss && pnpm build:tsc && pnpm build:cjs && pnpm run copy-css", + "build": "node scripts/clean-dist.mjs && pnpm generate:css-utils && pnpm build:scss && pnpm build:tsc && pnpm build:cjs && pnpm run copy-css", "typecheck": "tsc --noEmit", "build:tsc": "tsc -p . || true", "build:cjs": "tsdown", diff --git a/packages/react-ui/scripts/clean-dist.mjs b/packages/react-ui/scripts/clean-dist.mjs new file mode 100644 index 000000000..b2b8a99d0 --- /dev/null +++ b/packages/react-ui/scripts/clean-dist.mjs @@ -0,0 +1,8 @@ +import { rm } from "node:fs/promises"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; + +const dirname = path.dirname(fileURLToPath(import.meta.url)); +const distDir = path.resolve(dirname, "..", "dist"); + +await rm(distDir, { force: true, recursive: true });