mirror of
https://github.com/strapi/strapi.git
synced 2025-07-15 21:11:28 +00:00
62 lines
1.4 KiB
JavaScript
62 lines
1.4 KiB
JavaScript
![]() |
const path = require('path');
|
||
|
const fs = require('fs-extra');
|
||
|
const yargs = require('yargs');
|
||
|
const chokidar = require('chokidar');
|
||
|
|
||
|
const watch = (source, dest, { runOnce, quiet }) => {
|
||
|
const ignored = [/node_modules/, /\.git/, /\.DS_Store/, /__tests__/];
|
||
|
|
||
|
chokidar
|
||
|
.watch(source, {
|
||
|
ignored: [
|
||
|
filePath => ignored.filter(reg => reg.test(filePath)).length > 0,
|
||
|
],
|
||
|
})
|
||
|
.on('all', (event, filePath) => {
|
||
|
if (['change', 'add'].includes(event)) {
|
||
|
const newPath = path.join(
|
||
|
dest,
|
||
|
'node_modules',
|
||
|
path.relative(source, filePath)
|
||
|
);
|
||
|
fs.copy(filePath, newPath);
|
||
|
|
||
|
if (!quiet) {
|
||
|
console.log(
|
||
|
`Copied ${filePath} to ${path.join(
|
||
|
'node_modules',
|
||
|
path.relative(source, filePath)
|
||
|
)}`
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
.on('ready', () => {
|
||
|
if (runOnce) {
|
||
|
process.exit(0);
|
||
|
}
|
||
|
});
|
||
|
};
|
||
|
|
||
|
yargs
|
||
|
.command(
|
||
|
'$0 <dest>',
|
||
|
'default command',
|
||
|
yargs => {
|
||
|
yargs
|
||
|
.option('run-once', {
|
||
|
default: false,
|
||
|
})
|
||
|
.option('quiet', {
|
||
|
alias: 'q',
|
||
|
default: false,
|
||
|
});
|
||
|
},
|
||
|
argv => {
|
||
|
const source = path.resolve(__dirname, '..', 'packages');
|
||
|
const dest = path.resolve(process.cwd(), argv.dest);
|
||
|
watch(source, dest, argv);
|
||
|
}
|
||
|
)
|
||
|
.help().argv;
|