From c40b3dea6cefc9a192136d66311839bd7c5d5169 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 24 Jul 2018 21:39:31 +0200 Subject: Specify registry url only if local publish attempted --- packages/monorepo-scripts/src/postpublish_utils.ts | 43 +++++++++++----------- packages/monorepo-scripts/src/publish.ts | 14 ++++--- packages/monorepo-scripts/src/utils/configs.ts | 8 ++++ packages/monorepo-scripts/src/utils/npm_utils.ts | 6 +-- 4 files changed, 40 insertions(+), 31 deletions(-) create mode 100644 packages/monorepo-scripts/src/utils/configs.ts (limited to 'packages') diff --git a/packages/monorepo-scripts/src/postpublish_utils.ts b/packages/monorepo-scripts/src/postpublish_utils.ts index 229bb9031..37861f0dd 100644 --- a/packages/monorepo-scripts/src/postpublish_utils.ts +++ b/packages/monorepo-scripts/src/postpublish_utils.ts @@ -6,6 +6,7 @@ import * as path from 'path'; import * as publishRelease from 'publish-release'; import { constants } from './constants'; +import { configs } from './utils/configs'; import { utils } from './utils/utils'; const publishReleaseAsync = promisify(publishRelease); @@ -25,8 +26,6 @@ export interface DocPublishConfigs { s3StagingBucketPath: string; } -const IS_LOCAL_PUBLISH = process.env.IS_LOCAL_PUBLISH === 'true'; - export const postpublishUtils = { generateConfig(packageJSON: any, tsConfigJSON: any, cwd: string): PostpublishConfigs { if (_.isUndefined(packageJSON.name)) { @@ -36,7 +35,7 @@ export const postpublishUtils = { throw new Error('version field required in package.json. Cannot publish release notes to Github.'); } const postpublishConfig = _.get(packageJSON, 'config.postpublish', {}); - const configs: PostpublishConfigs = { + const postpublishConfigs: PostpublishConfigs = { cwd, packageName: packageJSON.name, version: packageJSON.version, @@ -50,47 +49,47 @@ export const postpublishUtils = { s3StagingBucketPath: _.get(postpublishConfig, 'docPublishConfigs.s3StagingBucketPath'), }, }; - return configs; + return postpublishConfigs; }, async runAsync(packageJSON: any, tsConfigJSON: any, cwd: string): Promise { - if (IS_LOCAL_PUBLISH) { + if (configs.IS_LOCAL_PUBLISH) { return; } - const configs = postpublishUtils.generateConfig(packageJSON, tsConfigJSON, cwd); + const postpublishConfigs = postpublishUtils.generateConfig(packageJSON, tsConfigJSON, cwd); await postpublishUtils.publishReleaseNotesAsync( - configs.cwd, - configs.packageName, - configs.version, - configs.assets, + postpublishConfigs.cwd, + postpublishConfigs.packageName, + postpublishConfigs.version, + postpublishConfigs.assets, ); if ( - !_.isUndefined(configs.docPublishConfigs.s3BucketPath) || - !_.isUndefined(configs.docPublishConfigs.s3StagingBucketPath) + !_.isUndefined(postpublishConfigs.docPublishConfigs.s3BucketPath) || + !_.isUndefined(postpublishConfigs.docPublishConfigs.s3StagingBucketPath) ) { utils.log('POSTPUBLISH: Release successful, generating docs...'); await postpublishUtils.generateAndUploadDocsAsync( - configs.cwd, - configs.docPublishConfigs.fileIncludes, - configs.version, - configs.docPublishConfigs.s3BucketPath, + postpublishConfigs.cwd, + postpublishConfigs.docPublishConfigs.fileIncludes, + postpublishConfigs.version, + postpublishConfigs.docPublishConfigs.s3BucketPath, ); } else { utils.log(`POSTPUBLISH: No S3Bucket config found for ${packageJSON.name}. Skipping doc JSON generation.`); } }, async publishDocsToStagingAsync(packageJSON: any, tsConfigJSON: any, cwd: string): Promise { - const configs = postpublishUtils.generateConfig(packageJSON, tsConfigJSON, cwd); - if (_.isUndefined(configs.docPublishConfigs.s3StagingBucketPath)) { + const postpublishConfigs = postpublishUtils.generateConfig(packageJSON, tsConfigJSON, cwd); + if (_.isUndefined(postpublishConfigs.docPublishConfigs.s3StagingBucketPath)) { utils.log('config.postpublish.docPublishConfigs.s3StagingBucketPath entry in package.json not found!'); return; } utils.log('POSTPUBLISH: Generating docs...'); await postpublishUtils.generateAndUploadDocsAsync( - configs.cwd, - configs.docPublishConfigs.fileIncludes, - configs.version, - configs.docPublishConfigs.s3StagingBucketPath, + postpublishConfigs.cwd, + postpublishConfigs.docPublishConfigs.fileIncludes, + postpublishConfigs.version, + postpublishConfigs.docPublishConfigs.s3StagingBucketPath, ); }, async publishReleaseNotesAsync(cwd: string, packageName: string, version: string, assets: string[]): Promise { diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 71eb16a98..d5238ab52 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -12,11 +12,11 @@ import semverSort = require('semver-sort'); import { constants } from './constants'; import { Package, PackageToNextVersion, VersionChangelog } from './types'; import { changelogUtils } from './utils/changelog_utils'; +import { configs } from './utils/configs'; import { utils } from './utils/utils'; const DOC_GEN_COMMAND = 'docs:json'; const NPM_NAMESPACE = '@0xproject/'; -const IS_LOCAL_PUBLISH = process.env.IS_LOCAL_PUBLISH === 'true'; const TODAYS_TIMESTAMP = moment().unix(); const packageNameToWebsitePath: { [name: string]: string } = { '0x.js': '0xjs', @@ -36,7 +36,7 @@ const packageNameToWebsitePath: { [name: string]: string } = { const shouldIncludePrivate = true; const allUpdatedPackages = await utils.getUpdatedPackagesAsync(shouldIncludePrivate); - if (!IS_LOCAL_PUBLISH) { + if (!configs.IS_LOCAL_PUBLISH) { await confirmDocPagesRenderAsync(allUpdatedPackages); } @@ -59,7 +59,7 @@ const packageNameToWebsitePath: { [name: string]: string } = { }); // Push changelog changes to Github - if (!IS_LOCAL_PUBLISH) { + if (!configs.IS_LOCAL_PUBLISH) { await pushChangelogsToGithubAsync(); } @@ -182,9 +182,11 @@ async function lernaPublishAsync(packageToNextVersion: { [name: string]: string const packageVersionString = _.map(packageToNextVersion, (nextVersion: string, packageName: string) => { return `${packageName}@${nextVersion}`; }).join(','); - let lernaPublishCmd = `node ${constants.lernaExecutable} publish --cdVersions=${packageVersionString}`; - if (IS_LOCAL_PUBLISH) { - lernaPublishCmd += ' --skip-git --yes --force-publish *'; + let lernaPublishCmd = `node ${constants.lernaExecutable} publish --cdVersions=${packageVersionString} --registry=${ + configs.NPM_REGISTRY_URL + }`; + if (configs.IS_LOCAL_PUBLISH) { + lernaPublishCmd += ` --skip-git --yes --force-publish *`; } utils.log('Lerna is publishing...'); await execAsync(lernaPublishCmd, { cwd: constants.monorepoRootPath }); diff --git a/packages/monorepo-scripts/src/utils/configs.ts b/packages/monorepo-scripts/src/utils/configs.ts new file mode 100644 index 000000000..e579bdb7c --- /dev/null +++ b/packages/monorepo-scripts/src/utils/configs.ts @@ -0,0 +1,8 @@ +const IS_LOCAL_PUBLISH = process.env.IS_LOCAL_PUBLISH === 'true'; +const LOCAL_NPM_REGISTRY_URL = 'http://localhost:4873'; +const REMOTE_NPM_REGISTRY_URL = 'https://registry.npmjs.org'; + +export const configs = { + IS_LOCAL_PUBLISH, + NPM_REGISTRY_URL: IS_LOCAL_PUBLISH ? LOCAL_NPM_REGISTRY_URL : REMOTE_NPM_REGISTRY_URL, +}; diff --git a/packages/monorepo-scripts/src/utils/npm_utils.ts b/packages/monorepo-scripts/src/utils/npm_utils.ts index 7c8310459..9c8e51508 100644 --- a/packages/monorepo-scripts/src/utils/npm_utils.ts +++ b/packages/monorepo-scripts/src/utils/npm_utils.ts @@ -4,14 +4,14 @@ import * as _ from 'lodash'; import { PackageRegistryJson } from '../types'; -const lernaJson = JSON.parse(fs.readFileSync('lerna.json').toString()); -const NPM_REGISTRY_BASE_URL = lernaJson.registry; +import { configs } from './configs'; + const SUCCESS_STATUS = 200; const NOT_FOUND_STATUS = 404; export const npmUtils = { async getPackageRegistryJsonIfExistsAsync(packageName: string): Promise { - const url = `${NPM_REGISTRY_BASE_URL}/${packageName}`; + const url = `${configs.NPM_REGISTRY_URL}/${packageName}`; const response = await fetch(url); if (response.status === NOT_FOUND_STATUS) { -- cgit v1.2.3