This is an automated email from the ASF dual-hosted git repository.

urfree pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pulsar-site.git


The following commit(s) were added to refs/heads/main by this push:
     new 5826159f0e8 fix: update watch scripts
5826159f0e8 is described below

commit 5826159f0e8c843b9326602bf7a79ffbc7e97f08
Author: Li Li <[email protected]>
AuthorDate: Thu May 26 16:35:50 2022 +0800

    fix: update watch scripts
    
    Signed-off-by: Li Li <[email protected]>
---
 site2/website-next/scripts/watch.js | 56 ++++++++++++++++++++-----------------
 1 file changed, 31 insertions(+), 25 deletions(-)

diff --git a/site2/website-next/scripts/watch.js 
b/site2/website-next/scripts/watch.js
index 697a2aa3d7f..da6028c4241 100644
--- a/site2/website-next/scripts/watch.js
+++ b/site2/website-next/scripts/watch.js
@@ -6,13 +6,41 @@ const versions = args.slice(1);
 let execa = null;
 (async () => {
   execa = (await import("execa")).execaCommand;
-  execa("sh preview.sh " + versions.join(" ")).stdout.pipe(process.stdout);
+  execa("sh preview.sh " + versions.join(" "), {
+    stdio: "inherit",
+  });
 })();
 
 const watcher = chokidar.watch([src + "/docs", src + "/website"], {
   persistent: true,
 });
 
+function _watch(path) {
+  let dest = src + "/.preview/pulsar-site/site2/website-next";
+  if (/pulsar-manager-release-notes\.md/.exec(path)) {
+    dest += "/pulsar-manager/pulsar-manager-release-notes.md";
+  } else if (/pulsar-manager-release\.json/.exec(path)) {
+    dest += "/pulsar-manager/pulsar-manager-release.json";
+  } else if (/pulsar-adapters-release\.json/.exec(path)) {
+    dest = "/pulsar-manager/pulsar-adapters-release.json";
+  } else if (/\/docs\/assets\/(.*)/.exec(path)) {
+    const r = /\/docs\/assets\/(.*)/.exec(path);
+    dest += "/static/assets/" + r[1];
+  } else if (/(\/docs\/.*)/.exec(path)) {
+    const r = /(\/docs\/.*)/.exec(path);
+    dest += r[1];
+  } else if (/\/website\/(.*)/.exec(path)) {
+    const r = /\/website\/(.*)/.exec(path);
+    dest += "/" + r[1];
+  } else {
+    console.log(path, "has been changed, do a full sync");
+    execa("sh scripts/sync-docs.sh " + src).stdout.pipe(process.stdout);
+    return;
+  }
+  console.log(path, "has been changed, sync to " + dest);
+  execa("cp -r " + path + " " + dest).stdout.pipe(process.stdout);
+}
+
 let inited = false;
 watcher
   .on("ready", function () {
@@ -21,31 +49,9 @@ watcher
   })
   .on("add", function (path) {
     if (inited) {
-      console.log(path, "has been added");
+      _watch(path);
     }
   })
   .on("change", function (path) {
-    let dest = src + "/.preview/pulsar-site/site2/website-next";
-    if (/pulsar-manager-release-notes\.md/.exec(path)) {
-      dest += "/pulsar-manager/pulsar-manager-release-notes.md";
-    } else if (/pulsar-manager-release\.json/.exec(path)) {
-      dest += "/pulsar-manager/pulsar-manager-release.json";
-    } else if (/pulsar-adapters-release\.json/.exec(path)) {
-      dest = "/pulsar-manager/pulsar-adapters-release.json";
-    } else if (/\/docs\/assets\/(.*)/.exec(path)) {
-      const r = /\/docs\/assets\/(.*)/.exec(path);
-      dest += "/static/assets/" + r[1];
-    } else if (/(\/docs\/.*)/.exec(path)) {
-      const r = /(\/docs\/.*)/.exec(path);
-      dest += r[1];
-    } else if (/\/website\/(.*)/.exec(path)) {
-      const r = /\/website\/(.*)/.exec(path);
-      dest += "/" + r[1];
-    } else {
-      console.log(path, "has been changed, do a full sync");
-      execa("sh scripts/sync-docs.sh " + src).stdout.pipe(process.stdout);
-      return;
-    }
-    console.log(path, "has been changed, sync to " + dest);
-    execa("cp -r " + path + " " + dest).stdout.pipe(process.stdout);
+    _watch(path);
   });

Reply via email to