You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
882 B
38 lines
882 B
const chokidar = require('chokidar');
|
|
const { join } = require('path');
|
|
|
|
const { fileBuilder } = require('./builders');
|
|
|
|
const config = require(join(process.cwd(), 'builder.config.js'));
|
|
|
|
const srcDir = join(process.cwd(), config.root);
|
|
const distDir = join(process.cwd(), config.out);
|
|
|
|
const watcher = chokidar.watch(srcDir, {
|
|
persistent: true,
|
|
});
|
|
|
|
const { target } = require('./options');
|
|
|
|
target();
|
|
|
|
// Check for changes in the src directory
|
|
watcher.on('change', async (path) => {
|
|
console.clear();
|
|
|
|
const relativePath = path.replace(srcDir + '/', '');
|
|
|
|
const splittedPath = relativePath.split('/');
|
|
|
|
splittedPath.pop();
|
|
|
|
const conf = config.interpreter.find((conf) => conf.input == (splittedPath.join('/') || '.'));
|
|
|
|
if (conf) {
|
|
const fileType = path.split('.').pop();
|
|
const outPath = join(distDir, conf.output);
|
|
|
|
await fileBuilder(path, outPath, fileType);
|
|
}
|
|
});
|