UNPKG

907 BJavaScriptView Raw
1const watch = require('watch');
2const { spawnSync } = require('child_process');
3
4const watchOptions = {
5 ignoreDirectoryPattern: /node_modules/,
6 interval: 0.5,
7};
8
9let lastPrepublishTriggered = (new Date()).getTime();
10
11watch.createMonitor(`${__dirname}/../src/`, watchOptions, (monitor) => {
12 monitor.on('changed', (file) => {
13 if (file.indexOf('.test.js') > -1) return;
14 if (file.indexOf('.jsx') < 0 && file.indexOf('.scss') < 0) return;
15
16 const now = (new Date()).getTime();
17
18 // just debouncing to avoid multiple, useless runs of prepublishOnly
19 if (now - lastPrepublishTriggered < 2000) return;
20
21 lastPrepublishTriggered = now;
22 console.log(file);
23
24 const execution = spawnSync('npm', ['run', 'prepublishOnly']);
25
26 if (execution.stdout) return console.log(execution.stdout.toString());
27 if (execution.stderr) return console.log(execution.stderr.toString());
28 });
29});