strapi/scripts/copy-monorepo.js
Alexandre Bodin 07e7cfc0bd Make lint stricter and fix the errors
Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
2020-11-02 19:41:42 +01:00

48 lines
1.2 KiB
JavaScript

'use strict';
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.boolean('run-once').boolean('quiet');
},
argv => {
const source = path.resolve(__dirname, '..', 'packages');
const dest = path.resolve(process.cwd(), argv.dest);
watch(source, dest, argv);
}
)
.help().argv;