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.
Magister-Auto-Login/src/builder/watch.js

32 lines
810 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,
});
// Check for changes in the src directory
watcher.on('change', async (path) => {
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);
}
});