From 0673da6867573603790101481f4ae99c528939d7 Mon Sep 17 00:00:00 2001 From: Tom Raithel Date: Fri, 10 Feb 2017 19:50:03 +0100 Subject: [PATCH] Add simplified watch --- package.json | 6 ++---- styles/base.css | 1 - tasks/file.js | 12 ++++++++++++ tasks/watch.js | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 tasks/watch.js diff --git a/package.json b/package.json index 4cd1762..7485b94 100644 --- a/package.json +++ b/package.json @@ -5,12 +5,10 @@ "main": "index.js", "scripts": { "build": "npm run clean && npm run build:radar && npm run build:js && npm run build:css", - "build:radar": "babel-node ./tasks/build.js", + "build:pages": "babel-node ./tasks/build.js", "build:js": "webpack --config webpack.config.js", "build:css": "postcss -c postcss.config.json -o dist/styles.css styles/main.css", - "watch:radar": "nodemon -w radar -w static-pages -w templates -e md,pug --exec 'npm run build:radar'", - "watch:css": "nodemon -w styles -e css --exec 'npm run build:css'", - "watch:js": "nodemon -w js -e js --exec 'npm run build:js'", + "watch": "babel-node ./tasks/watch.js", "clean": "babel-node ./tasks/clean.js", "test": "echo \"Error: no test specified\" && exit 1" }, diff --git a/styles/base.css b/styles/base.css index e3cb2da..780e040 100644 --- a/styles/base.css +++ b/styles/base.css @@ -1,4 +1,3 @@ - body { background: #475157; box-sizing: border-box; diff --git a/tasks/file.js b/tasks/file.js index 7979f21..84c856d 100644 --- a/tasks/file.js +++ b/tasks/file.js @@ -13,6 +13,18 @@ export const staticPath = (...pathInSrc) => ( relativePath('static-pages', ...pathInSrc) ); +export const templatesPath = (...pathInSrc) => ( + relativePath('templates', ...pathInSrc) +); + +export const stylesPath = (...pathInSrc) => ( + relativePath('styles', ...pathInSrc) +); + +export const jsPath = (...pathInSrc) => ( + relativePath('js', ...pathInSrc) +); + export const distPath = (...pathInDist) => ( relativePath('dist', ...pathInDist) ); diff --git a/tasks/watch.js b/tasks/watch.js new file mode 100644 index 0000000..c4ad50b --- /dev/null +++ b/tasks/watch.js @@ -0,0 +1,33 @@ +import { watch } from 'fs'; +import { exec } from 'child_process'; + +import { + stylesPath, + jsPath, + radarPath, + staticPath, + templatesPath, +} from './file'; + +const watchBuild = (name) => (eventType, fileName) => { + exec(`npm run build:${name}`, (error, stdout, stderr) => { + if (error) { + console.error(`exec error: ${error}`); + return; + } + console.log(stdout); + console.error(stderr); + }) +} + +const options = { + recursive: true, +} + +watch(stylesPath(), options, watchBuild('css')); +watch(jsPath(), options, watchBuild('js')); +watch(radarPath(), options, watchBuild('pages')); +watch(staticPath(), options, watchBuild('pages')); +watch(templatesPath(), options, watchBuild('pages')); + +console.log('Watching for changes, press CTRL+C to quit');