1. #!/usr/bin/env node
    
  2. 
    
  3. 'use strict';
    
  4. 
    
  5. const {execRead, logPromise} = require('../utils');
    
  6. const theme = require('../theme');
    
  7. 
    
  8. const run = async ({cwd, packages, version}) => {
    
  9.   const currentUser = await execRead('npm whoami');
    
  10.   const failedProjects = [];
    
  11. 
    
  12.   const checkProject = async project => {
    
  13.     const owners = (await execRead(`npm owner ls ${project}`))
    
  14.       .split('\n')
    
  15.       .filter(owner => owner)
    
  16.       .map(owner => owner.split(' ')[0]);
    
  17. 
    
  18.     if (!owners.includes(currentUser)) {
    
  19.       failedProjects.push(project);
    
  20.     }
    
  21.   };
    
  22. 
    
  23.   await logPromise(
    
  24.     Promise.all(packages.map(checkProject)),
    
  25.     theme`Checking NPM permissions for {underline ${currentUser}}.`
    
  26.   );
    
  27. 
    
  28.   if (failedProjects.length) {
    
  29.     console.error(
    
  30.       theme`
    
  31.       {error Insufficient NPM permissions}
    
  32.       \nNPM user {underline ${currentUser}} is not an owner for: ${failedProjects
    
  33.         .map(name => theme.package(name))
    
  34.         .join(', ')}
    
  35.       \nPlease contact a React team member to be added to the above project(s).
    
  36.       `
    
  37.         .replace(/\n +/g, '\n')
    
  38.         .trim()
    
  39.     );
    
  40.     process.exit(1);
    
  41.   }
    
  42. };
    
  43. 
    
  44. module.exports = run;