1. #!/usr/bin/env node
    
  2. 
    
  3. 'use strict';
    
  4. 
    
  5. const chalk = require('chalk');
    
  6. const {execSync} = require('child_process');
    
  7. const {existsSync} = require('fs');
    
  8. const {isAbsolute, join, relative} = require('path');
    
  9. const {argv} = require('yargs');
    
  10. const build = require('../build');
    
  11. 
    
  12. const main = async () => {
    
  13.   const {crx, keyPath} = argv;
    
  14. 
    
  15.   if (crx) {
    
  16.     if (!keyPath || !existsSync(keyPath)) {
    
  17.       console.error('Must specify a key file (.pem) to build CRX');
    
  18.       process.exit(1);
    
  19.     }
    
  20.   }
    
  21. 
    
  22.   await build('chrome');
    
  23. 
    
  24.   if (crx) {
    
  25.     const cwd = join(__dirname, 'build');
    
  26. 
    
  27.     let safeKeyPath = keyPath;
    
  28.     if (!isAbsolute(keyPath)) {
    
  29.       safeKeyPath = join(relative(cwd, process.cwd()), keyPath);
    
  30.     }
    
  31. 
    
  32.     const crxPath = join(
    
  33.       __dirname,
    
  34.       '..',
    
  35.       '..',
    
  36.       '..',
    
  37.       'node_modules',
    
  38.       '.bin',
    
  39.       'crx'
    
  40.     );
    
  41. 
    
  42.     execSync(
    
  43.       `${crxPath} pack ./unpacked -o ReactDevTools.crx -p ${safeKeyPath}`,
    
  44.       {
    
  45.         cwd,
    
  46.       }
    
  47.     );
    
  48.   }
    
  49. 
    
  50.   console.log(chalk.green('\nThe Chrome extension has been built!'));
    
  51.   console.log(chalk.green('You can test this build by running:'));
    
  52.   console.log(chalk.gray('\n# From the react-devtools root directory:'));
    
  53.   console.log('yarn run test:chrome');
    
  54. };
    
  55. 
    
  56. main();