| 58 | } |
| 59 | |
| 60 | async function publishToNPM() { |
| 61 | const {otp} = await inquirer.prompt([ |
| 62 | { |
| 63 | type: 'input', |
| 64 | name: 'otp', |
| 65 | message: 'Please provide an NPM two-factor auth token:', |
| 66 | }, |
| 67 | ]); |
| 68 | |
| 69 | console.log(''); |
| 70 | |
| 71 | if (!otp) { |
| 72 | console.error(chalk.red(`Invalid OTP provided: "${chalk.bold(otp)}"`)); |
| 73 | process.exit(0); |
| 74 | } |
| 75 | |
| 76 | for (let index = 0; index < NPM_PACKAGES.length; index++) { |
| 77 | const npmPackage = NPM_PACKAGES[index]; |
| 78 | const packagePath = join(ROOT_PATH, 'packages', npmPackage); |
| 79 | const {version} = readJsonSync(join(packagePath, 'package.json')); |
| 80 | |
| 81 | // Check if this package version has already been published. |
| 82 | // If so we might be resuming from a previous run. |
| 83 | // We could infer this by comparing the build-info.json, |
| 84 | // But for now the easiest way is just to ask if this is expected. |
| 85 | const versionListJSON = await execRead( |
| 86 | `npm view ${npmPackage} versions --json` |
| 87 | ); |
| 88 | const versionList = JSON.parse(versionListJSON); |
| 89 | const versionIsAlreadyPublished = versionList.includes(version); |
| 90 | |
| 91 | if (versionIsAlreadyPublished) { |
| 92 | console.log(''); |
| 93 | console.log( |
| 94 | `${npmPackage} version ${chalk.bold( |
| 95 | version |
| 96 | )} has already been published.` |
| 97 | ); |
| 98 | |
| 99 | await confirm(`Is this expected (will skip ${npmPackage}@${version})?`); |
| 100 | continue; |
| 101 | } |
| 102 | |
| 103 | if (DRY_RUN) { |
| 104 | console.log(`Publishing package ${chalk.bold(npmPackage)}`); |
| 105 | console.log(chalk.dim(` npm publish --otp=${otp}`)); |
| 106 | } else { |
| 107 | const publishPromise = exec(`npm publish --otp=${otp}`, { |
| 108 | cwd: packagePath, |
| 109 | }); |
| 110 | |
| 111 | await logger( |
| 112 | publishPromise, |
| 113 | `Publishing package ${chalk.bold(npmPackage)}`, |
| 114 | { |
| 115 | estimate: 2500, |
| 116 | } |
| 117 | ); |