From 0e380a26ba009c8b9bdea0a76146d29272c609de Mon Sep 17 00:00:00 2001 From: Lynn Smeria Date: Wed, 18 Mar 2020 01:30:56 +0200 Subject: [PATCH] Collect & simulate hooks --- hooks.js | 38 +++++++++++++++++++++++++++++++++ index.js | 59 +++++++++++++++++++++++++++++++++++++++++++++++----- package.json | 3 ++- yarn.lock | 5 +++++ 4 files changed, 99 insertions(+), 6 deletions(-) create mode 100644 hooks.js diff --git a/hooks.js b/hooks.js new file mode 100644 index 0000000..d5614f1 --- /dev/null +++ b/hooks.js @@ -0,0 +1,38 @@ +const fs = require('fs').promises; +const ms = require('ms'); +const os = require('os'); +const path = require('path'); + +const getHooksRoot = () => path.join(os.homedir(), '/.syncthing-hooks'); + +const readHooksRoot = async root => { + try { + const files = await fs.readdir(root); + return files; + } catch { + return []; + } +}; + +const parseHooks = (root, hooks) => + hooks + .map(x => ({ + path: path.join(root, x), + match: x.match(/(?.{11})-(?