Skip to content

Instantly share code, notes, and snippets.

@syusui-s
Created June 18, 2018 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save syusui-s/91cd4f1f4e052b53df95eab097b490eb to your computer and use it in GitHub Desktop.
Save syusui-s/91cd4f1f4e052b53df95eab097b490eb to your computer and use it in GitHub Desktop.
const fs = require('fs');
const process = require('process');
const child_process = require('child_process');
const filename = 'test.mjs'
const x = fs.watch(filename, (t, f) => {
console.log(`eventType: ${t}, file: ${f}`)
try {
console.log(child_process.execSync(`ls -lah "${filename}"`, { encoding: 'utf-8' }))
} catch (e) {
// ignore error
}
});
console.log('start watching')
console.log('first write')
child_process.exec(`vim -c ":wq" "${filename}"`).on('close', () => {
console.log('second write')
child_process.exec(`vim -c ":wq" "${filename}"`).on('close', () => {
console.log('end')
console.log('もしも2回目の書込みでログが出なかったら、監視から外れている証拠。')
x.close()
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment