Created
June 18, 2018 14:18
-
-
Save syusui-s/91cd4f1f4e052b53df95eab097b490eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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