56 lines
1.4 KiB
JavaScript
Raw Normal View History

2019-01-25 16:51:21 +01:00
const chokidar = require('chokidar');
const liveServer = require('live-server');
const build = require('./utils/build-fn');
const path = require('path');
2019-01-28 03:37:25 +01:00
const nanogen = require('nanogen')
const staticSiteOptions = require('../site.config');
2019-01-25 16:51:21 +01:00
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
};
/**
* Serve the site in watch mode
*/
const serve = (flags) => {
console.log(`Starting local server at http://localhost:${flags.port}`);
const options = {
2019-01-28 03:37:25 +01:00
sourceFile: path.resolve(__dirname, '../lib/terminal.css'),
2019-01-25 16:51:21 +01:00
distFolder: path.resolve(__dirname, '../dist'),
2019-01-28 03:37:25 +01:00
docsFolder: path.resolve(__dirname, '../public'),
docsSrcFolder: path.resolve(__dirname, '../src')
2019-01-25 16:51:21 +01:00
}
build.run(options);
2019-01-28 03:37:25 +01:00
nanogen.build({ site: staticSiteOptions.site })
2019-01-25 16:51:21 +01:00
liveServer.start({
port: flags.port,
root: options.docsFolder,
open: true,
logLevel: 0
});
2019-01-28 03:37:25 +01:00
chokidar.watch([options.sourceFile, options.docsSrcFolder], { ignoreInitial: true }).on(
2019-01-25 16:51:21 +01:00
'all',
debounce(() => {
build.run(options);
2019-01-28 03:37:25 +01:00
nanogen.build({ site: staticSiteOptions.site })
2019-01-25 16:51:21 +01:00
console.log('Waiting for changes...');
}, 500)
);
};
serve({ port: 3000 })