aboutsummaryrefslogtreecommitdiffstats
path: root/packages/monorepo-scripts/src/prepublish_checks.ts
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-06-02 04:39:04 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-06-02 04:39:04 +0800
commit2f8e52f9057b98b5f60dc3ec3428b024739a2997 (patch)
tree94db9ee29af85315426744662e3b6a8a02ed7fa7 /packages/monorepo-scripts/src/prepublish_checks.ts
parent06e5fc233c512d152d61c4acbed8d9344e769abe (diff)
downloaddexon-sol-tools-2f8e52f9057b98b5f60dc3ec3428b024739a2997.tar
dexon-sol-tools-2f8e52f9057b98b5f60dc3ec3428b024739a2997.tar.gz
dexon-sol-tools-2f8e52f9057b98b5f60dc3ec3428b024739a2997.tar.bz2
dexon-sol-tools-2f8e52f9057b98b5f60dc3ec3428b024739a2997.tar.lz
dexon-sol-tools-2f8e52f9057b98b5f60dc3ec3428b024739a2997.tar.xz
dexon-sol-tools-2f8e52f9057b98b5f60dc3ec3428b024739a2997.tar.zst
dexon-sol-tools-2f8e52f9057b98b5f60dc3ec3428b024739a2997.zip
Move prepublish checks before building packages for publishing
Diffstat (limited to 'packages/monorepo-scripts/src/prepublish_checks.ts')
-rw-r--r--packages/monorepo-scripts/src/prepublish_checks.ts55
1 files changed, 55 insertions, 0 deletions
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);
+});