forked from bs-community/blessing-skin-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatch.js
29 lines (26 loc) · 796 Bytes
/
watch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const fs = require('fs')
const dirname = require('path').dirname
const chokidar = require('chokidar')
const mkdirp = require('mkdirp')
const args = require('minimist')(process.argv.slice(2))
const dest = args.dest || '../blessing-skin-server/public/plugins'
chokidar
.watch('**/assets/**/*', {
ignored: [/(^|[\/\\])\../, '**/assets/src'],
ignoreInitial: true,
})
.on('all', (_, path) => {
try {
fs.accessSync(path)
} catch (_) {
fs.unlink(`${dest}/${path}`, err => err && console.error(err))
return
}
const dir = `${dest}/${dirname(path)}`
try {
fs.accessSync(dir, fs.constants.F_OK | fs.constants.W_OK)
} catch (error) {
mkdirp.sync(dir)
}
fs.copyFile(path, `${dest}/${path}`, err => err && console.error(err))
})