UNPKG

@area17/a17-boilerplate

Version:

The official AREA 17 boilerplate

45 lines (36 loc) 1.34 kB
const path = require('path'); const watch = require('watch'); const spawn = require('cross-spawn'); const utils = require('../utils'); const createLogger = require('logging').default; const data = utils.getManifest(); const logger = createLogger('Watch'); let bundleTask = utils.attemptResolve(path.join(__dirname, '../tasks', 'bundle')); let iconTask = utils.attemptResolve(path.join(__dirname, '../tasks', 'icons')); let watchOptions = { 'ignoreDotFiles' : true, 'interval' : 2, 'ignoreDirectoryPattern' : /node_modules/ }; logger.info('Starting watch'); // use webpack watch : clean, copy fonts and images, set CSS and JS and watch for changes spawn('node', [].concat([bundleTask], ['--watch']), {stdio: 'inherit'}); // Watch for icons (svg files) watch.watchTree(path.resolve(data.paths.source + 'icons/'), watchOptions, (f, curt, prev)=>{ let result = {}; result.status = 0; if (typeof f === 'object' && prev === null && curt === null) { logger.info('Start to watch non-js and non-scss files'); } else if (f != null) { let fileType = f.split('.').pop(); switch(fileType) { case 'svg' : result = spawn.sync('node', [iconTask], {stdio: 'inherit'}); break; } } if (result.status !== 0) { logger.error('Something went wrong'); process.exit(result.status); } });