Skip to content

Instantly share code, notes, and snippets.

@FND
Last active March 14, 2019 11:02
Show Gist options
  • Select an option

  • Save FND/7058b69a3af1e5527c04b34dfa39d4e7 to your computer and use it in GitHub Desktop.

Select an option

Save FND/7058b69a3af1e5527c04b34dfa39d4e7 to your computer and use it in GitHub Desktop.
test case for faucet-pipeline's watch mode on Windows
/node_modules

test case for faucet-pipeline's watch mode on Windows

  1. npm install
  2. npm run setup (required due to GitHub Gist restrictions)
  3. npm start
  4. modify src/sample.txt
    ⇒ change should be reported in console

note that under the hood, faucet uses nite-owl, which in turn relies on chokidar

let chokidar = require("chokidar");
let path = require("path");
let DIRPATH = "./src";
DIRPATH = path.resolve(__dirname, DIRPATH);
let PATTERNS = [path.resolve(DIRPATH, "**")];
let watcher = chokidar.watch(PATTERNS);
let notify = filepath => {
console.log("~~~", filepath);
};
watcher.on("ready", () => {
watcher.on("add", notify).
on("change", notify).
on("unlink", notify);
}).on("error", err => {
if(err.code === "ENOSPC") {
err = new Error("you are watching too many files - try limiting the " +
"directories being watched");
}
console.error(err);
process.exit(1);
});
{
"scripts": {
"start": "node ./mtc.js",
"setup": "node ./setup.js"
},
"dependencies": {},
"devDependencies": {
"chokidar": "^2.1.2"
}
}
lorem ipsum
dolor sit amet
let fs = require("fs");
let path = require("path");
let DIRPATH = path.resolve(__dirname, "./src");
let FILENAME = "sample.txt";
if(!fs.existsSync(DIRPATH)) {
fs.mkdirSync(DIRPATH);
}
fs.renameSync(FILENAME, path.resolve(DIRPATH, FILENAME));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment