feat: add yarn dev watcher script

This commit is contained in:
ndom91 2021-09-04 23:57:25 +02:00 committed by thatmattlove
parent 4913d7ee39
commit 7ce0cdedb0
3 changed files with 37 additions and 1 deletions

View File

@ -0,0 +1,34 @@
const { exec, execSync } = require('child_process')
const chokidar = require('chokidar')
const sassWatcher = chokidar.watch('styles/**/*.scss')
const tsWatcher = chokidar.watch('src/**/*.ts')
const collectStatic = (type) => {
console.log('bundling...')
let args = ""
if (type === 'style') args += "--styles"
if (type === 'script') args += "--scripts"
execSync(`node bundle.js ${args}`)
console.log('collecting...')
exec("../../venv/bin/python3 ../manage.py collectstatic --no-input", (err, stdout, stderr) => {
err && console.error(err)
stdout && console.log(stdout)
stderr && console.log('python err:',stderr)
console.log('waiting...')
})
}
sassWatcher
.on('change', path => {
console.log(`Sass file ${path} has changed`)
collectStatic('style')
})
tsWatcher
.on('change', path => {
console.log(`TS file ${path} has changed`)
collectStatic('script')
})

View File

@ -8,6 +8,7 @@
"netbox-graphiql" "netbox-graphiql"
], ],
"scripts": { "scripts": {
"dev": "node develop.js",
"bundle": "node bundle.js", "bundle": "node bundle.js",
"bundle:styles": "node bundle.js --styles", "bundle:styles": "node bundle.js --styles",
"bundle:scripts": "node bundle.js --scripts", "bundle:scripts": "node bundle.js --scripts",
@ -44,6 +45,7 @@
"@types/masonry-layout": "^4.2.2", "@types/masonry-layout": "^4.2.2",
"@typescript-eslint/eslint-plugin": "^4.29.3", "@typescript-eslint/eslint-plugin": "^4.29.3",
"@typescript-eslint/parser": "^4.29.3", "@typescript-eslint/parser": "^4.29.3",
"chokidar": "^3.5.2",
"esbuild": "^0.12.24", "esbuild": "^0.12.24",
"esbuild-sass-plugin": "^1.5.2", "esbuild-sass-plugin": "^1.5.2",
"eslint": "^7.32.0", "eslint": "^7.32.0",

View File

@ -608,7 +608,7 @@ chalk@^4.0.0:
ansi-styles "^4.1.0" ansi-styles "^4.1.0"
supports-color "^7.1.0" supports-color "^7.1.0"
"chokidar@>=3.0.0 <4.0.0": "chokidar@>=3.0.0 <4.0.0", chokidar@^3.5.2:
version "3.5.2" version "3.5.2"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.2.tgz#dba3976fcadb016f66fd365021d91600d01c1e75" resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.2.tgz#dba3976fcadb016f66fd365021d91600d01c1e75"
integrity sha512-ekGhOnNVPgT77r4K/U3GDhu+FQ2S8TnK/s2KbIGXi0SZWuwkZ2QNyfWdZW+TVfn84DpEP7rLeCt2UI6bJ8GwbQ== integrity sha512-ekGhOnNVPgT77r4K/U3GDhu+FQ2S8TnK/s2KbIGXi0SZWuwkZ2QNyfWdZW+TVfn84DpEP7rLeCt2UI6bJ8GwbQ==