From bddcebfbb1ca81199f273b6571ace0da14cf105a Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 23 Jul 2018 19:09:24 +0200 Subject: Allow registry to be configured in lerna.json --- packages/monorepo-scripts/src/prepublish_checks.ts | 2 +- packages/monorepo-scripts/src/publish.ts | 3 +-- packages/monorepo-scripts/src/utils/npm_utils.ts | 6 ++++-- 3 files changed, 6 insertions(+), 5 deletions(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/prepublish_checks.ts b/packages/monorepo-scripts/src/prepublish_checks.ts index 431e848ca..683c26094 100644 --- a/packages/monorepo-scripts/src/prepublish_checks.ts +++ b/packages/monorepo-scripts/src/prepublish_checks.ts @@ -50,7 +50,7 @@ async function checkGitTagsForNextVersionAndDeleteIfExistAsync(updatedPublicPack async function checkCurrentVersionMatchesLatestPublishedNPMPackageAsync( updatedPublicPackages: Package[], ): Promise { - utils.log('Check package versions against npmjs.org...'); + utils.log('Check package versions against npm registry...'); const versionMismatches = []; for (const pkg of updatedPublicPackages) { const packageName = pkg.packageJson.name; diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index c44e1f85e..53492e012 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -172,8 +172,7 @@ async function updateChangeLogsAsync(updatedPublicPackages: Package[]): Promise< async function lernaPublishAsync(packageToVersionChange: { [name: string]: string }): Promise { // HACK: Lerna publish does not provide a way to specify multiple package versions via // flags so instead we need to interact with their interactive prompt interface. - const PACKAGE_REGISTRY = 'https://registry.npmjs.org/'; - const child = spawn('lerna', ['publish', `--registry=${PACKAGE_REGISTRY}`], { + const child = spawn('lerna', ['publish'], { cwd: constants.monorepoRootPath, }); let shouldPrintOutput = false; diff --git a/packages/monorepo-scripts/src/utils/npm_utils.ts b/packages/monorepo-scripts/src/utils/npm_utils.ts index cc1e046e7..7c8310459 100644 --- a/packages/monorepo-scripts/src/utils/npm_utils.ts +++ b/packages/monorepo-scripts/src/utils/npm_utils.ts @@ -1,9 +1,11 @@ +import * as fs from 'fs'; import 'isomorphic-fetch'; import * as _ from 'lodash'; import { PackageRegistryJson } from '../types'; -const NPM_REGISTRY_BASE_URL = 'https://registry.npmjs.org'; +const lernaJson = JSON.parse(fs.readFileSync('lerna.json').toString()); +const NPM_REGISTRY_BASE_URL = lernaJson.registry; const SUCCESS_STATUS = 200; const NOT_FOUND_STATUS = 404; @@ -15,7 +17,7 @@ export const npmUtils = { if (response.status === NOT_FOUND_STATUS) { return undefined; } else if (response.status !== SUCCESS_STATUS) { - throw new Error(`Request to ${url} failed. Check your internet connection and that npmjs.org is up.`); + throw new Error(`Request to ${url} failed. Check your internet connection and that npm registry is up.`); } const packageRegistryJson = await response.json(); return packageRegistryJson; -- cgit v1.2.3 From e2d027e2521c8695bb16128fb8f038e2455e5481 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 23 Jul 2018 19:09:35 +0200 Subject: Add skip-git for testing --- packages/monorepo-scripts/src/publish.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 53492e012..958cb58ba 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -172,7 +172,7 @@ async function updateChangeLogsAsync(updatedPublicPackages: Package[]): Promise< async function lernaPublishAsync(packageToVersionChange: { [name: string]: string }): Promise { // HACK: Lerna publish does not provide a way to specify multiple package versions via // flags so instead we need to interact with their interactive prompt interface. - const child = spawn('lerna', ['publish'], { + const child = spawn('lerna', ['publish', `--skip-git`], { cwd: constants.monorepoRootPath, }); let shouldPrintOutput = false; -- cgit v1.2.3 From 195c3af84e080b51c4258739da0e996f690f52f5 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 23 Jul 2018 19:56:53 +0200 Subject: Fix lerna publish to include publishing prerelease versions --- packages/monorepo-scripts/src/publish.ts | 23 ++++++++++------------- packages/monorepo-scripts/src/types.ts | 5 +++++ 2 files changed, 15 insertions(+), 13 deletions(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 958cb58ba..e22d9800c 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -19,11 +19,6 @@ const DOC_GEN_COMMAND = 'docs:json'; const NPM_NAMESPACE = '@0xproject/'; const IS_DRY_RUN = process.env.IS_DRY_RUN === 'true'; const TODAYS_TIMESTAMP = moment().unix(); -const semverNameToIndex: { [semver: string]: number } = { - patch: SemVerIndex.Patch, - minor: SemVerIndex.Minor, - major: SemVerIndex.Major, -}; const packageNameToWebsitePath: { [name: string]: string } = { '0x.js': '0xjs', 'web3-wrapper': 'web3_wrapper', @@ -176,6 +171,7 @@ async function lernaPublishAsync(packageToVersionChange: { [name: string]: strin cwd: constants.monorepoRootPath, }); let shouldPrintOutput = false; + let packageName: string; child.stdout.on('data', (data: Buffer) => { const output = data.toString('utf8'); if (shouldPrintOutput) { @@ -184,14 +180,15 @@ async function lernaPublishAsync(packageToVersionChange: { [name: string]: strin const isVersionPrompt = _.includes(output, 'Select a new version'); if (isVersionPrompt) { const outputStripLeft = output.split('new version for ')[1]; - const packageName = outputStripLeft.split(' ')[0]; - let versionChange = packageToVersionChange[packageName]; - const isPrivatePackage = _.isUndefined(versionChange); - if (isPrivatePackage) { - versionChange = 'patch'; // Always patch updates to private packages. - } - const semVerIndex = semverNameToIndex[versionChange]; - child.stdin.write(`${semVerIndex}\n`); + packageName = outputStripLeft.split(' ')[0]; + child.stdin.write(`${SemVerIndex.Custom}\n`); + return; + } + const isCustomVersionPrompt = _.includes(output, 'Enter a custom version'); + if (isCustomVersionPrompt) { + const versionChange = packageToVersionChange[packageName]; + child.stdin.write(`${versionChange}\n`); + return; } const isFinalPrompt = _.includes(output, 'Are you sure you want to publish the above changes?'); if (isFinalPrompt && !IS_DRY_RUN) { diff --git a/packages/monorepo-scripts/src/types.ts b/packages/monorepo-scripts/src/types.ts index 9f991c86c..62d52d7bf 100644 --- a/packages/monorepo-scripts/src/types.ts +++ b/packages/monorepo-scripts/src/types.ts @@ -22,6 +22,11 @@ export enum SemVerIndex { Patch, Minor, Major, + Prepatch, + Preminor, + Premajor, + Prerelease, + Custom, } export interface PackageToVersionChange { -- cgit v1.2.3 From c8108a1db2c258eb4a5c3485cc6facf116ab4f57 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 23 Jul 2018 20:12:18 +0200 Subject: Temporarily uncommented parts of publish flow --- packages/monorepo-scripts/src/postpublish_utils.ts | 42 +++++++++++----------- packages/monorepo-scripts/src/publish.ts | 4 +-- 2 files changed, 23 insertions(+), 23 deletions(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/postpublish_utils.ts b/packages/monorepo-scripts/src/postpublish_utils.ts index 3ecb7b7c5..8c9d95e44 100644 --- a/packages/monorepo-scripts/src/postpublish_utils.ts +++ b/packages/monorepo-scripts/src/postpublish_utils.ts @@ -51,27 +51,27 @@ export const postpublishUtils = { return configs; }, async runAsync(packageJSON: any, tsConfigJSON: any, cwd: string): Promise { - const configs = postpublishUtils.generateConfig(packageJSON, tsConfigJSON, cwd); - await postpublishUtils.publishReleaseNotesAsync( - configs.cwd, - configs.packageName, - configs.version, - configs.assets, - ); - if ( - !_.isUndefined(configs.docPublishConfigs.s3BucketPath) || - !_.isUndefined(configs.docPublishConfigs.s3StagingBucketPath) - ) { - utils.log('POSTPUBLISH: Release successful, generating docs...'); - await postpublishUtils.generateAndUploadDocsAsync( - configs.cwd, - configs.docPublishConfigs.fileIncludes, - configs.version, - configs.docPublishConfigs.s3BucketPath, - ); - } else { - utils.log(`POSTPUBLISH: No S3Bucket config found for ${packageJSON.name}. Skipping doc JSON generation.`); - } + // const configs = postpublishUtils.generateConfig(packageJSON, tsConfigJSON, cwd); + // await postpublishUtils.publishReleaseNotesAsync( + // configs.cwd, + // configs.packageName, + // configs.version, + // configs.assets, + // ); + // if ( + // !_.isUndefined(configs.docPublishConfigs.s3BucketPath) || + // !_.isUndefined(configs.docPublishConfigs.s3StagingBucketPath) + // ) { + // utils.log('POSTPUBLISH: Release successful, generating docs...'); + // await postpublishUtils.generateAndUploadDocsAsync( + // configs.cwd, + // configs.docPublishConfigs.fileIncludes, + // configs.version, + // configs.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); diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index e22d9800c..77c768f4e 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -37,7 +37,7 @@ const packageNameToWebsitePath: { [name: string]: string } = { const shouldIncludePrivate = false; const updatedPublicPackages = await utils.getUpdatedPackagesAsync(shouldIncludePrivate); - await confirmDocPagesRenderAsync(updatedPublicPackages); + // await confirmDocPagesRenderAsync(updatedPublicPackages); // Update CHANGELOGs const updatedPublicPackageNames = _.map(updatedPublicPackages, pkg => pkg.packageJson.name); @@ -46,7 +46,7 @@ const packageNameToWebsitePath: { [name: string]: string } = { // Push changelog changes to Github if (!IS_DRY_RUN) { - await pushChangelogsToGithubAsync(); + // await pushChangelogsToGithubAsync(); } // Call LernaPublish -- cgit v1.2.3 From 76eab5d3ecfa5fe3b09392c54eb600e484576abc Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 23 Jul 2018 20:21:49 +0200 Subject: Fix publish to give lerna actual version rather then the semver diff --- packages/monorepo-scripts/src/publish.ts | 22 +++++++++++----------- packages/monorepo-scripts/src/types.ts | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 77c768f4e..6e5144e83 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -11,7 +11,7 @@ import semverDiff = require('semver-diff'); import semverSort = require('semver-sort'); import { constants } from './constants'; -import { Package, PackageToVersionChange, SemVerIndex, VersionChangelog } from './types'; +import { Package, PackageToNextVersion, SemVerIndex, VersionChangelog } from './types'; import { changelogUtils } from './utils/changelog_utils'; import { utils } from './utils/utils'; @@ -42,7 +42,7 @@ const packageNameToWebsitePath: { [name: string]: string } = { // Update CHANGELOGs const updatedPublicPackageNames = _.map(updatedPublicPackages, pkg => pkg.packageJson.name); utils.log(`Will update CHANGELOGs and publish: \n${updatedPublicPackageNames.join('\n')}\n`); - const packageToVersionChange = await updateChangeLogsAsync(updatedPublicPackages); + const packageToNextVersion = await updateChangeLogsAsync(updatedPublicPackages); // Push changelog changes to Github if (!IS_DRY_RUN) { @@ -51,11 +51,11 @@ const packageNameToWebsitePath: { [name: string]: string } = { // Call LernaPublish utils.log('Version updates to apply:'); - _.each(packageToVersionChange, (versionChange: string, packageName: string) => { + _.each(packageToNextVersion, (versionChange: string, packageName: string) => { utils.log(`${packageName} -> ${versionChange}`); }); utils.log(`Calling 'lerna publish'...`); - await lernaPublishAsync(packageToVersionChange); + await lernaPublishAsync(packageToNextVersion); })().catch(err => { utils.log(err); process.exit(1); @@ -110,8 +110,8 @@ async function pushChangelogsToGithubAsync(): Promise { utils.log(`Pushed CHANGELOG updates to Github`); } -async function updateChangeLogsAsync(updatedPublicPackages: Package[]): Promise { - const packageToVersionChange: PackageToVersionChange = {}; +async function updateChangeLogsAsync(updatedPublicPackages: Package[]): Promise { + const packageToNextVersion: PackageToNextVersion = {}; for (const pkg of updatedPublicPackages) { const packageName = pkg.packageJson.name; let changelog = changelogUtils.getChangelogOrCreateIfMissing(packageName, pkg.location); @@ -138,7 +138,7 @@ async function updateChangeLogsAsync(updatedPublicPackages: Package[]): Promise< ], }; changelog = [newChangelogEntry, ...changelog]; - packageToVersionChange[packageName] = semverDiff(currentVersion, nextPatchVersionIfValid); + packageToNextVersion[packageName] = nextPatchVersionIfValid; } else { // Update existing entry with timestamp const lastEntry = changelog[0]; @@ -149,7 +149,7 @@ async function updateChangeLogsAsync(updatedPublicPackages: Package[]): Promise< const proposedNextVersion = lastEntry.version; lastEntry.version = updateVersionNumberIfNeeded(currentVersion, proposedNextVersion); changelog[0] = lastEntry; - packageToVersionChange[packageName] = semverDiff(currentVersion, lastEntry.version); + packageToNextVersion[packageName] = lastEntry.version; } // Save updated CHANGELOG.json @@ -161,10 +161,10 @@ async function updateChangeLogsAsync(updatedPublicPackages: Package[]): Promise< utils.log(`${packageName}: Updated CHANGELOG.md`); } - return packageToVersionChange; + return packageToNextVersion; } -async function lernaPublishAsync(packageToVersionChange: { [name: string]: string }): Promise { +async function lernaPublishAsync(packageToNextVersion: { [name: string]: string }): Promise { // HACK: Lerna publish does not provide a way to specify multiple package versions via // flags so instead we need to interact with their interactive prompt interface. const child = spawn('lerna', ['publish', `--skip-git`], { @@ -186,7 +186,7 @@ async function lernaPublishAsync(packageToVersionChange: { [name: string]: strin } const isCustomVersionPrompt = _.includes(output, 'Enter a custom version'); if (isCustomVersionPrompt) { - const versionChange = packageToVersionChange[packageName]; + const versionChange = packageToNextVersion[packageName]; child.stdin.write(`${versionChange}\n`); return; } diff --git a/packages/monorepo-scripts/src/types.ts b/packages/monorepo-scripts/src/types.ts index 62d52d7bf..c0622debc 100644 --- a/packages/monorepo-scripts/src/types.ts +++ b/packages/monorepo-scripts/src/types.ts @@ -29,7 +29,7 @@ export enum SemVerIndex { Custom, } -export interface PackageToVersionChange { +export interface PackageToNextVersion { [name: string]: string; } -- cgit v1.2.3 From b110d95de14f55a2cc65fbb8a886872adcd9eea5 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 23 Jul 2018 20:29:14 +0200 Subject: testing --- packages/monorepo-scripts/src/publish.ts | 3 +++ 1 file changed, 3 insertions(+) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 6e5144e83..820dbc86e 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -187,6 +187,9 @@ async function lernaPublishAsync(packageToNextVersion: { [name: string]: string const isCustomVersionPrompt = _.includes(output, 'Enter a custom version'); if (isCustomVersionPrompt) { const versionChange = packageToNextVersion[packageName]; + if (_.isUndefined(versionChange)) { + console.log('versionChange', versionChange, ' UNDEFINED!'); + } child.stdin.write(`${versionChange}\n`); return; } -- cgit v1.2.3 From c9ee526d8b34638e457db32b9df801c05c197eea Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 23 Jul 2018 20:30:51 +0200 Subject: more bogus --- packages/monorepo-scripts/src/publish.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 820dbc86e..df93a46a0 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -188,7 +188,7 @@ async function lernaPublishAsync(packageToNextVersion: { [name: string]: string if (isCustomVersionPrompt) { const versionChange = packageToNextVersion[packageName]; if (_.isUndefined(versionChange)) { - console.log('versionChange', versionChange, ' UNDEFINED!'); + console.log('packageName', packageName, 'versionChange', versionChange, ' UNDEFINED!'); } child.stdin.write(`${versionChange}\n`); return; -- cgit v1.2.3 From 15bbbb37623845f5bb425e5ae3dbd0e02154cb0c Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 23 Jul 2018 20:36:03 +0200 Subject: Make sure private packages have a next version --- packages/monorepo-scripts/src/publish.ts | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index df93a46a0..9268de796 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -122,6 +122,14 @@ async function updateChangeLogsAsync(updatedPublicPackages: Package[]): Promise< currentVersion, changelog, ); + if (pkg.packageJson.private) { + const nextPatchVersionIfValid = semver.inc(currentVersion, 'patch'); + if (!_.isNull(nextPatchVersionIfValid)) { + packageToNextVersion[packageName] = nextPatchVersionIfValid; + } else { + throw new Error(`Encountered invalid semver version: ${currentVersion} for package: ${packageName}`); + } + } if (shouldAddNewEntry) { // Create a new entry for a patch version with generic changelog entry. const nextPatchVersionIfValid = semver.inc(currentVersion, 'patch'); -- cgit v1.2.3 From df00d93b9c3c9167700165500ff2dcc6c5681ac2 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 23 Jul 2018 20:44:47 +0200 Subject: Also add private package new versions to packageToNextVersion --- packages/monorepo-scripts/src/publish.ts | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 9268de796..e86036d57 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -34,16 +34,27 @@ const packageNameToWebsitePath: { [name: string]: string } = { (async () => { // Fetch public, updated Lerna packages - const shouldIncludePrivate = false; - const updatedPublicPackages = await utils.getUpdatedPackagesAsync(shouldIncludePrivate); + const shouldIncludePrivate = true; + const allUpdatedPackages = await utils.getUpdatedPackagesAsync(shouldIncludePrivate); // await confirmDocPagesRenderAsync(updatedPublicPackages); // Update CHANGELOGs + const updatedPublicPackages = _.filter(allUpdatedPackages, pkg => !pkg.packageJson.private); const updatedPublicPackageNames = _.map(updatedPublicPackages, pkg => pkg.packageJson.name); utils.log(`Will update CHANGELOGs and publish: \n${updatedPublicPackageNames.join('\n')}\n`); const packageToNextVersion = await updateChangeLogsAsync(updatedPublicPackages); + const updatedPrivatePackages = _.filter(allUpdatedPackages, pkg => pkg.packageJson.private); + _.each(updatedPrivatePackages, pkg => { + const nextPatchVersionIfValid = semver.inc(pkg.packageJson.version, 'patch'); + if (!_.isNull(nextPatchVersionIfValid)) { + packageToNextVersion[pkg.packageJson.name] = nextPatchVersionIfValid; + } else { + throw new Error(`Encountered invalid semver version: ${currentVersion} for package: ${packageName}`); + } + }); + // Push changelog changes to Github if (!IS_DRY_RUN) { // await pushChangelogsToGithubAsync(); @@ -122,14 +133,6 @@ async function updateChangeLogsAsync(updatedPublicPackages: Package[]): Promise< currentVersion, changelog, ); - if (pkg.packageJson.private) { - const nextPatchVersionIfValid = semver.inc(currentVersion, 'patch'); - if (!_.isNull(nextPatchVersionIfValid)) { - packageToNextVersion[packageName] = nextPatchVersionIfValid; - } else { - throw new Error(`Encountered invalid semver version: ${currentVersion} for package: ${packageName}`); - } - } if (shouldAddNewEntry) { // Create a new entry for a patch version with generic changelog entry. const nextPatchVersionIfValid = semver.inc(currentVersion, 'patch'); @@ -196,7 +199,7 @@ async function lernaPublishAsync(packageToNextVersion: { [name: string]: string if (isCustomVersionPrompt) { const versionChange = packageToNextVersion[packageName]; if (_.isUndefined(versionChange)) { - console.log('packageName', packageName, 'versionChange', versionChange, ' UNDEFINED!'); + throw new Error(`Must have a nextVersion for each packageName. Didn't find one for ${packageName}`); } child.stdin.write(`${versionChange}\n`); return; -- cgit v1.2.3 From 27d44e3021ed488419aa35173a97191e124c27d0 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 23 Jul 2018 20:46:10 +0200 Subject: Add missing vars --- packages/monorepo-scripts/src/publish.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index e86036d57..bd26057fb 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -47,9 +47,11 @@ const packageNameToWebsitePath: { [name: string]: string } = { const updatedPrivatePackages = _.filter(allUpdatedPackages, pkg => pkg.packageJson.private); _.each(updatedPrivatePackages, pkg => { - const nextPatchVersionIfValid = semver.inc(pkg.packageJson.version, 'patch'); + const currentVersion = pkg.packageJson.version; + const packageName = pkg.packageJson.name; + const nextPatchVersionIfValid = semver.inc(currentVersion, 'patch'); if (!_.isNull(nextPatchVersionIfValid)) { - packageToNextVersion[pkg.packageJson.name] = nextPatchVersionIfValid; + packageToNextVersion[packageName] = nextPatchVersionIfValid; } else { throw new Error(`Encountered invalid semver version: ${currentVersion} for package: ${packageName}`); } -- cgit v1.2.3 From dae975b08c23d1ad81be72f46ae64f59406953ab Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 23 Jul 2018 20:51:25 +0200 Subject: Add in print statements --- packages/monorepo-scripts/src/publish.ts | 3 +++ 1 file changed, 3 insertions(+) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index bd26057fb..1bdf5c218 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -187,6 +187,9 @@ async function lernaPublishAsync(packageToNextVersion: { [name: string]: string let packageName: string; child.stdout.on('data', (data: Buffer) => { const output = data.toString('utf8'); + console.log('-------'); + console.log(output); + console.log('-------'); if (shouldPrintOutput) { utils.log(output); } -- cgit v1.2.3 From bfe57b84d600c0d4aaa8b7a22323de6051f0751c Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 23 Jul 2018 20:59:41 +0200 Subject: Use string equals and remove returns --- packages/monorepo-scripts/src/publish.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 1bdf5c218..af707ca47 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -198,16 +198,14 @@ async function lernaPublishAsync(packageToNextVersion: { [name: string]: string const outputStripLeft = output.split('new version for ')[1]; packageName = outputStripLeft.split(' ')[0]; child.stdin.write(`${SemVerIndex.Custom}\n`); - return; } - const isCustomVersionPrompt = _.includes(output, 'Enter a custom version'); + const isCustomVersionPrompt = output === '? Enter a custom version '; if (isCustomVersionPrompt) { const versionChange = packageToNextVersion[packageName]; if (_.isUndefined(versionChange)) { throw new Error(`Must have a nextVersion for each packageName. Didn't find one for ${packageName}`); } child.stdin.write(`${versionChange}\n`); - return; } const isFinalPrompt = _.includes(output, 'Are you sure you want to publish the above changes?'); if (isFinalPrompt && !IS_DRY_RUN) { -- cgit v1.2.3 From 39a06e1d3b977b88225b18e171338196b17691df Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 23 Jul 2018 21:10:44 +0200 Subject: Add timeout before writing to stdin --- packages/monorepo-scripts/src/publish.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index af707ca47..6e2f1c3b8 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -193,11 +193,11 @@ async function lernaPublishAsync(packageToNextVersion: { [name: string]: string if (shouldPrintOutput) { utils.log(output); } - const isVersionPrompt = _.includes(output, 'Select a new version'); + const isVersionPrompt = /^\? Select a new version .* (currently .*)$/.test(output); if (isVersionPrompt) { const outputStripLeft = output.split('new version for ')[1]; packageName = outputStripLeft.split(' ')[0]; - child.stdin.write(`${SemVerIndex.Custom}\n`); + sleepAndWrite(child.stdin, SemVerIndex.Custom); } const isCustomVersionPrompt = output === '? Enter a custom version '; if (isCustomVersionPrompt) { @@ -205,11 +205,11 @@ async function lernaPublishAsync(packageToNextVersion: { [name: string]: string if (_.isUndefined(versionChange)) { throw new Error(`Must have a nextVersion for each packageName. Didn't find one for ${packageName}`); } - child.stdin.write(`${versionChange}\n`); + sleepAndWrite(child.stdin, versionChange); } const isFinalPrompt = _.includes(output, 'Are you sure you want to publish the above changes?'); if (isFinalPrompt && !IS_DRY_RUN) { - child.stdin.write(`y\n`); + sleepAndWrite(child.stdin, 'y'); // After confirmations, we want to print the output to watch the `lerna publish` command shouldPrintOutput = true; } else if (isFinalPrompt && IS_DRY_RUN) { @@ -224,6 +224,13 @@ async function lernaPublishAsync(packageToNextVersion: { [name: string]: string }); } +function sleepAndWrite(fileDescriptor: any, input: string | number): void { + const TIMEOUT = 100; + setTimeout(() => { + fileDescriptor.write(`${input}\n`); + }, TIMEOUT); +} + function updateVersionNumberIfNeeded(currentVersion: string, proposedNextVersion: string): string { const updatedVersionIfValid = semver.inc(currentVersion, 'patch'); if (_.isNull(updatedVersionIfValid)) { -- cgit v1.2.3 From 68974313e178bdee3c45b4556406960eaa26ce2a Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 23 Jul 2018 21:12:47 +0200 Subject: Make regex less strict --- packages/monorepo-scripts/src/publish.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 6e2f1c3b8..d1f9e4594 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -193,7 +193,7 @@ async function lernaPublishAsync(packageToNextVersion: { [name: string]: string if (shouldPrintOutput) { utils.log(output); } - const isVersionPrompt = /^\? Select a new version .* (currently .*)$/.test(output); + const isVersionPrompt = /^\? Select a new version .* (currently .*)/.test(output); if (isVersionPrompt) { const outputStripLeft = output.split('new version for ')[1]; packageName = outputStripLeft.split(' ')[0]; -- cgit v1.2.3 From df341717f78e8100802b110b1254181cc670ecc3 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 23 Jul 2018 21:14:51 +0200 Subject: Remove regex --- packages/monorepo-scripts/src/publish.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index d1f9e4594..4d5425ac6 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -193,7 +193,7 @@ async function lernaPublishAsync(packageToNextVersion: { [name: string]: string if (shouldPrintOutput) { utils.log(output); } - const isVersionPrompt = /^\? Select a new version .* (currently .*)/.test(output); + const isVersionPrompt = _.includes(output, 'Select a new version'); if (isVersionPrompt) { const outputStripLeft = output.split('new version for ')[1]; packageName = outputStripLeft.split(' ')[0]; -- cgit v1.2.3 From b4cd8897b293e903ad5710d90d9904e1bc56c08e Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 23 Jul 2018 21:20:09 +0200 Subject: Dedup versionPrompt being triggered multiple times --- packages/monorepo-scripts/src/publish.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 4d5425ac6..4506595e1 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -196,11 +196,16 @@ async function lernaPublishAsync(packageToNextVersion: { [name: string]: string const isVersionPrompt = _.includes(output, 'Select a new version'); if (isVersionPrompt) { const outputStripLeft = output.split('new version for ')[1]; - packageName = outputStripLeft.split(' ')[0]; + const packageNameFound = outputStripLeft.split(' ')[0]; + if (packageName === packageNameFound) { + return; // noop + } + packageName = packageNameFound; sleepAndWrite(child.stdin, SemVerIndex.Custom); } const isCustomVersionPrompt = output === '? Enter a custom version '; if (isCustomVersionPrompt) { + console.log('custom version prompt hit!'); const versionChange = packageToNextVersion[packageName]; if (_.isUndefined(versionChange)) { throw new Error(`Must have a nextVersion for each packageName. Didn't find one for ${packageName}`); @@ -225,8 +230,9 @@ async function lernaPublishAsync(packageToNextVersion: { [name: string]: string } function sleepAndWrite(fileDescriptor: any, input: string | number): void { - const TIMEOUT = 100; + const TIMEOUT = 1000; setTimeout(() => { + console.log('Printing to console:', input); fileDescriptor.write(`${input}\n`); }, TIMEOUT); } -- cgit v1.2.3 From 1d9a77027eaf2ae9a21262305f75a274b0bd214a Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 23 Jul 2018 21:23:09 +0200 Subject: Use include --- packages/monorepo-scripts/src/publish.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 4506595e1..df1bfff2f 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -203,9 +203,8 @@ async function lernaPublishAsync(packageToNextVersion: { [name: string]: string packageName = packageNameFound; sleepAndWrite(child.stdin, SemVerIndex.Custom); } - const isCustomVersionPrompt = output === '? Enter a custom version '; + const isCustomVersionPrompt = _.includes(output, 'Enter a custom version'); if (isCustomVersionPrompt) { - console.log('custom version prompt hit!'); const versionChange = packageToNextVersion[packageName]; if (_.isUndefined(versionChange)) { throw new Error(`Must have a nextVersion for each packageName. Didn't find one for ${packageName}`); @@ -232,7 +231,6 @@ async function lernaPublishAsync(packageToNextVersion: { [name: string]: string function sleepAndWrite(fileDescriptor: any, input: string | number): void { const TIMEOUT = 1000; setTimeout(() => { - console.log('Printing to console:', input); fileDescriptor.write(`${input}\n`); }, TIMEOUT); } -- cgit v1.2.3 From d50174b89eda6a9df590dac6b121885b74ec35d9 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 23 Jul 2018 21:33:03 +0200 Subject: Add ignore flag --- packages/monorepo-scripts/src/publish.ts | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index df1bfff2f..42d0a374f 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -185,7 +185,12 @@ async function lernaPublishAsync(packageToNextVersion: { [name: string]: string }); let shouldPrintOutput = false; let packageName: string; + let ignoreCounter = 0; child.stdout.on('data', (data: Buffer) => { + if (ignoreCounter !== 0) { + ignoreCounter--; + return; // ignore + } const output = data.toString('utf8'); console.log('-------'); console.log(output); @@ -201,6 +206,7 @@ async function lernaPublishAsync(packageToNextVersion: { [name: string]: string return; // noop } packageName = packageNameFound; + ignoreCounter = 1; // SemVerIndex.Custom is a single digit number sleepAndWrite(child.stdin, SemVerIndex.Custom); } const isCustomVersionPrompt = _.includes(output, 'Enter a custom version'); @@ -209,10 +215,12 @@ async function lernaPublishAsync(packageToNextVersion: { [name: string]: string if (_.isUndefined(versionChange)) { throw new Error(`Must have a nextVersion for each packageName. Didn't find one for ${packageName}`); } + ignoreCounter = versionChange.length; sleepAndWrite(child.stdin, versionChange); } const isFinalPrompt = _.includes(output, 'Are you sure you want to publish the above changes?'); if (isFinalPrompt && !IS_DRY_RUN) { + ignoreCounter = 'y'.length; sleepAndWrite(child.stdin, 'y'); // After confirmations, we want to print the output to watch the `lerna publish` command shouldPrintOutput = true; -- cgit v1.2.3 From 91dcfd5ee88d704ed9d56ec16e58f18ca04aa42b Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 24 Jul 2018 12:39:41 +0200 Subject: Use cdVersions flag instead of interactive prompt --- packages/monorepo-scripts/src/publish.ts | 67 ++------------------------------ 1 file changed, 4 insertions(+), 63 deletions(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 42d0a374f..7007b75e5 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -178,69 +178,10 @@ async function updateChangeLogsAsync(updatedPublicPackages: Package[]): Promise< } async function lernaPublishAsync(packageToNextVersion: { [name: string]: string }): Promise { - // HACK: Lerna publish does not provide a way to specify multiple package versions via - // flags so instead we need to interact with their interactive prompt interface. - const child = spawn('lerna', ['publish', `--skip-git`], { - cwd: constants.monorepoRootPath, - }); - let shouldPrintOutput = false; - let packageName: string; - let ignoreCounter = 0; - child.stdout.on('data', (data: Buffer) => { - if (ignoreCounter !== 0) { - ignoreCounter--; - return; // ignore - } - const output = data.toString('utf8'); - console.log('-------'); - console.log(output); - console.log('-------'); - if (shouldPrintOutput) { - utils.log(output); - } - const isVersionPrompt = _.includes(output, 'Select a new version'); - if (isVersionPrompt) { - const outputStripLeft = output.split('new version for ')[1]; - const packageNameFound = outputStripLeft.split(' ')[0]; - if (packageName === packageNameFound) { - return; // noop - } - packageName = packageNameFound; - ignoreCounter = 1; // SemVerIndex.Custom is a single digit number - sleepAndWrite(child.stdin, SemVerIndex.Custom); - } - const isCustomVersionPrompt = _.includes(output, 'Enter a custom version'); - if (isCustomVersionPrompt) { - const versionChange = packageToNextVersion[packageName]; - if (_.isUndefined(versionChange)) { - throw new Error(`Must have a nextVersion for each packageName. Didn't find one for ${packageName}`); - } - ignoreCounter = versionChange.length; - sleepAndWrite(child.stdin, versionChange); - } - const isFinalPrompt = _.includes(output, 'Are you sure you want to publish the above changes?'); - if (isFinalPrompt && !IS_DRY_RUN) { - ignoreCounter = 'y'.length; - sleepAndWrite(child.stdin, 'y'); - // After confirmations, we want to print the output to watch the `lerna publish` command - shouldPrintOutput = true; - } else if (isFinalPrompt && IS_DRY_RUN) { - utils.log( - `Submitted all versions to Lerna but since this is a dry run, did not confirm. You need to CTRL-C to exit.`, - ); - } - }); - child.stderr.on('data', (data: Buffer) => { - const output = data.toString('utf8'); - utils.log('Stderr:', output); - }); -} - -function sleepAndWrite(fileDescriptor: any, input: string | number): void { - const TIMEOUT = 1000; - setTimeout(() => { - fileDescriptor.write(`${input}\n`); - }, TIMEOUT); + const packageVersionString = _.map(packageToNextVersion, (nextVersion: string, packageName: string) => { + return `${packageName}@${nextVersion}`; + }).join(','); + await execAsync('lerna', `--cdVersions=${packageVersionString}`, '--skip-git'); } function updateVersionNumberIfNeeded(currentVersion: string, proposedNextVersion: string): string { -- cgit v1.2.3 From 73d75bc4052f4d122924d9be2e2fae4bc2764a90 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 24 Jul 2018 12:44:38 +0200 Subject: Fix publish command --- packages/monorepo-scripts/src/publish.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 7007b75e5..7d10c7d9e 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -4,14 +4,14 @@ import * as promisify from 'es6-promisify'; import * as _ from 'lodash'; import * as moment from 'moment'; import opn = require('opn'); -import { exec as execAsync, spawn } from 'promisify-child-process'; +import { exec as execAsync } from 'promisify-child-process'; import * as prompt from 'prompt'; import semver = require('semver'); import semverDiff = require('semver-diff'); import semverSort = require('semver-sort'); import { constants } from './constants'; -import { Package, PackageToNextVersion, SemVerIndex, VersionChangelog } from './types'; +import { Package, PackageToNextVersion, VersionChangelog } from './types'; import { changelogUtils } from './utils/changelog_utils'; import { utils } from './utils/utils'; @@ -181,7 +181,9 @@ async function lernaPublishAsync(packageToNextVersion: { [name: string]: string const packageVersionString = _.map(packageToNextVersion, (nextVersion: string, packageName: string) => { return `${packageName}@${nextVersion}`; }).join(','); - await execAsync('lerna', `--cdVersions=${packageVersionString}`, '--skip-git'); + const lernaPublishCmd = `lerna --cdVersions=${packageVersionString} --skip-git`; + console.log('lernaPublishCmd', lernaPublishCmd); + await execAsync(lernaPublishCmd, { cwd: constants.monorepoRootPath }); } function updateVersionNumberIfNeeded(currentVersion: string, proposedNextVersion: string): string { -- cgit v1.2.3 From 6f38d1bee5e13a0b684a17c7fbc689a4fbb051f8 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 24 Jul 2018 12:46:40 +0200 Subject: Add missing 'publish' --- packages/monorepo-scripts/src/publish.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 7d10c7d9e..66ecb912b 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -181,7 +181,7 @@ async function lernaPublishAsync(packageToNextVersion: { [name: string]: string const packageVersionString = _.map(packageToNextVersion, (nextVersion: string, packageName: string) => { return `${packageName}@${nextVersion}`; }).join(','); - const lernaPublishCmd = `lerna --cdVersions=${packageVersionString} --skip-git`; + const lernaPublishCmd = `lerna publish --cdVersions=${packageVersionString} --skip-git`; console.log('lernaPublishCmd', lernaPublishCmd); await execAsync(lernaPublishCmd, { cwd: constants.monorepoRootPath }); } -- cgit v1.2.3 From d280311734a26aed731bae4bcba5b091054a99f8 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 24 Jul 2018 13:19:31 +0200 Subject: Use relative path to lerna executable --- packages/monorepo-scripts/src/publish.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 66ecb912b..39af64a5a 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -7,7 +7,6 @@ import opn = require('opn'); import { exec as execAsync } from 'promisify-child-process'; import * as prompt from 'prompt'; import semver = require('semver'); -import semverDiff = require('semver-diff'); import semverSort = require('semver-sort'); import { constants } from './constants'; @@ -181,9 +180,10 @@ async function lernaPublishAsync(packageToNextVersion: { [name: string]: string const packageVersionString = _.map(packageToNextVersion, (nextVersion: string, packageName: string) => { return `${packageName}@${nextVersion}`; }).join(','); - const lernaPublishCmd = `lerna publish --cdVersions=${packageVersionString} --skip-git`; + const lernaPublishCmd = `${constants.lernaExecutable} publish --cdVersions=${packageVersionString} --skip-git`; console.log('lernaPublishCmd', lernaPublishCmd); - await execAsync(lernaPublishCmd, { cwd: constants.monorepoRootPath }); + const { stdout, stderr } = await execAsync(lernaPublishCmd, { cwd: constants.monorepoRootPath }); + console.log('stdout, stderr', stdout.toString(), stderr.toString()); } function updateVersionNumberIfNeeded(currentVersion: string, proposedNextVersion: string): string { -- cgit v1.2.3 From e9e73aa0a3c39dd9ad39749cc3df4e766edd816c Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 24 Jul 2018 13:21:28 +0200 Subject: Add node --- packages/monorepo-scripts/src/publish.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 39af64a5a..bc8d76ac6 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -180,7 +180,7 @@ async function lernaPublishAsync(packageToNextVersion: { [name: string]: string const packageVersionString = _.map(packageToNextVersion, (nextVersion: string, packageName: string) => { return `${packageName}@${nextVersion}`; }).join(','); - const lernaPublishCmd = `${constants.lernaExecutable} publish --cdVersions=${packageVersionString} --skip-git`; + const lernaPublishCmd = `node ${constants.lernaExecutable} publish --cdVersions=${packageVersionString} --skip-git`; console.log('lernaPublishCmd', lernaPublishCmd); const { stdout, stderr } = await execAsync(lernaPublishCmd, { cwd: constants.monorepoRootPath }); console.log('stdout, stderr', stdout.toString(), stderr.toString()); -- cgit v1.2.3 From 98b2875512f1a095fb2b6b549db47eda075ce0ee Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 24 Jul 2018 13:28:02 +0200 Subject: Add --yes flag --- packages/monorepo-scripts/src/publish.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index bc8d76ac6..6f3ec3742 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -180,7 +180,7 @@ async function lernaPublishAsync(packageToNextVersion: { [name: string]: string const packageVersionString = _.map(packageToNextVersion, (nextVersion: string, packageName: string) => { return `${packageName}@${nextVersion}`; }).join(','); - const lernaPublishCmd = `node ${constants.lernaExecutable} publish --cdVersions=${packageVersionString} --skip-git`; + const lernaPublishCmd = `node ${constants.lernaExecutable} publish --cdVersions=${packageVersionString} --skip-git --yes`; console.log('lernaPublishCmd', lernaPublishCmd); const { stdout, stderr } = await execAsync(lernaPublishCmd, { cwd: constants.monorepoRootPath }); console.log('stdout, stderr', stdout.toString(), stderr.toString()); -- cgit v1.2.3 From 8acfc9a2f9ad83add986cab7ae57940f421f97c4 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 24 Jul 2018 13:43:27 +0200 Subject: improve logs --- packages/monorepo-scripts/src/publish.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 6f3ec3742..4647b389a 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -181,9 +181,8 @@ async function lernaPublishAsync(packageToNextVersion: { [name: string]: string return `${packageName}@${nextVersion}`; }).join(','); const lernaPublishCmd = `node ${constants.lernaExecutable} publish --cdVersions=${packageVersionString} --skip-git --yes`; - console.log('lernaPublishCmd', lernaPublishCmd); - const { stdout, stderr } = await execAsync(lernaPublishCmd, { cwd: constants.monorepoRootPath }); - console.log('stdout, stderr', stdout.toString(), stderr.toString()); + utils.log('Lerna is publishing...'); + await execAsync(lernaPublishCmd, { cwd: constants.monorepoRootPath }); } function updateVersionNumberIfNeeded(currentVersion: string, proposedNextVersion: string): string { -- cgit v1.2.3 From 038602539542a94b99198fb51d72977a8806dc09 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 24 Jul 2018 15:19:36 +0200 Subject: Temp: Force publish --- packages/monorepo-scripts/src/publish.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 4647b389a..f3c406eed 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -180,7 +180,9 @@ async function lernaPublishAsync(packageToNextVersion: { [name: string]: string const packageVersionString = _.map(packageToNextVersion, (nextVersion: string, packageName: string) => { return `${packageName}@${nextVersion}`; }).join(','); - const lernaPublishCmd = `node ${constants.lernaExecutable} publish --cdVersions=${packageVersionString} --skip-git --yes`; + const lernaPublishCmd = `node ${ + constants.lernaExecutable + } publish --cdVersions=${packageVersionString} --skip-git --yes --force-publish *`; utils.log('Lerna is publishing...'); await execAsync(lernaPublishCmd, { cwd: constants.monorepoRootPath }); } -- cgit v1.2.3 From 2073aa9abcdaee04834b972bbafb455260a67e99 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 24 Jul 2018 15:19:57 +0200 Subject: Test installation on latest version, not the packed one --- packages/monorepo-scripts/src/test_installation.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/test_installation.ts b/packages/monorepo-scripts/src/test_installation.ts index 668d4ef1d..52868483f 100644 --- a/packages/monorepo-scripts/src/test_installation.ts +++ b/packages/monorepo-scripts/src/test_installation.ts @@ -16,16 +16,14 @@ import { utils } from './utils/utils'; pkg => !pkg.packageJson.private && !_.isUndefined(pkg.packageJson.main) && pkg.packageJson.main.endsWith('.js'), ); for (const installablePackage of installablePackages) { - const packagePath = installablePackage.location; const packageName = installablePackage.packageJson.name; + const packageVersion = installablePackage.packageJson.version; utils.log(`Testing ${packageName}`); - let result = await execAsync('npm pack', { cwd: packagePath }); - const packedPackageFileName = result.stdout.trim(); const testDirectory = path.join(monorepoRootPath, '../test-env'); fs.mkdirSync(testDirectory); - result = await execAsync('yarn init --yes', { cwd: testDirectory }); - utils.log(`Installing ${packedPackageFileName}`); - result = await execAsync(`yarn add ${packagePath}/${packedPackageFileName}`, { cwd: testDirectory }); + let result = await execAsync('yarn init --yes', { cwd: testDirectory }); + utils.log(`Installing ${packageName}@${packageVersion}`); + result = await execAsync(`yarn add ${packageName}@${packageVersion}`, { cwd: testDirectory }); const indexFilePath = path.join(testDirectory, 'index.ts'); fs.writeFileSync(indexFilePath, `import * as Package from '${packageName}';\n`); const tsConfig = { -- cgit v1.2.3 From f50ac932d6de28b3474ef8023813835badff4b09 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 24 Jul 2018 16:06:51 +0200 Subject: Introduce PackageJson file --- packages/monorepo-scripts/src/types.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/types.ts b/packages/monorepo-scripts/src/types.ts index c0622debc..c1483d884 100644 --- a/packages/monorepo-scripts/src/types.ts +++ b/packages/monorepo-scripts/src/types.ts @@ -46,16 +46,18 @@ export interface GitTagsByPackageName { [packageName: string]: string[]; } +export interface PackageJSON { + private?: boolean; + version: string; + name: string; + main?: string; + scripts?: { [command: string]: string }; + config?: { + additionalTsTypings?: string[]; + }; +} + export interface Package { location: string; - packageJson: { - private?: boolean; - version: string; - name: string; - main?: string; - scripts?: { [command: string]: string }; - config?: { - additionalTsTypings?: string[]; - }; - }; + packageJson: PackageJSON; } -- cgit v1.2.3 From d1e33a3dff3f62b7c84fd5b5d1307572853beeee Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 24 Jul 2018 16:07:11 +0200 Subject: Add utils.getTopologicallySortedPackages --- packages/monorepo-scripts/src/utils/utils.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/utils/utils.ts b/packages/monorepo-scripts/src/utils/utils.ts index 8ba59c81d..d9bae3ea9 100644 --- a/packages/monorepo-scripts/src/utils/utils.ts +++ b/packages/monorepo-scripts/src/utils/utils.ts @@ -1,10 +1,11 @@ +import batchPackages = require('@lerna/batch-packages'); import * as fs from 'fs'; import * as _ from 'lodash'; import { exec as execAsync } from 'promisify-child-process'; import semver = require('semver'); import { constants } from '../constants'; -import { GitTagsByPackageName, Package, UpdatedPackage } from '../types'; +import { GitTagsByPackageName, Package, PackageJSON, UpdatedPackage } from '../types'; import { changelogUtils } from './changelog_utils'; @@ -12,6 +13,15 @@ export const utils = { log(...args: any[]): void { console.log(...args); // tslint:disable-line:no-console }, + getTopologicallySortedPackages(rootDir: string): Package[] { + const packages = utils.getPackages(rootDir); + const batchedPackages: PackageJSON[] = _.flatten(batchPackages(_.map(packages, pkg => pkg.packageJson), false)); + const topsortedPackages: Package[] = _.map( + batchedPackages, + (pkg: PackageJSON) => _.find(packages, pkg1 => pkg1.packageJson.name === pkg.name) as Package, + ); + return topsortedPackages; + }, getPackages(rootDir: string): Package[] { const rootPackageJsonString = fs.readFileSync(`${rootDir}/package.json`, 'utf8'); const rootPackageJson = JSON.parse(rootPackageJsonString); -- cgit v1.2.3 From f699da90ba1658d50f251f988b27508cbf66b64c Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 24 Jul 2018 16:07:32 +0200 Subject: Pretend we defined types for @lerna/batch-packages --- packages/monorepo-scripts/src/globals.d.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/globals.d.ts b/packages/monorepo-scripts/src/globals.d.ts index cb6a61b55..2b25802ee 100644 --- a/packages/monorepo-scripts/src/globals.d.ts +++ b/packages/monorepo-scripts/src/globals.d.ts @@ -14,3 +14,4 @@ declare module 'semver-sort' { } declare module 'promisify-child-process'; +declare module '@lerna/batch-packages'; -- cgit v1.2.3 From 24aa5cd1bf38197a72be32a53f2e4a7c9aaf58ef Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 24 Jul 2018 16:08:07 +0200 Subject: Make the test:installation work with the local npm registry --- packages/monorepo-scripts/src/test_installation.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/test_installation.ts b/packages/monorepo-scripts/src/test_installation.ts index 52868483f..a9610e5ee 100644 --- a/packages/monorepo-scripts/src/test_installation.ts +++ b/packages/monorepo-scripts/src/test_installation.ts @@ -10,20 +10,27 @@ import { utils } from './utils/utils'; (async () => { const monorepoRootPath = path.join(__dirname, '../../..'); - const packages = utils.getPackages(monorepoRootPath); + const packages = utils.getTopologicallySortedPackages(monorepoRootPath); const installablePackages = _.filter( packages, pkg => !pkg.packageJson.private && !_.isUndefined(pkg.packageJson.main) && pkg.packageJson.main.endsWith('.js'), ); + utils.log('Testing packages:'); + _.map(installablePackages, pkg => utils.log(`* ${pkg.packageJson.name}`)); for (const installablePackage of installablePackages) { + const changelogPath = path.join(installablePackage.location, 'CHANGELOG.json'); + const lastChangelogVersion = JSON.parse(fs.readFileSync(changelogPath).toString())[0].version; const packageName = installablePackage.packageJson.name; - const packageVersion = installablePackage.packageJson.version; utils.log(`Testing ${packageName}`); const testDirectory = path.join(monorepoRootPath, '../test-env'); fs.mkdirSync(testDirectory); - let result = await execAsync('yarn init --yes', { cwd: testDirectory }); - utils.log(`Installing ${packageName}@${packageVersion}`); - result = await execAsync(`yarn add ${packageName}@${packageVersion}`, { cwd: testDirectory }); + await execAsync('yarn init --yes', { cwd: testDirectory }); + const npmrcFilePath = path.join(testDirectory, '.npmrc'); + fs.writeFileSync(npmrcFilePath, `registry=http://localhost:4873`); + utils.log(`Installing ${packageName}@${lastChangelogVersion}`); + await execAsync(`npm install --save ${packageName}@${lastChangelogVersion} --registry=http://localhost:4873`, { + cwd: testDirectory, + }); const indexFilePath = path.join(testDirectory, 'index.ts'); fs.writeFileSync(indexFilePath, `import * as Package from '${packageName}';\n`); const tsConfig = { -- cgit v1.2.3 From c5859b65a395f31c87a3d3fbd303ed17156be09f Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 24 Jul 2018 19:35:13 +0200 Subject: Install our fork of lerna and use it --- packages/monorepo-scripts/src/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/constants.ts b/packages/monorepo-scripts/src/constants.ts index f08313bd2..e5d3348bd 100644 --- a/packages/monorepo-scripts/src/constants.ts +++ b/packages/monorepo-scripts/src/constants.ts @@ -3,6 +3,6 @@ import * as path from 'path'; export const constants = { monorepoRootPath: path.join(__dirname, '../../..'), stagingWebsite: 'http://staging-0xproject.s3-website-us-east-1.amazonaws.com', - lernaExecutable: path.join('node_modules', 'lerna', 'cli.js'), + lernaExecutable: path.join('node_modules', '@0x-lerna-fork', 'lerna', 'cli.js'), githubPersonalAccessToken: process.env.GITHUB_PERSONAL_ACCESS_TOKEN_0X_JS, }; -- cgit v1.2.3 From dbc798596b052d3e28cf5772c94789d37ee5a4c7 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 24 Jul 2018 21:37:01 +0200 Subject: Replace dry mode with local publishing mode --- packages/monorepo-scripts/src/postpublish_utils.ts | 47 ++++++++++++---------- packages/monorepo-scripts/src/publish.ts | 17 ++++---- 2 files changed, 36 insertions(+), 28 deletions(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/postpublish_utils.ts b/packages/monorepo-scripts/src/postpublish_utils.ts index 8c9d95e44..229bb9031 100644 --- a/packages/monorepo-scripts/src/postpublish_utils.ts +++ b/packages/monorepo-scripts/src/postpublish_utils.ts @@ -25,6 +25,8 @@ 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)) { @@ -51,27 +53,30 @@ export const postpublishUtils = { return configs; }, async runAsync(packageJSON: any, tsConfigJSON: any, cwd: string): Promise { - // const configs = postpublishUtils.generateConfig(packageJSON, tsConfigJSON, cwd); - // await postpublishUtils.publishReleaseNotesAsync( - // configs.cwd, - // configs.packageName, - // configs.version, - // configs.assets, - // ); - // if ( - // !_.isUndefined(configs.docPublishConfigs.s3BucketPath) || - // !_.isUndefined(configs.docPublishConfigs.s3StagingBucketPath) - // ) { - // utils.log('POSTPUBLISH: Release successful, generating docs...'); - // await postpublishUtils.generateAndUploadDocsAsync( - // configs.cwd, - // configs.docPublishConfigs.fileIncludes, - // configs.version, - // configs.docPublishConfigs.s3BucketPath, - // ); - // } else { - // utils.log(`POSTPUBLISH: No S3Bucket config found for ${packageJSON.name}. Skipping doc JSON generation.`); - // } + if (IS_LOCAL_PUBLISH) { + return; + } + const configs = postpublishUtils.generateConfig(packageJSON, tsConfigJSON, cwd); + await postpublishUtils.publishReleaseNotesAsync( + configs.cwd, + configs.packageName, + configs.version, + configs.assets, + ); + if ( + !_.isUndefined(configs.docPublishConfigs.s3BucketPath) || + !_.isUndefined(configs.docPublishConfigs.s3StagingBucketPath) + ) { + utils.log('POSTPUBLISH: Release successful, generating docs...'); + await postpublishUtils.generateAndUploadDocsAsync( + configs.cwd, + configs.docPublishConfigs.fileIncludes, + configs.version, + configs.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); diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index f3c406eed..71eb16a98 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -16,7 +16,7 @@ import { utils } from './utils/utils'; const DOC_GEN_COMMAND = 'docs:json'; const NPM_NAMESPACE = '@0xproject/'; -const IS_DRY_RUN = process.env.IS_DRY_RUN === 'true'; +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,9 @@ const packageNameToWebsitePath: { [name: string]: string } = { const shouldIncludePrivate = true; const allUpdatedPackages = await utils.getUpdatedPackagesAsync(shouldIncludePrivate); - // await confirmDocPagesRenderAsync(updatedPublicPackages); + if (!IS_LOCAL_PUBLISH) { + await confirmDocPagesRenderAsync(allUpdatedPackages); + } // Update CHANGELOGs const updatedPublicPackages = _.filter(allUpdatedPackages, pkg => !pkg.packageJson.private); @@ -57,8 +59,8 @@ const packageNameToWebsitePath: { [name: string]: string } = { }); // Push changelog changes to Github - if (!IS_DRY_RUN) { - // await pushChangelogsToGithubAsync(); + if (!IS_LOCAL_PUBLISH) { + await pushChangelogsToGithubAsync(); } // Call LernaPublish @@ -180,9 +182,10 @@ async function lernaPublishAsync(packageToNextVersion: { [name: string]: string const packageVersionString = _.map(packageToNextVersion, (nextVersion: string, packageName: string) => { return `${packageName}@${nextVersion}`; }).join(','); - const lernaPublishCmd = `node ${ - constants.lernaExecutable - } publish --cdVersions=${packageVersionString} --skip-git --yes --force-publish *`; + let lernaPublishCmd = `node ${constants.lernaExecutable} publish --cdVersions=${packageVersionString}`; + if (IS_LOCAL_PUBLISH) { + lernaPublishCmd += ' --skip-git --yes --force-publish *'; + } utils.log('Lerna is publishing...'); await execAsync(lernaPublishCmd, { cwd: constants.monorepoRootPath }); } -- cgit v1.2.3 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/monorepo-scripts/src') 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 From f9e99a27d3b274cefa9065e9cd5dabd4a2cc6057 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 25 Jul 2018 11:51:06 +0200 Subject: Remove force publish --- packages/monorepo-scripts/src/publish.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index d5238ab52..d1df4c56e 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -186,7 +186,7 @@ async function lernaPublishAsync(packageToNextVersion: { [name: string]: string configs.NPM_REGISTRY_URL }`; if (configs.IS_LOCAL_PUBLISH) { - lernaPublishCmd += ` --skip-git --yes --force-publish *`; + lernaPublishCmd += ` --skip-git --yes`; } utils.log('Lerna is publishing...'); await execAsync(lernaPublishCmd, { cwd: constants.monorepoRootPath }); -- cgit v1.2.3 From f13d43dbf5fa108cd3b7a250a3bc01471914fa6d Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 25 Jul 2018 11:54:51 +0200 Subject: Remove unused typwe --- packages/monorepo-scripts/src/types.ts | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/types.ts b/packages/monorepo-scripts/src/types.ts index c1483d884..d9e1dfabb 100644 --- a/packages/monorepo-scripts/src/types.ts +++ b/packages/monorepo-scripts/src/types.ts @@ -17,18 +17,6 @@ export interface VersionChangelog { changes: Change[]; } -export enum SemVerIndex { - Invalid, - Patch, - Minor, - Major, - Prepatch, - Preminor, - Premajor, - Prerelease, - Custom, -} - export interface PackageToNextVersion { [name: string]: string; } -- cgit v1.2.3 From 28114c3b5a7b4bff55c813aba1bad246eef29169 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 25 Jul 2018 12:04:45 +0200 Subject: Remove unused import --- packages/monorepo-scripts/src/utils/npm_utils.ts | 1 - 1 file changed, 1 deletion(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/utils/npm_utils.ts b/packages/monorepo-scripts/src/utils/npm_utils.ts index 9c8e51508..363e31fbb 100644 --- a/packages/monorepo-scripts/src/utils/npm_utils.ts +++ b/packages/monorepo-scripts/src/utils/npm_utils.ts @@ -1,4 +1,3 @@ -import * as fs from 'fs'; import 'isomorphic-fetch'; import * as _ from 'lodash'; -- cgit v1.2.3