diff --git a/netbox/project-static/develop.js b/netbox/project-static/develop.js new file mode 100644 index 000000000..67785981a --- /dev/null +++ b/netbox/project-static/develop.js @@ -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') + }) + diff --git a/netbox/project-static/package.json b/netbox/project-static/package.json index 4ec08d7b3..5d58696bc 100644 --- a/netbox/project-static/package.json +++ b/netbox/project-static/package.json @@ -8,6 +8,7 @@ "netbox-graphiql" ], "scripts": { + "dev": "node develop.js", "bundle": "node bundle.js", "bundle:styles": "node bundle.js --styles", "bundle:scripts": "node bundle.js --scripts", @@ -44,6 +45,7 @@ "@types/masonry-layout": "^4.2.2", "@typescript-eslint/eslint-plugin": "^4.29.3", "@typescript-eslint/parser": "^4.29.3", + "chokidar": "^3.5.2", "esbuild": "^0.12.24", "esbuild-sass-plugin": "^1.5.2", "eslint": "^7.32.0", diff --git a/netbox/project-static/yarn.lock b/netbox/project-static/yarn.lock index 780ba071e..4f917235f 100644 --- a/netbox/project-static/yarn.lock +++ b/netbox/project-static/yarn.lock @@ -608,7 +608,7 @@ chalk@^4.0.0: ansi-styles "^4.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" resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.2.tgz#dba3976fcadb016f66fd365021d91600d01c1e75" integrity sha512-ekGhOnNVPgT77r4K/U3GDhu+FQ2S8TnK/s2KbIGXi0SZWuwkZ2QNyfWdZW+TVfn84DpEP7rLeCt2UI6bJ8GwbQ==