aboutsummaryrefslogtreecommitdiffstats
path: root/packages/monorepo-scripts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/monorepo-scripts')
-rw-r--r--packages/monorepo-scripts/package.json1
-rw-r--r--packages/monorepo-scripts/src/prepublish_checks.ts55
-rw-r--r--packages/monorepo-scripts/src/publish.ts53
3 files changed, 56 insertions, 53 deletions
diff --git a/packages/monorepo-scripts/package.json b/packages/monorepo-scripts/package.json
index 02a8e4a42..2bbf4df11 100644
--- a/packages/monorepo-scripts/package.json
+++ b/packages/monorepo-scripts/package.json
@@ -16,6 +16,7 @@
"find_unused_deps": "run-s build script:find_unused_deps",
"remove_tags": "run-s build script:remove_tags",
"script:deps_versions": "node ./lib/deps_versions.js",
+ "script:prepublish_checks": "node ./lib/prepublish_checks.js",
"script:publish": "IS_DRY_RUN=true node ./lib/publish.js",
"script:find_unused_deps": "node ./lib/find_unused_dependencies.js",
"script:remove_tags": "node ./lib/remove_tags.js"
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<void> {
+ // 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<boolean> {
- // 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<void> {
await execAsync(`git add . --all`, { cwd: constants.monorepoRootPath });
await execAsync(`git commit -m "Updated CHANGELOGS"`, { cwd: constants.monorepoRootPath });