From 75222858694902c7d99c8ae0b42717cf29171189 Mon Sep 17 00:00:00 2001 From: Aakansha Doshi Date: Thu, 9 May 2024 13:31:07 +0530 Subject: [PATCH] watch utils folder and build it when updated --- package.json | 2 +- scripts/buildUtils.js | 2 ++ scripts/watchUtils.js | 16 ++++++++++++++++ yarn.lock | 2 +- 4 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 scripts/watchUtils.js diff --git a/package.json b/package.json index 89c22f138..298661c4a 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "locales-coverage:description": "node scripts/locales-coverage-description.js", "prepare": "husky install", "prettier": "prettier \"**/*.{css,scss,json,md,html,yml}\" --ignore-path=.eslintignore", - "start": "yarn clear:workspaces && yarn workspace @excalidraw/utils run build:esm && yarn --cwd ./excalidraw-app start", + "start": "yarn clear:workspaces && yarn workspace @excalidraw/utils run build:esm && yarn --cwd ./excalidraw-app start & node scripts/watchUtils.js", "start:app:production": "npm run build && npx http-server build -a localhost -p 5001 -o", "test:all": "yarn test:typecheck && yarn test:code && yarn test:other && yarn test:app --watch=false", "test:app": "vitest", diff --git a/scripts/buildUtils.js b/scripts/buildUtils.js index 1d51f11c1..a0c7273f9 100644 --- a/scripts/buildUtils.js +++ b/scripts/buildUtils.js @@ -121,5 +121,7 @@ const createESMRawBuild = async () => { fs.writeFileSync("meta-raw-prod.json", JSON.stringify(rawProd.metafile)); }; +console.info("BUILDING UTILS STARTED"); createESMRawBuild(); createESMBrowserBuild(); +console.info("BUILDING UTILS COMPLETE"); diff --git a/scripts/watchUtils.js b/scripts/watchUtils.js new file mode 100644 index 000000000..232dad148 --- /dev/null +++ b/scripts/watchUtils.js @@ -0,0 +1,16 @@ +const chokidar = require("chokidar"); +const path = require("path"); +const { execSync } = require("child_process"); + +const BASE_PATH = `${path.resolve(`${__dirname}/..`)}`; +const utilsDir = `${BASE_PATH}/packages/utils/src`; +// One-liner for current directory +chokidar.watch(utilsDir).on("change", (event) => { + console.info("Watching", event); + try { + execSync(`yarn workspace @excalidraw/utils run build:src`); + } catch (err) { + console.error("Error when building workspace", err); + } + console.info("BUILD DONE"); +}); diff --git a/yarn.lock b/yarn.lock index 1b4507be5..269bc96c6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4660,7 +4660,7 @@ check-error@^1.0.2, check-error@^1.0.3: dependencies: get-func-name "^2.0.2" -"chokidar@>=3.0.0 <4.0.0", chokidar@^3.5.1, chokidar@^3.5.3: +chokidar@3.6.0, "chokidar@>=3.0.0 <4.0.0", chokidar@^3.5.1, chokidar@^3.5.3: version "3.6.0" resolved "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz#197c6cc669ef2a8dc5e7b4d97ee4e092c3eb0d5b" integrity sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==