diff options
author | Fabio Berger <me@fabioberger.com> | 2018-06-02 08:13:02 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-06-02 08:13:02 +0800 |
commit | d3c64bd5b493dc1779a24c7c051c255106a4292a (patch) | |
tree | d1c818e64b75c1f4fed1c7d797892fb0d35dd779 /packages/monorepo-scripts/src/prepublish_checks.ts | |
parent | 7024a7468a549a96cf120e6b7e287e79d7ad2d61 (diff) | |
parent | 62e60e2ba6d07b9b892b4f2e92a5421c54f5fa20 (diff) | |
download | dexon-sol-tools-d3c64bd5b493dc1779a24c7c051c255106a4292a.tar dexon-sol-tools-d3c64bd5b493dc1779a24c7c051c255106a4292a.tar.gz dexon-sol-tools-d3c64bd5b493dc1779a24c7c051c255106a4292a.tar.bz2 dexon-sol-tools-d3c64bd5b493dc1779a24c7c051c255106a4292a.tar.lz dexon-sol-tools-d3c64bd5b493dc1779a24c7c051c255106a4292a.tar.xz dexon-sol-tools-d3c64bd5b493dc1779a24c7c051c255106a4292a.tar.zst dexon-sol-tools-d3c64bd5b493dc1779a24c7c051c255106a4292a.zip |
Merge branch 'v2-prototype' into refactor/order-utils/for-v2
* v2-prototype:
Set contract expiration time to a constant 10 minutes
Remove unused promises array
Make erc20_wrapper and erc721_wrapper serial
Rename changelogs to changelog
Add CHANGELOG entry
Check that git branch is up to date before publishing
Move prepublish checks before building packages for publishing
Refactor changelog utils to a separate module
Diffstat (limited to 'packages/monorepo-scripts/src/prepublish_checks.ts')
-rw-r--r-- | packages/monorepo-scripts/src/prepublish_checks.ts | 71 |
1 files changed, 71 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..2c096d8f6 --- /dev/null +++ b/packages/monorepo-scripts/src/prepublish_checks.ts @@ -0,0 +1,71 @@ +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.'); + } + + utils.log('Checking that git branch is up to date with upstream...'); + await execAsync('git fetch'); + const res = await execAsync('git status -bs'); // s - short format, b - branch info + /** + * Possible outcomes + * ## branch_name...origin/branch_name [behind n] + * ## branch_name...origin/branch_name [ahead n] + * ## branch_name...origin/branch_name + */ + const gitShortStatusHeader = res.stdout.split('\n')[0]; + if (gitShortStatusHeader.includes('behind')) { + throw new Error('Your branch is behind upstream. Please pull before publishing.'); + } else if (gitShortStatusHeader.includes('ahead')) { + throw new Error('Your branch is ahead of upstream. Please push before publishing.'); + } +} + +checkPublishRequiredSetupAsync().catch(err => { + utils.log(err.message); + process.exit(1); +}); |