Watching for changes in the dc09.js script

This commit is contained in:
DarkCat09 2023-03-16 17:21:15 +04:00
parent fa88138bc2
commit 3856235544

14
dc09.js
View file

@ -12,6 +12,7 @@ const exec = (cmd) => {
console.log(`Exec: ${cmd}`) console.log(`Exec: ${cmd}`)
return cp.execSync(cmd) return cp.execSync(cmd)
} }
const cwd = process.cwd()
const CleanCSS = require('clean-css') const CleanCSS = require('clean-css')
const Handlebars = require('handlebars') const Handlebars = require('handlebars')
@ -38,6 +39,18 @@ main()
function main() { function main() {
switch (process.argv[2]) { switch (process.argv[2]) {
case 'watch':
fs.watch(cwd, {recursive: true}, (_ev, file) => {
const rel = path.relative(cwd, file)
if (rel.includes('dist/'))
return
print(`Changed: ${file}`, true, '#', yellow)
const dirs = rel.split(path.sep)
const dir = (dirs.length > 1) ? dirs[0] : '.'
buildOne(dir)
})
break
case 'build': case 'build':
const dir = process.argv[3] const dir = process.argv[3]
if (dir) if (dir)
@ -57,6 +70,7 @@ function main() {
default: default:
print('Available actions:', true) print('Available actions:', true)
printList([ printList([
'watch',
'build', 'build',
'build <dir>', 'build <dir>',
'archive', 'archive',