| 17 | }); |
| 18 | |
| 19 | async function checkNPMPermissions() { |
| 20 | const currentUser = await execRead('npm whoami'); |
| 21 | const failedProjects = []; |
| 22 | |
| 23 | const checkProject = async project => { |
| 24 | const owners = (await execRead(`npm owner ls ${project}`)) |
| 25 | .split('\n') |
| 26 | .filter(owner => owner) |
| 27 | .map(owner => owner.split(' ')[0]); |
| 28 | |
| 29 | if (!owners.includes(currentUser)) { |
| 30 | failedProjects.push(project); |
| 31 | } |
| 32 | }; |
| 33 | |
| 34 | await logger( |
| 35 | Promise.all(NPM_PACKAGES.map(checkProject)), |
| 36 | `Checking NPM permissions for ${chalk.bold(currentUser)}.`, |
| 37 | {estimate: 2500} |
| 38 | ); |
| 39 | |
| 40 | console.log(''); |
| 41 | |
| 42 | if (failedProjects.length) { |
| 43 | console.error(chalk.red.bold('Insufficient NPM permissions')); |
| 44 | console.error(''); |
| 45 | console.error( |
| 46 | chalk.red( |
| 47 | `NPM user {underline ${currentUser}} is not an owner for: ${chalk.bold( |
| 48 | failedProjects.join(', ') |
| 49 | )}` |
| 50 | ) |
| 51 | ); |
| 52 | console.error( |
| 53 | chalk.red( |
| 54 | 'Please contact a React team member to be added to the above project(s).' |
| 55 | ) |
| 56 | ); |
| 57 | process.exit(1); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | function clear() { |
| 62 | console.clear(); |