From fc2b7f747bf15b8c9329f2940ed2f6cf71353c33 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 19 Apr 2018 14:10:48 +0900 Subject: Add checks for the required local setup before running the publish script --- packages/monorepo-scripts/src/publish.ts | 50 ++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index a2d641ff9..9bd9ff6be 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -38,6 +38,11 @@ const packageNameToWebsitePath: { [name: string]: string } = { }; (async () => { + const hasRequiredSetup = await checkPublishRequiredSetupAsync(); + if (!hasRequiredSetup) { + return; // abort + } + // Fetch public, updated Lerna packages const updatedPublicLernaPackages = await getUpdatedPublicLernaPackagesAsync(); @@ -107,6 +112,51 @@ package.ts. Please add an entry for it and try again.`, } } +async function checkPublishRequiredSetupAsync(): Promise { + // check to see if logged into npm before publishing (npm whoami) + try { + 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 creds setup (check for ENV 'GITHUB_PERSONAL_ACCESS_TOKEN_0X_JS') + if (_.isUndefined(process.env.GITHUB_PERSONAL_ACCESS_TOKEN_0X_JS)) { + 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 NPM version is 5.X + const result = await execAsync(`npm --version`); + const version = result.stdout; + const versionSegments = version.split('.'); + const majorVersion = _.parseInt(versionSegments[0]); + if (majorVersion < 5) { + utils.log('You npm version must be v5.x or higher. Upgrade your npm and try again.'); + return false; + } + + // Check that `aws` commandline 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` creds 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() { await execAsync(`git add . --all`, { cwd: constants.monorepoRootPath }); await execAsync(`git commit -m "Updated CHANGELOGS"`, { cwd: constants.monorepoRootPath }); -- cgit v1.2.3