From 2f8e52f9057b98b5f60dc3ec3428b024739a2997 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 1 Jun 2018 13:39:04 -0700 Subject: Move prepublish checks before building packages for publishing --- packages/monorepo-scripts/src/prepublish_checks.ts | 55 ++++++++++++++++++++++ packages/monorepo-scripts/src/publish.ts | 53 --------------------- 2 files changed, 55 insertions(+), 53 deletions(-) create mode 100644 packages/monorepo-scripts/src/prepublish_checks.ts (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/prepublish_checks.ts b/packages/monorepo-scripts/src/prepublish_checks.ts new file mode 100644 index 000000000..ae58524f5 --- /dev/null +++ b/packages/monorepo-scripts/src/prepublish_checks.ts @@ -0,0 +1,55 @@ +import * as _ from 'lodash'; +import { exec as execAsync } from 'promisify-child-process'; + +import { constants } from './constants'; +import { utils } from './utils/utils'; + +async function checkPublishRequiredSetupAsync(): Promise { + // check to see if logged into npm before publishing + try { + // HACK: for some reason on some setups, the `npm whoami` will not recognize a logged-in user + // unless run with `sudo` (i.e Fabio's NVM setup) but is fine for others (Jacob's NVM setup). + utils.log('Checking that the user is logged in on npm...'); + await execAsync(`sudo npm whoami`); + } catch (err) { + throw new Error('You must be logged into npm in the commandline to publish. Run `npm login` and try again.'); + } + + // Check to see if Git personal token setup + if (_.isUndefined(constants.githubPersonalAccessToken)) { + throw new Error( + 'You must have a Github personal access token set to an envVar named `GITHUB_PERSONAL_ACCESS_TOKEN_0X_JS`. Add it then try again.', + ); + } + + // Check Yarn version is 1.X + utils.log('Checking the yarn version...'); + const result = await execAsync(`yarn --version`); + const version = result.stdout; + const versionSegments = version.split('.'); + const majorVersion = _.parseInt(versionSegments[0]); + if (majorVersion < 1) { + throw new Error('Your yarn version must be v1.x or higher. Upgrade yarn and try again.'); + } + + // Check that `aws` commandline tool is installed + try { + utils.log('Checking that aws CLI tool is installed...'); + await execAsync(`aws help`); + } catch (err) { + throw new Error('You must have `awscli` commandline tool installed. Install it and try again.'); + } + + // Check that `aws` credentials are setup + try { + utils.log('Checking that aws credentials are configured...'); + await execAsync(`aws sts get-caller-identity`); + } catch (err) { + throw new Error('You must setup your AWS credentials by running `aws configure`. Do this and try again.'); + } +} + +checkPublishRequiredSetupAsync().catch(err => { + utils.log(err); + process.exit(1); +}); diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 022fe172e..45dea9796 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -39,11 +39,6 @@ const packageNameToWebsitePath: { [name: string]: string } = { }; (async () => { - const hasRequiredSetup = await checkPublishRequiredSetupAsync(); - if (!hasRequiredSetup) { - return; // abort - } - // Fetch public, updated Lerna packages const shouldIncludePrivate = false; const updatedPublicLernaPackages = await utils.getUpdatedLernaPackagesAsync(shouldIncludePrivate); @@ -114,54 +109,6 @@ package.ts. Please add an entry for it and try again.`, } } -async function checkPublishRequiredSetupAsync(): Promise { - // check to see if logged into npm before publishing - try { - // HACK: for some reason on some setups, the `npm whoami` will not recognize a logged-in user - // unless run with `sudo` (i.e Fabio's NVM setup) but is fine for others (Jacob's NVM setup). - await execAsync(`sudo npm whoami`); - } catch (err) { - utils.log('You must be logged into npm in the commandline to publish. Run `npm login` and try again.'); - return false; - } - - // Check to see if Git personal token setup - if (_.isUndefined(constants.githubPersonalAccessToken)) { - utils.log( - 'You must have a Github personal access token set to an envVar named `GITHUB_PERSONAL_ACCESS_TOKEN_0X_JS`. Add it then try again.', - ); - return false; - } - - // Check Yarn version is 1.X - const result = await execAsync(`yarn --version`); - const version = result.stdout; - const versionSegments = version.split('.'); - const majorVersion = _.parseInt(versionSegments[0]); - if (majorVersion < 1) { - utils.log('Your yarn version must be v1.x or higher. Upgrade yarn and try again.'); - return false; - } - - // Check that `aws` commandline tool is installed - try { - await execAsync(`aws help`); - } catch (err) { - utils.log('You must have `awscli` commandline tool installed. Install it and try again.'); - return false; - } - - // Check that `aws` credentials are setup - try { - await execAsync(`aws sts get-caller-identity`); - } catch (err) { - utils.log('You must setup your AWS credentials by running `aws configure`. Do this and try again.'); - return false; - } - - return true; -} - async function pushChangelogsToGithubAsync(): Promise { await execAsync(`git add . --all`, { cwd: constants.monorepoRootPath }); await execAsync(`git commit -m "Updated CHANGELOGS"`, { cwd: constants.monorepoRootPath }); -- cgit v1.2.3