aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--package.json6
-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
4 files changed, 60 insertions, 55 deletions
diff --git a/package.json b/package.json
index cdbc7a385..8c51ee017 100644
--- a/package.json
+++ b/package.json
@@ -13,8 +13,9 @@
"prettier:ci": "prettier --list-different '**/*.{ts,tsx,json,md}' --config .prettierrc",
"report_coverage": "lcov-result-merger 'packages/*/coverage/lcov.info' | coveralls",
"test:installation": "node ./packages/monorepo-scripts/lib/test_installation.js",
- "run:publish": "run-s install:all rebuild script:publish",
- "run:publish:dry": "run-s install:all rebuild script:publish:dry",
+ "run:publish": "run-s install:all build:monorepo_scripts script:prepublish_checks rebuild script:publish",
+ "run:publish:dry": "run-s install:all build:monorepo_scripts script:prepublish_checks rebuild script:publish:dry",
+ "script:prepublish_checks": "node ./packages/monorepo-scripts/lib/prepublish_checks.js",
"script:publish": "node ./packages/monorepo-scripts/lib/publish.js",
"script:publish:dry": "IS_DRY_RUN=true yarn script:publish",
"install:all": "yarn install",
@@ -22,6 +23,7 @@
"lerna:run": "lerna run",
"watch": "wsrun watch $PKG --fast-exit -r --stages --done-criteria='complete|successfully'",
"build": "wsrun build $PKG --fast-exit -r --stages",
+ "build:monorepo_scripts": "PKG=@0xproject/monorepo-scripts yarn build",
"clean": "wsrun clean $PKG --fast-exit -r --parallel",
"rebuild": "run-s clean build",
"test": "wsrun test $PKG --fast-exit --serial --exclude-missing",
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 });