strapi/scripts/copy-monorepo.js

48 lines
1.2 KiB
JavaScript
Raw Normal View History

'use strict';
2019-04-16 18:05:12 +02:00
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],
2019-04-16 18:05:12 +02:00
})
.on('all', (event, filePath) => {
if (['change', 'add'].includes(event)) {
const newPath = path.join(dest, 'node_modules', path.relative(source, filePath));
2019-04-16 18:05:12 +02:00
fs.copy(filePath, newPath);
if (!quiet) {
console.log(
`Copied ${filePath} to ${path.join('node_modules', path.relative(source, filePath))}`
2019-04-16 18:05:12 +02:00
);
}
}
})
.on('ready', () => {
if (runOnce) {
process.exit(0);
}
});
};
yargs
.command(
'$0 <dest>',
'default command',
yargs => {
2019-04-23 11:24:23 +02:00
yargs.boolean('run-once').boolean('quiet');
2019-04-16 18:05:12 +02:00
},
argv => {
const source = path.resolve(__dirname, '..', 'packages');
const dest = path.resolve(process.cwd(), argv.dest);
watch(source, dest, argv);
}
)
.help().argv;