Skip to content
This repository was archived by the owner on Dec 18, 2023. It is now read-only.

Commit 7ab51bf

Browse files
authored
Merge pull request #19 from livestorm/liv-5996-plugins-cli-watch-should-be-debounced
feat(watch): add debounce to avoid a long wait before plugin is really update, liv-5996
2 parents b51e499 + 4ba48d7 commit 7ab51bf

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"adm-zip": "^0.5.5",
1616
"cliff": "^0.1.10",
1717
"command-line-args": "^5.1.1",
18+
"debounce": "^1.2.1",
1819
"node-fetch": "^2.6.1",
1920
"node-watch": "^0.7.2",
2021
"prompts": "^2.4.0",

src/cmds/watch.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
const fs = require('fs')
22
const { execSync } = require('child_process')
3+
const nodeWatch = require('node-watch');
4+
const debounce = require('debounce')
35
const getLivestormPluginInformation = require('../helpers/getLivestormPluginInformation')
46
const env = process.argv[3]
5-
const nodeWatch = require('node-watch');
6-
77

88
function updatePlugin(evt, name) {
9-
console.log('%s changed', name);
9+
console.log('Updating plugin');
1010
process.stdout.write('\x1b[0m.\x1b[0m')
1111

1212
try {
@@ -30,10 +30,9 @@ module.exports = function watch() {
3030
nodeWatch('./', {
3131
recursive: true,
3232
filter: (f, skip) => {
33-
if (/\/node_modules/.test(f)) return skip;
34-
if (/\/build/.test(f)) return skip;
35-
if (/\/\.git/.test(f)) return skip;
33+
if (/node_modules/.test(f)) return skip;
34+
if (/.git/.test(f)) return skip;
3635
return true
3736
},
38-
}, updatePlugin);
37+
}, debounce(updatePlugin, 300));
3938
}

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ [email protected]:
6969
resolved "https://registry.yarnpkg.com/cycle/-/cycle-1.0.3.tgz#21e80b2be8580f98b468f379430662b046c34ad2"
7070
integrity sha1-IegLK+hYD5i0aPN5QwZisEbDStI=
7171

72+
debounce@^1.2.1:
73+
version "1.2.1"
74+
resolved "https://registry.yarnpkg.com/debounce/-/debounce-1.2.1.tgz#38881d8f4166a5c5848020c11827b834bcb3e0a5"
75+
integrity sha512-XRRe6Glud4rd/ZGQfiV1ruXSfbvfJedlV9Y6zOlP+2K04vBYiJEte6stfFkCP03aMnY5tsipamumUjL14fofug==
76+
7277
[email protected], eyes@~0.1.8:
7378
version "0.1.8"
7479
resolved "https://registry.yarnpkg.com/eyes/-/eyes-0.1.8.tgz#62cf120234c683785d902348a800ef3e0cc20bc0"

0 commit comments

Comments
 (0)