Browse Source

watch utils folder and build it when updated

Aakansha Doshi 1 year ago
parent
commit
7522285869
4 changed files with 20 additions and 2 deletions
  1. 1 1
      package.json
  2. 2 0
      scripts/buildUtils.js
  3. 16 0
      scripts/watchUtils.js
  4. 1 1
      yarn.lock

+ 1 - 1
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",

+ 2 - 0
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");

+ 16 - 0
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");
+});

+ 1 - 1
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:
+[email protected], "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==