index.js 692 B

12345678910111213141516171819
  1. const { fork } = require('child_process');
  2. const { join } = require('path');
  3. const { getClassesMapping, readDir, chunk } = require('./src/utils');
  4. const cpus = require('os').cpus().length;
  5. const arg = process.argv.slice(2)[0];
  6. const mode = arg && ((arg === 'reverse') || (arg === '-r')) ? 'reverse' : 'forward';
  7. const SEARCH_DIR = 'node_modules';
  8. const classesMapping = getClassesMapping();
  9. const files = readDir(SEARCH_DIR);
  10. console.log(`Jetifier found ${files.length} file(s) to ${mode}-jetify. Using ${cpus} workers...`);
  11. for (const filesChunk of chunk(files, cpus)) {
  12. const worker = fork(join(__dirname, 'src', 'worker.js'));
  13. worker.send({ filesChunk, classesMapping, mode });
  14. }