Files
TechRadarAJR/tasks/watch.js
2017-02-10 20:00:37 +01:00

42 lines
948 B
JavaScript

import { watch } from 'fs';
import { exec } from 'child_process';
import liveServer from 'live-server';
import {
stylesPath,
assetsPath,
jsPath,
radarPath,
staticPath,
templatesPath,
distPath,
} 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(assetsPath(), options, watchBuild('assets'));
watch(radarPath(), options, watchBuild('pages'));
watch(staticPath(), options, watchBuild('pages'));
watch(templatesPath(), options, watchBuild('pages'));
var params = {
root: distPath(),
logLevel: 2, // 0 = errors only, 1 = some, 2 = lots
};
liveServer.start(params);