From 29042e1939315b997422d095fc1c23364f752a63 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 3 Apr 2018 09:36:43 +0900 Subject: Remove temporary convert_changelog script --- .../monorepo-scripts/src/convert_changelogs.ts | 99 ---------------------- 1 file changed, 99 deletions(-) delete mode 100644 packages/monorepo-scripts/src/convert_changelogs.ts (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/convert_changelogs.ts b/packages/monorepo-scripts/src/convert_changelogs.ts deleted file mode 100644 index b5be14ed8..000000000 --- a/packages/monorepo-scripts/src/convert_changelogs.ts +++ /dev/null @@ -1,99 +0,0 @@ -#!/usr/bin/env node -/** - * TEMPORARY SCRIPT - * This script exists to migrate the legacy CHANGELOG.md to the canonical CHANGELOG.md - * TODO: Remove after migration is successful and committed. - */ - -import * as fs from 'fs'; -import lernaGetPackages = require('lerna-get-packages'); -import * as _ from 'lodash'; -import * as moment from 'moment'; -import * as path from 'path'; -import { exec as execAsync } from 'promisify-child-process'; - -import { constants } from './constants'; -import { Changelog, Changes, UpdatedPackage } from './types'; -import { utils } from './utils'; - -const HEADER_PRAGMA = '##'; - -(async () => { - const allLernaPackages = lernaGetPackages(constants.monorepoRootPath); - const publicLernaPackages = _.filter(allLernaPackages, pkg => !pkg.package.private); - for (const lernaPackage of publicLernaPackages) { - const changelogMdIfExists = getChangelogMdIfExists(lernaPackage.package.name, lernaPackage.location); - if (_.isUndefined(changelogMdIfExists)) { - throw new Error(`${lernaPackage.package.name} should have CHANGELOG.md b/c it's public. Add one.`); - } - - const lines = changelogMdIfExists.split('\n'); - const changelogs: Changelog[] = []; - let changelog: Changelog = { - version: '', - changes: [], - }; - /** - * Example MD entry: - * ## v0.3.1 - _March 18, 2018_ - * - * * Add TS types for `yargs` (#400) - */ - for (const line of lines) { - if (_.startsWith(line, `${HEADER_PRAGMA} `)) { - let version = line.substr(4).split(' - ')[0]; - if (version === '0.x.x') { - version = utils.getNextPatchVersion(lernaPackage.package.version); - } - const dateStr = line.split('_')[1]; - let date; - if (!_.includes(dateStr, 'TBD')) { - date = moment(dateStr, 'MMMM D, YYYY'); - } - changelog = { - version, - changes: [], - }; - if (!_.isUndefined(date)) { - changelog.timestamp = date.unix(); - } - if (!_.includes(dateStr, 'TBD')) { - changelog.isPublished = true; - } - changelogs.push(changelog); - } else if (_.includes(line, '* ')) { - const note = line.split('* ')[1].split(' (#')[0]; - const prChunk = line.split(' (#')[1]; - let pr; - if (!_.isUndefined(prChunk)) { - pr = prChunk.split(')')[0]; - } - const changes: Changes = { - note, - }; - if (!_.isUndefined(pr)) { - changes.pr = _.parseInt(pr); - } - changelog.changes.push(changes); - } - } - const changelogJSON = JSON.stringify(changelogs, null, 4); - const changelogJSONPath = `${lernaPackage.location}/CHANGELOG.json`; - fs.writeFileSync(changelogJSONPath, changelogJSON); - await utils.prettifyAsync(changelogJSONPath, constants.monorepoRootPath); - } -})().catch(err => { - utils.log(err.stdout); - process.exit(1); -}); - -function getChangelogMdIfExists(packageName: string, location: string): string | undefined { - const changelogPath = path.join(location, 'CHANGELOG.md'); - let changelogMd: string; - try { - changelogMd = fs.readFileSync(changelogPath, 'utf-8'); - return changelogMd; - } catch (err) { - return undefined; - } -} -- cgit v1.2.3 From dd87588dfec2b9ec79b47b72e1dd99afadcbabe7 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 3 Apr 2018 09:45:30 +0900 Subject: Now that every version of a package published has a corresponding entry in it's CHANGELOG we no longer need the isPublished flag. Remove it. --- packages/monorepo-scripts/src/postpublish_utils.ts | 44 ++++++++-------------- packages/monorepo-scripts/src/publish.ts | 7 ++-- packages/monorepo-scripts/src/types.ts | 1 - 3 files changed, 19 insertions(+), 33 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 236b54379..ca4c92f5d 100644 --- a/packages/monorepo-scripts/src/postpublish_utils.ts +++ b/packages/monorepo-scripts/src/postpublish_utils.ts @@ -91,7 +91,7 @@ export const postpublishUtils = { ); }, async publishReleaseNotesAsync(cwd: string, packageName: string, version: string, assets: string[]): Promise { - const notes = this.getReleaseNotes(packageName); + const notes = this.getReleaseNotes(packageName, version); const releaseName = this.getReleaseName(packageName, version); const tag = this.getTag(packageName, version); const finalAssets = this.adjustAssetPaths(cwd, assets); @@ -109,9 +109,8 @@ export const postpublishUtils = { reuseDraftOnly: false, assets, }); - this.updateChangelogIsPublished(packageName); }, - getReleaseNotes(packageName: string) { + getReleaseNotes(packageName: string, version: string) { const packageNameWithNamespace = packageName.replace('@0xproject/', ''); const changelogJSONPath = path.join( constants.monorepoRootPath, @@ -122,33 +121,20 @@ export const postpublishUtils = { const changelogJSON = fs.readFileSync(changelogJSONPath, 'utf-8'); const changelogs = JSON.parse(changelogJSON); const latestLog = changelogs[0]; - if (_.isUndefined(latestLog.isPublished)) { - let notes = ''; - _.each(latestLog.changes, change => { - notes += `* ${change.note}`; - if (change.pr) { - notes += ` (${change.pr})`; - } - notes += `\n`; - }); - return notes; + // We sanity check that the version for the changelog notes we are about to publish to Github + // correspond to the new version of the package. + if (version !== latestLog.version) { + throw new Error('Expected CHANGELOG.json latest entry version to coincide with published version.'); } - return 'N/A'; - }, - updateChangelogIsPublished(packageName: string) { - const packageNameWithNamespace = packageName.replace('@0xproject/', ''); - const changelogJSONPath = path.join( - constants.monorepoRootPath, - 'packages', - packageNameWithNamespace, - 'CHANGELOG.json', - ); - const changelogJSON = fs.readFileSync(changelogJSONPath, 'utf-8'); - const changelogs = JSON.parse(changelogJSON); - const latestLog = changelogs[0]; - latestLog.isPublished = true; - changelogs[0] = latestLog; - fs.writeFileSync(changelogJSONPath, JSON.stringify(changelogs, null, '\t')); + let notes = ''; + _.each(latestLog.changes, change => { + notes += `* ${change.note}`; + if (change.pr) { + notes += ` (${change.pr})`; + } + notes += `\n`; + }); + return notes; }, getTag(packageName: string, version: string) { return `${packageName}@${version}`; diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index d749ec630..adc1de64a 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -48,7 +48,7 @@ const semverNameToIndex: { [semver: string]: number } = { } const currentVersion = lernaPackage.package.version; - const shouldAddNewEntry = shouldAddNewChangelogEntry(changelogs); + const shouldAddNewEntry = shouldAddNewChangelogEntry(currentVersion, changelogs); if (shouldAddNewEntry) { // Create a new entry for a patch version with generic changelog entry. const nextPatchVersion = utils.getNextPatchVersion(currentVersion); @@ -174,12 +174,13 @@ function getChangelogJSONOrCreateIfMissing(packageName: string, changelogPath: s } } -function shouldAddNewChangelogEntry(changelogs: Changelog[]): boolean { +function shouldAddNewChangelogEntry(currentVersion: string, changelogs: Changelog[]): boolean { if (_.isEmpty(changelogs)) { return true; } const lastEntry = changelogs[0]; - return !!lastEntry.isPublished; + const lastEntryCurrentVersion = lastEntry.version === currentVersion; + return lastEntryCurrentVersion; } function generateChangelogMd(changelogs: Changelog[]): string { diff --git a/packages/monorepo-scripts/src/types.ts b/packages/monorepo-scripts/src/types.ts index 7adec202f..9e6edd186 100644 --- a/packages/monorepo-scripts/src/types.ts +++ b/packages/monorepo-scripts/src/types.ts @@ -13,7 +13,6 @@ export interface Changelog { timestamp?: number; version: string; changes: Changes[]; - isPublished?: boolean; } export enum SemVerIndex { -- cgit v1.2.3 From 8281be235cf55b04f24297bf6606a8dc24d8fac7 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 3 Apr 2018 12:03:59 +0900 Subject: Use @0xproject/utils promisify everywhere --- packages/monorepo-scripts/src/globals.d.ts | 1 - packages/monorepo-scripts/src/postpublish_utils.ts | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) (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 c5898d0f5..b9f3d2e71 100644 --- a/packages/monorepo-scripts/src/globals.d.ts +++ b/packages/monorepo-scripts/src/globals.d.ts @@ -1,6 +1,5 @@ declare module 'async-child-process'; declare module 'publish-release'; -declare module 'es6-promisify'; declare module 'semver-diff'; // semver-sort declarations diff --git a/packages/monorepo-scripts/src/postpublish_utils.ts b/packages/monorepo-scripts/src/postpublish_utils.ts index 236b54379..d068adb4d 100644 --- a/packages/monorepo-scripts/src/postpublish_utils.ts +++ b/packages/monorepo-scripts/src/postpublish_utils.ts @@ -1,5 +1,5 @@ +import { promisify } from '@0xproject/utils'; import { execAsync } from 'async-child-process'; -import * as promisify from 'es6-promisify'; import * as fs from 'fs'; import * as _ from 'lodash'; import * as path from 'path'; -- cgit v1.2.3 From a88b4040ffdf1057ffb539c79c4ec517a670a950 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 3 Apr 2018 12:58:45 +0900 Subject: Stop using utils --- packages/monorepo-scripts/src/globals.d.ts | 1 + packages/monorepo-scripts/src/postpublish_utils.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (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 b9f3d2e71..c5898d0f5 100644 --- a/packages/monorepo-scripts/src/globals.d.ts +++ b/packages/monorepo-scripts/src/globals.d.ts @@ -1,5 +1,6 @@ declare module 'async-child-process'; declare module 'publish-release'; +declare module 'es6-promisify'; declare module 'semver-diff'; // semver-sort declarations diff --git a/packages/monorepo-scripts/src/postpublish_utils.ts b/packages/monorepo-scripts/src/postpublish_utils.ts index d068adb4d..236b54379 100644 --- a/packages/monorepo-scripts/src/postpublish_utils.ts +++ b/packages/monorepo-scripts/src/postpublish_utils.ts @@ -1,5 +1,5 @@ -import { promisify } from '@0xproject/utils'; import { execAsync } from 'async-child-process'; +import * as promisify from 'es6-promisify'; import * as fs from 'fs'; import * as _ from 'lodash'; import * as path from 'path'; -- cgit v1.2.3 From fd9278ac02d7c03bb70a34205ef012cf432f879f Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 3 Apr 2018 15:28:07 +0900 Subject: Add find_unused_deps monorepo script --- .../src/find_unused_dependencies.ts | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 packages/monorepo-scripts/src/find_unused_dependencies.ts (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/find_unused_dependencies.ts b/packages/monorepo-scripts/src/find_unused_dependencies.ts new file mode 100644 index 000000000..406500b21 --- /dev/null +++ b/packages/monorepo-scripts/src/find_unused_dependencies.ts @@ -0,0 +1,44 @@ +#!/usr/bin/env node + +import * as depcheck from 'depcheck'; +import * as fs from 'fs'; +import lernaGetPackages = require('lerna-get-packages'); +import * as _ from 'lodash'; +import { exec as execAsync } from 'promisify-child-process'; + +import { constants } from './constants'; +import { utils } from './utils'; + +const IGNORE_PACKAGES = ['@0xproject/deployer']; + +(async () => { + utils.log('*** NOTE: Not all deps listed here are actually not required. ***'); + utils.log("*** `depcheck` isn't perfect so double check before actually removing any. ***\n"); + const lernaPackages = lernaGetPackages(constants.monorepoRootPath); + for (const lernaPackage of lernaPackages) { + if (_.includes(IGNORE_PACKAGES, lernaPackage.package.name)) { + continue; // skip + } + utils.log(`Checking ${lernaPackage.package.name} for unused deps. This might take a while...`); + + const configs = {}; + const result: any = await depcheckAsync(lernaPackage.location, configs); + if (!_.isEmpty(result.dependencies)) { + _.each(result.dependencies, dep => { + utils.log(dep); + }); + } + utils.log('\n'); + } +})().catch(err => { + utils.log(err); + process.exit(1); +}); + +async function depcheckAsync(path: string, opts: any) { + return new Promise((resolve, reject) => { + depcheck(path, opts, (unused: any) => { + resolve(unused); + }); + }); +} -- cgit v1.2.3 From e9cb5c069a46a2402fb2e930b3f14a71e056d207 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 3 Apr 2018 15:44:07 +0900 Subject: Add comment about ignored packages --- packages/monorepo-scripts/src/find_unused_dependencies.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/find_unused_dependencies.ts b/packages/monorepo-scripts/src/find_unused_dependencies.ts index 406500b21..1b47f2458 100644 --- a/packages/monorepo-scripts/src/find_unused_dependencies.ts +++ b/packages/monorepo-scripts/src/find_unused_dependencies.ts @@ -9,6 +9,7 @@ import { exec as execAsync } from 'promisify-child-process'; import { constants } from './constants'; import { utils } from './utils'; +// For some reason, `depcheck` hangs on some packages. Add them here. const IGNORE_PACKAGES = ['@0xproject/deployer']; (async () => { -- cgit v1.2.3 From b2c423dd8410b884357fdb476012e4a213e52580 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 4 Apr 2018 03:54:58 +0900 Subject: Use Results type --- packages/monorepo-scripts/src/find_unused_dependencies.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/find_unused_dependencies.ts b/packages/monorepo-scripts/src/find_unused_dependencies.ts index 1b47f2458..374cba2e3 100644 --- a/packages/monorepo-scripts/src/find_unused_dependencies.ts +++ b/packages/monorepo-scripts/src/find_unused_dependencies.ts @@ -23,7 +23,7 @@ const IGNORE_PACKAGES = ['@0xproject/deployer']; utils.log(`Checking ${lernaPackage.package.name} for unused deps. This might take a while...`); const configs = {}; - const result: any = await depcheckAsync(lernaPackage.location, configs); + const result = await depcheckAsync(lernaPackage.location, configs); if (!_.isEmpty(result.dependencies)) { _.each(result.dependencies, dep => { utils.log(dep); @@ -36,8 +36,8 @@ const IGNORE_PACKAGES = ['@0xproject/deployer']; process.exit(1); }); -async function depcheckAsync(path: string, opts: any) { - return new Promise((resolve, reject) => { +async function depcheckAsync(path: string, opts: any): Promise { + return new Promise((resolve, reject) => { depcheck(path, opts, (unused: any) => { resolve(unused); }); -- cgit v1.2.3 From 249bf0163d8ee71b7329fd58b72e554c0324279c Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 3 Apr 2018 16:19:38 +0300 Subject: Move our contract templates to accept Provider instead of Web3Wrapper --- .../monorepo-scripts/src/find_unused_dependencies.ts | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/find_unused_dependencies.ts b/packages/monorepo-scripts/src/find_unused_dependencies.ts index 374cba2e3..bfc38044c 100644 --- a/packages/monorepo-scripts/src/find_unused_dependencies.ts +++ b/packages/monorepo-scripts/src/find_unused_dependencies.ts @@ -1,6 +1,6 @@ #!/usr/bin/env node -import * as depcheck from 'depcheck'; +import * as depcheckAsync from 'depcheck'; import * as fs from 'fs'; import lernaGetPackages = require('lerna-get-packages'); import * as _ from 'lodash'; @@ -23,9 +23,9 @@ const IGNORE_PACKAGES = ['@0xproject/deployer']; utils.log(`Checking ${lernaPackage.package.name} for unused deps. This might take a while...`); const configs = {}; - const result = await depcheckAsync(lernaPackage.location, configs); - if (!_.isEmpty(result.dependencies)) { - _.each(result.dependencies, dep => { + const { dependencies } = await depcheckAsync(lernaPackage.location, configs); + if (!_.isEmpty(dependencies)) { + _.each(dependencies, dep => { utils.log(dep); }); } @@ -35,11 +35,3 @@ const IGNORE_PACKAGES = ['@0xproject/deployer']; utils.log(err); process.exit(1); }); - -async function depcheckAsync(path: string, opts: any): Promise { - return new Promise((resolve, reject) => { - depcheck(path, opts, (unused: any) => { - resolve(unused); - }); - }); -} -- cgit v1.2.3 From b7e98abc43daa4c625e155327cf8ea5656da2451 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 9 Apr 2018 19:11:18 +0900 Subject: Refactor publish script to have it's main execution body be lean and discrete steps --- packages/monorepo-scripts/src/publish.ts | 61 +++++++++++++++++++++----------- packages/monorepo-scripts/src/types.ts | 4 +++ 2 files changed, 44 insertions(+), 21 deletions(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index adc1de64a..f0fb00acd 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -10,7 +10,7 @@ import semverDiff = require('semver-diff'); import semverSort = require('semver-sort'); import { constants } from './constants'; -import { Changelog, Changes, SemVerIndex, UpdatedPackage } from './types'; +import { Changelog, Changes, PackageToVersionChange, SemVerIndex, UpdatedPackage } from './types'; import { utils } from './utils'; const IS_DRY_RUN = process.env.IS_DRY_RUN === 'true'; @@ -23,6 +23,39 @@ const semverNameToIndex: { [semver: string]: number } = { }; (async () => { + // Fetch public, updated Lerna packages + const updatedPublicLernaPackages = await getUpdatedPublicLernaPackagesAsync(); + + // Update CHANGELOGs + const updatedPublicLernaPackageNames = _.map(updatedPublicLernaPackages, pkg => pkg.package.name); + utils.log(`Will update CHANGELOGs and publish: \n${updatedPublicLernaPackageNames.join('\n')}\n`); + const packageToVersionChange = await updateChangeLogsAsync(updatedPublicLernaPackages); + + // Push changelog changes to Github + if (!IS_DRY_RUN) { + await pushChangelogsToGithubAsync(); + } + + // Call LernaPublish + utils.log('Version updates to apply:'); + _.each(packageToVersionChange, (versionChange: string, packageName: string) => { + utils.log(`${packageName} -> ${versionChange}`); + }); + utils.log(`Calling 'lerna publish'...`); + await lernaPublishAsync(packageToVersionChange); +})().catch(err => { + utils.log(err); + process.exit(1); +}); + +async function pushChangelogsToGithubAsync() { + await execAsync(`git add . --all`, { cwd: constants.monorepoRootPath }); + await execAsync(`git commit -m "Updated CHANGELOGS"`, { cwd: constants.monorepoRootPath }); + await execAsync(`git push`, { cwd: constants.monorepoRootPath }); + utils.log(`Pushed CHANGELOG updates to Github`); +} + +async function getUpdatedPublicLernaPackagesAsync(): Promise { const updatedPublicPackages = await getPublicLernaUpdatedPackagesAsync(); const updatedPackageNames = _.map(updatedPublicPackages, pkg => pkg.name); @@ -30,10 +63,11 @@ const semverNameToIndex: { [semver: string]: number } = { const updatedPublicLernaPackages = _.filter(allLernaPackages, pkg => { return _.includes(updatedPackageNames, pkg.package.name); }); - const updatedPublicLernaPackageNames = _.map(updatedPublicLernaPackages, pkg => pkg.package.name); - utils.log(`Will update CHANGELOGs and publish: \n${updatedPublicLernaPackageNames.join('\n')}\n`); + return updatedPublicLernaPackages; +} - const packageToVersionChange: { [name: string]: string } = {}; +async function updateChangeLogsAsync(updatedPublicLernaPackages: LernaPackage[]): Promise { + const packageToVersionChange: PackageToVersionChange = {}; for (const lernaPackage of updatedPublicLernaPackages) { const packageName = lernaPackage.package.name; const changelogJSONPath = path.join(lernaPackage.location, 'CHANGELOG.json'); @@ -88,23 +122,8 @@ const semverNameToIndex: { [semver: string]: number } = { utils.log(`${packageName}: Updated CHANGELOG.md`); } - if (!IS_DRY_RUN) { - await execAsync(`git add . --all`, { cwd: constants.monorepoRootPath }); - await execAsync(`git commit -m "Updated CHANGELOGS"`, { cwd: constants.monorepoRootPath }); - await execAsync(`git push`, { cwd: constants.monorepoRootPath }); - utils.log(`Pushed CHANGELOG updates to Github`); - } - - utils.log('Version updates to apply:'); - _.each(packageToVersionChange, (versionChange: string, packageName: string) => { - utils.log(`${packageName} -> ${versionChange}`); - }); - utils.log(`Calling 'lerna publish'...`); - await lernaPublishAsync(packageToVersionChange); -})().catch(err => { - utils.log(err); - process.exit(1); -}); + return packageToVersionChange; +} async function lernaPublishAsync(packageToVersionChange: { [name: string]: string }) { // HACK: Lerna publish does not provide a way to specify multiple package versions via diff --git a/packages/monorepo-scripts/src/types.ts b/packages/monorepo-scripts/src/types.ts index 9e6edd186..28d00d710 100644 --- a/packages/monorepo-scripts/src/types.ts +++ b/packages/monorepo-scripts/src/types.ts @@ -21,3 +21,7 @@ export enum SemVerIndex { Minor, Major, } + +export interface PackageToVersionChange { + [name: string]: string; +} -- cgit v1.2.3 From efdbc1ff6cc3b50a6ccd36ebb185d7f09056c2a8 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 10 Apr 2018 14:49:13 +0900 Subject: Add step to publishing that upload staging doc jsons, deploys staging website, opens every docs page and asks the dev to confirm that each one renders properly before publishing --- packages/monorepo-scripts/src/constants.ts | 1 + packages/monorepo-scripts/src/globals.d.ts | 6 ++++ packages/monorepo-scripts/src/publish.ts | 58 ++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/constants.ts b/packages/monorepo-scripts/src/constants.ts index 74387a159..081a49332 100644 --- a/packages/monorepo-scripts/src/constants.ts +++ b/packages/monorepo-scripts/src/constants.ts @@ -2,4 +2,5 @@ import * as path from 'path'; export const constants = { monorepoRootPath: path.join(__dirname, '../../..'), + stagingWebsite: 'http://staging-0xproject.s3-website-us-east-1.amazonaws.com', }; diff --git a/packages/monorepo-scripts/src/globals.d.ts b/packages/monorepo-scripts/src/globals.d.ts index c5898d0f5..1693a6dbb 100644 --- a/packages/monorepo-scripts/src/globals.d.ts +++ b/packages/monorepo-scripts/src/globals.d.ts @@ -3,6 +3,11 @@ declare module 'publish-release'; declare module 'es6-promisify'; declare module 'semver-diff'; +declare module 'prompt' { + const start: () => void; + const get: (promptMessages: string[], callback: (err: Error, result: string) => void) => void; +} + // semver-sort declarations declare module 'semver-sort' { const desc: (versions: string[]) => string[]; @@ -15,6 +20,7 @@ declare interface LernaPackage { version: string; name: string; main?: string; + scripts?: { [command: string]: string }; config?: { additionalTsTypings?: string[]; }; diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index f0fb00acd..ebc30def4 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -1,11 +1,14 @@ #!/usr/bin/env node +import * as promisify from 'es6-promisify'; import * as fs from 'fs'; import lernaGetPackages = require('lerna-get-packages'); import * as _ from 'lodash'; import * as moment from 'moment'; +import opn = require('opn'); import * as path from 'path'; import { exec as execAsync, spawn } from 'promisify-child-process'; +import * as prompt from 'prompt'; import semverDiff = require('semver-diff'); import semverSort = require('semver-sort'); @@ -13,6 +16,8 @@ import { constants } from './constants'; import { Changelog, Changes, PackageToVersionChange, SemVerIndex, UpdatedPackage } from './types'; import { utils } from './utils'; +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 LERNA_EXECUTABLE = './node_modules/lerna/bin/lerna.js'; @@ -21,11 +26,23 @@ const semverNameToIndex: { [semver: string]: number } = { minor: SemVerIndex.Minor, major: SemVerIndex.Major, }; +const packageNameToWebsitePath: { [name: string]: string } = { + '0x.js': '0xjs', + 'web3-wrapper': 'web3_wrapper', + contracts: 'contracts', + connect: 'connect', + 'json-schemas': 'json-schemas', + deployer: 'deployer', + 'sol-cov': 'sol-cov', + subproviders: 'subproviders', +}; (async () => { // Fetch public, updated Lerna packages const updatedPublicLernaPackages = await getUpdatedPublicLernaPackagesAsync(); + await confirmDocPagesRenderAsync(updatedPublicLernaPackages); + // Update CHANGELOGs const updatedPublicLernaPackageNames = _.map(updatedPublicLernaPackages, pkg => pkg.package.name); utils.log(`Will update CHANGELOGs and publish: \n${updatedPublicLernaPackageNames.join('\n')}\n`); @@ -48,6 +65,47 @@ const semverNameToIndex: { [semver: string]: number } = { process.exit(1); }); +async function confirmDocPagesRenderAsync(packages: LernaPackage[]) { + // push docs to staging + utils.log("Upload all docJson's to S3 staging..."); + await execAsync(`yarn lerna:stage_docs`, { cwd: constants.monorepoRootPath }); + + // deploy website to staging + utils.log('Deploy website to staging...'); + const pathToWebsite = `${constants.monorepoRootPath}/packages/website`; + await execAsync(`yarn deploy_staging`, { cwd: pathToWebsite }); + + const packagesWithDocs = _.filter(packages, pkg => { + const scriptsIfExists = pkg.package.scripts; + if (_.isUndefined(scriptsIfExists)) { + throw new Error('Found a public package without any scripts in package.json'); + } + return !_.isUndefined(scriptsIfExists[DOC_GEN_COMMAND]); + }); + _.each(packagesWithDocs, pkg => { + const name = pkg.package.name; + const nameWithoutPrefix = _.startsWith(name, NPM_NAMESPACE) ? name.split('@0xproject/')[1] : name; + const docSegmentIfExists = packageNameToWebsitePath[nameWithoutPrefix]; + if (_.isUndefined(docSegmentIfExists)) { + throw new Error( + `Found package '${name}' with doc commands but no corresponding docSegment in monorepo_scripts +package.ts. Please add an entry for it and try again.`, + ); + } + const link = `${constants.stagingWebsite}/docs/${docSegmentIfExists}`; + opn(link); + }); + + prompt.start(); + const message = 'Do all the doc pages render properly? (yn)'; + const result = await promisify(prompt.get)([message]); + const didConfirm = result[message] === 'y'; + if (!didConfirm) { + utils.log('Publish process aborted.'); + process.exit(0); + } +} + async function pushChangelogsToGithubAsync() { await execAsync(`git add . --all`, { cwd: constants.monorepoRootPath }); await execAsync(`git commit -m "Updated CHANGELOGS"`, { cwd: constants.monorepoRootPath }); -- cgit v1.2.3 From 2fe209d5ff2f2e81b3c1d83ac870c0cac9acdef8 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 11 Apr 2018 18:55:42 +0900 Subject: Fix lint error --- packages/monorepo-scripts/src/publish.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index ebc30def4..21c8b72c9 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -93,6 +93,7 @@ package.ts. Please add an entry for it and try again.`, ); } const link = `${constants.stagingWebsite}/docs/${docSegmentIfExists}`; + // tslint:disable-next-line:no-floating-promises opn(link); }); -- cgit v1.2.3 From 72aa3d3005c81c1d0deb66369ce543bda3cccdc1 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 4 Apr 2018 13:29:38 +0300 Subject: Fix some of the publishing/installation issues --- packages/monorepo-scripts/src/test_installation.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 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 195b64b2a..78e0f0929 100644 --- a/packages/monorepo-scripts/src/test_installation.ts +++ b/packages/monorepo-scripts/src/test_installation.ts @@ -31,7 +31,7 @@ import { utils } from './utils'; utils.log(`Installing ${packedPackageFileName}`); result = await execAsync(`yarn add ${packagePath}/${packedPackageFileName}`, { cwd: testDirectory }); const indexFilePath = path.join(testDirectory, 'index.ts'); - fs.writeFileSync(indexFilePath, `import * as Package from '${packageName}'`); + fs.writeFileSync(indexFilePath, `import * as Package from '${packageName}';\n`); const tsConfig = { compilerOptions: { typeRoots: ['node_modules/@0xproject/typescript-typings/types', 'node_modules/@types'], @@ -48,11 +48,13 @@ import { utils } from './utils'; const tsconfigFilePath = path.join(testDirectory, 'tsconfig.json'); fs.writeFileSync(tsconfigFilePath, JSON.stringify(tsConfig, null, 4)); utils.log(`Compiling ${packageName}`); - await execAsync('../node_modules/typescript/bin/tsc', { cwd: testDirectory }); + const tscBinaryPath = path.join(monorepoRootPath, './node_modules/typescript/bin/tsc'); + await execAsync(tscBinaryPath, { cwd: testDirectory }); utils.log(`Successfully compiled with ${packageName} as a dependency`); rimraf.sync(testDirectory); } })().catch(err => { + utils.log(err.stderr); utils.log(err.stdout); process.exit(1); }); -- cgit v1.2.3 From 4d485fc42432709d816c161d346bdc62a5a9ecf8 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 18 Apr 2018 20:03:50 +0900 Subject: Print out stderr --- packages/monorepo-scripts/src/publish.ts | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 21c8b72c9..a2d641ff9 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -219,6 +219,10 @@ async function lernaPublishAsync(packageToVersionChange: { [name: string]: strin ); } }); + child.stderr.on('data', (data: Buffer) => { + const output = data.toString('utf8'); + utils.log('Stderr:', output); + }); } async function getPublicLernaUpdatedPackagesAsync(): Promise { -- cgit v1.2.3 From 7dd3b2d38b4e4ee2f1daa24c90f503b2e7ad0422 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 19 Apr 2018 11:40:22 +0900 Subject: Add removeGitTags script that can be run after a failed Lerna publish --- packages/monorepo-scripts/src/constants.ts | 1 + packages/monorepo-scripts/src/remove_tags.ts | 56 ++++++++++++++++++++++++++++ packages/monorepo-scripts/src/utils.ts | 45 ++++++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 packages/monorepo-scripts/src/remove_tags.ts (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/constants.ts b/packages/monorepo-scripts/src/constants.ts index 081a49332..e93b27820 100644 --- a/packages/monorepo-scripts/src/constants.ts +++ b/packages/monorepo-scripts/src/constants.ts @@ -3,4 +3,5 @@ import * as path from 'path'; export const constants = { monorepoRootPath: path.join(__dirname, '../../..'), stagingWebsite: 'http://staging-0xproject.s3-website-us-east-1.amazonaws.com', + lernaExecutable: './node_modules/lerna/bin/lerna.js', }; diff --git a/packages/monorepo-scripts/src/remove_tags.ts b/packages/monorepo-scripts/src/remove_tags.ts new file mode 100644 index 000000000..a91c6ec39 --- /dev/null +++ b/packages/monorepo-scripts/src/remove_tags.ts @@ -0,0 +1,56 @@ +#!/usr/bin/env node + +import lernaGetPackages = require('lerna-get-packages'); +import * as _ from 'lodash'; +import * as path from 'path'; +import { exec as execAsync } from 'promisify-child-process'; +import semverSort = require('semver-sort'); + +import { constants } from './constants'; +import { Changelog } from './types'; +import { utils } from './utils'; + +(async () => { + const shouldIncludePrivate = true; + const updatedPublicLernaPackages = await utils.getUpdatedLernaPackagesAsync(shouldIncludePrivate); + + for (const lernaPackage of updatedPublicLernaPackages) { + const packageName = lernaPackage.package.name; + const currentVersion = lernaPackage.package.version; + const changelogJSONPath = path.join(lernaPackage.location, 'CHANGELOG.json'); + const changelogJSONIfExists = utils.getChangelogJSONIfExists(changelogJSONPath); + + let latestChangelogVersion: string; + if (!_.isUndefined(changelogJSONIfExists)) { + let changelogs: Changelog[]; + try { + changelogs = JSON.parse(changelogJSONIfExists); + } catch (err) { + throw new Error( + `${lernaPackage.package.name}'s CHANGELOG.json contains invalid JSON. Please fix and try again.`, + ); + } + latestChangelogVersion = changelogs[0].version; + } else { + latestChangelogVersion = utils.getNextPatchVersion(currentVersion); + } + + const sortedVersions = semverSort.desc([latestChangelogVersion, currentVersion]); + if (sortedVersions[0] === latestChangelogVersion && latestChangelogVersion !== currentVersion) { + const tagName = `${packageName}@${latestChangelogVersion}`; + try { + await execAsync(`git tag -d ${tagName}`, { cwd: constants.monorepoRootPath }); + utils.log(`removed tag: ${tagName}`); + } catch (err) { + if (_.includes(err.message, 'not found')) { + utils.log(`Could not find tag: ${tagName}`); + } else { + throw err; + } + } + } + } +})().catch(err => { + utils.log(err); + process.exit(1); +}); diff --git a/packages/monorepo-scripts/src/utils.ts b/packages/monorepo-scripts/src/utils.ts index 9aa37e272..3a16bf91d 100644 --- a/packages/monorepo-scripts/src/utils.ts +++ b/packages/monorepo-scripts/src/utils.ts @@ -1,6 +1,11 @@ +import * as fs from 'fs'; +import lernaGetPackages = require('lerna-get-packages'); import * as _ from 'lodash'; import { exec as execAsync, spawn } from 'promisify-child-process'; +import { constants } from './constants'; +import { UpdatedPackage } from './types'; + export const utils = { log(...args: any[]): void { console.log(...args); // tslint:disable-line:no-console @@ -17,4 +22,44 @@ export const utils = { cwd, }); }, + async getUpdatedLernaPackagesAsync(shouldIncludePrivate: boolean): Promise { + const updatedPublicPackages = await this.getLernaUpdatedPackagesAsync(shouldIncludePrivate); + const updatedPackageNames = _.map(updatedPublicPackages, pkg => pkg.name); + + const allLernaPackages = lernaGetPackages(constants.monorepoRootPath); + const updatedPublicLernaPackages = _.filter(allLernaPackages, pkg => { + return _.includes(updatedPackageNames, pkg.package.name); + }); + return updatedPublicLernaPackages; + }, + async getLernaUpdatedPackagesAsync(shouldIncludePrivate: boolean): Promise { + const result = await execAsync(`${constants.lernaExecutable} updated --json`, { + cwd: constants.monorepoRootPath, + }); + const updatedPackages = JSON.parse(result.stdout); + if (!shouldIncludePrivate) { + const updatedPublicPackages = _.filter(updatedPackages, updatedPackage => !updatedPackage.private); + return updatedPublicPackages; + } + return updatedPackages; + }, + getChangelogJSONIfExists(changelogPath: string) { + let changelogJSON: string; + try { + changelogJSON = fs.readFileSync(changelogPath, 'utf-8'); + return changelogJSON; + } catch (err) { + return undefined; + } + }, + getChangelogJSONOrCreateIfMissing(changelogPath: string): string { + const changelogIfExists = this.getChangelogJSONIfExists(changelogPath); + if (_.isUndefined(changelogIfExists)) { + // If none exists, create new, empty one. + const emptyChangelogJSON = JSON.stringify([], null, 4); + fs.writeFileSync(changelogPath, emptyChangelogJSON); + return emptyChangelogJSON; + } + return changelogIfExists; + }, }; -- cgit v1.2.3 From fc2b7f747bf15b8c9329f2940ed2f6cf71353c33 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 19 Apr 2018 14:10:48 +0900 Subject: Add checks for the required local setup before running the publish script --- packages/monorepo-scripts/src/publish.ts | 50 ++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index a2d641ff9..9bd9ff6be 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -38,6 +38,11 @@ const packageNameToWebsitePath: { [name: string]: string } = { }; (async () => { + const hasRequiredSetup = await checkPublishRequiredSetupAsync(); + if (!hasRequiredSetup) { + return; // abort + } + // Fetch public, updated Lerna packages const updatedPublicLernaPackages = await getUpdatedPublicLernaPackagesAsync(); @@ -107,6 +112,51 @@ package.ts. Please add an entry for it and try again.`, } } +async function checkPublishRequiredSetupAsync(): Promise { + // check to see if logged into npm before publishing (npm whoami) + try { + 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 creds setup (check for ENV 'GITHUB_PERSONAL_ACCESS_TOKEN_0X_JS') + if (_.isUndefined(process.env.GITHUB_PERSONAL_ACCESS_TOKEN_0X_JS)) { + 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 NPM version is 5.X + const result = await execAsync(`npm --version`); + const version = result.stdout; + const versionSegments = version.split('.'); + const majorVersion = _.parseInt(versionSegments[0]); + if (majorVersion < 5) { + utils.log('You npm version must be v5.x or higher. Upgrade your npm and try again.'); + return false; + } + + // Check that `aws` commandline 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` creds 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() { await execAsync(`git add . --all`, { cwd: constants.monorepoRootPath }); await execAsync(`git commit -m "Updated CHANGELOGS"`, { cwd: constants.monorepoRootPath }); -- cgit v1.2.3 From 858d1768cecf165adefcdf860f247dad258d8cae Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 19 Apr 2018 14:14:10 +0900 Subject: Improve comments --- packages/monorepo-scripts/src/publish.ts | 9 +++++---- 1 file changed, 5 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 9bd9ff6be..827d6165e 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -113,7 +113,7 @@ package.ts. Please add an entry for it and try again.`, } async function checkPublishRequiredSetupAsync(): Promise { - // check to see if logged into npm before publishing (npm whoami) + // check to see if logged into npm before publishing try { await execAsync(`sudo npm whoami`); } catch (err) { @@ -121,13 +121,14 @@ async function checkPublishRequiredSetupAsync(): Promise { return false; } - // Check to see if Git creds setup (check for ENV 'GITHUB_PERSONAL_ACCESS_TOKEN_0X_JS') + // Check to see if Git personal token setup if (_.isUndefined(process.env.GITHUB_PERSONAL_ACCESS_TOKEN_0X_JS)) { 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 NPM version is 5.X const result = await execAsync(`npm --version`); const version = result.stdout; @@ -138,7 +139,7 @@ async function checkPublishRequiredSetupAsync(): Promise { return false; } - // Check that `aws` commandline is installed + // Check that `aws` commandline tool is installed try { await execAsync(`aws help`); } catch (err) { @@ -146,7 +147,7 @@ async function checkPublishRequiredSetupAsync(): Promise { return false; } - // Check that `aws` creds are setup + // Check that `aws` credentials are setup try { await execAsync(`aws sts get-caller-identity`); } catch (err) { -- cgit v1.2.3 From 60d879e04537f2af4d7476d384fd0e2002a0fbd3 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 19 Apr 2018 14:16:11 +0900 Subject: Add comment --- packages/monorepo-scripts/src/remove_tags.ts | 2 ++ 1 file changed, 2 insertions(+) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/remove_tags.ts b/packages/monorepo-scripts/src/remove_tags.ts index a91c6ec39..6d09729c7 100644 --- a/packages/monorepo-scripts/src/remove_tags.ts +++ b/packages/monorepo-scripts/src/remove_tags.ts @@ -18,6 +18,8 @@ import { utils } from './utils'; const packageName = lernaPackage.package.name; const currentVersion = lernaPackage.package.version; const changelogJSONPath = path.join(lernaPackage.location, 'CHANGELOG.json'); + // Private packages don't have changelogs, and their versions are always incremented + // by a patch version. const changelogJSONIfExists = utils.getChangelogJSONIfExists(changelogJSONPath); let latestChangelogVersion: string; -- cgit v1.2.3 From 2b15c03b9ac516f7e38eef174503096026162b90 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 19 Apr 2018 14:19:34 +0900 Subject: Use methods moved to utils since now shared by multiple scripts --- packages/monorepo-scripts/src/publish.ts | 36 +++----------------------------- 1 file changed, 3 insertions(+), 33 deletions(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 827d6165e..2ae9bbb60 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -44,7 +44,8 @@ const packageNameToWebsitePath: { [name: string]: string } = { } // Fetch public, updated Lerna packages - const updatedPublicLernaPackages = await getUpdatedPublicLernaPackagesAsync(); + const shouldIncludePrivate = false; + const updatedPublicLernaPackages = await utils.getUpdatedLernaPackagesAsync(shouldIncludePrivate); await confirmDocPagesRenderAsync(updatedPublicLernaPackages); @@ -165,23 +166,12 @@ async function pushChangelogsToGithubAsync() { utils.log(`Pushed CHANGELOG updates to Github`); } -async function getUpdatedPublicLernaPackagesAsync(): Promise { - const updatedPublicPackages = await getPublicLernaUpdatedPackagesAsync(); - const updatedPackageNames = _.map(updatedPublicPackages, pkg => pkg.name); - - const allLernaPackages = lernaGetPackages(constants.monorepoRootPath); - const updatedPublicLernaPackages = _.filter(allLernaPackages, pkg => { - return _.includes(updatedPackageNames, pkg.package.name); - }); - return updatedPublicLernaPackages; -} - async function updateChangeLogsAsync(updatedPublicLernaPackages: LernaPackage[]): Promise { const packageToVersionChange: PackageToVersionChange = {}; for (const lernaPackage of updatedPublicLernaPackages) { const packageName = lernaPackage.package.name; const changelogJSONPath = path.join(lernaPackage.location, 'CHANGELOG.json'); - const changelogJSON = getChangelogJSONOrCreateIfMissing(lernaPackage.package.name, changelogJSONPath); + const changelogJSON = utils.getChangelogJSONOrCreateIfMissing(changelogJSONPath); let changelogs: Changelog[]; try { changelogs = JSON.parse(changelogJSON); @@ -276,13 +266,6 @@ async function lernaPublishAsync(packageToVersionChange: { [name: string]: strin }); } -async function getPublicLernaUpdatedPackagesAsync(): Promise { - const result = await execAsync(`${LERNA_EXECUTABLE} updated --json`, { cwd: constants.monorepoRootPath }); - const updatedPackages = JSON.parse(result.stdout); - const updatedPublicPackages = _.filter(updatedPackages, updatedPackage => !updatedPackage.private); - return updatedPublicPackages; -} - function updateVersionNumberIfNeeded(currentVersion: string, proposedNextVersion: string) { if (proposedNextVersion === currentVersion) { return utils.getNextPatchVersion(currentVersion); @@ -294,19 +277,6 @@ function updateVersionNumberIfNeeded(currentVersion: string, proposedNextVersion return proposedNextVersion; } -function getChangelogJSONOrCreateIfMissing(packageName: string, changelogPath: string): string { - let changelogJSON: string; - try { - changelogJSON = fs.readFileSync(changelogPath, 'utf-8'); - return changelogJSON; - } catch (err) { - // If none exists, create new, empty one. - const emptyChangelogJSON = JSON.stringify([], null, 4); - fs.writeFileSync(changelogPath, emptyChangelogJSON); - return emptyChangelogJSON; - } -} - function shouldAddNewChangelogEntry(currentVersion: string, changelogs: Changelog[]): boolean { if (_.isEmpty(changelogs)) { return true; -- cgit v1.2.3 From 417cec9e04af84935c38ed77cdb53a8026b0004e Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 20 Apr 2018 09:36:03 +0900 Subject: Consolidate github personal access token env to one place: constants.ts --- packages/monorepo-scripts/src/constants.ts | 1 + packages/monorepo-scripts/src/postpublish_utils.ts | 3 +-- packages/monorepo-scripts/src/publish.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/constants.ts b/packages/monorepo-scripts/src/constants.ts index e93b27820..154a86069 100644 --- a/packages/monorepo-scripts/src/constants.ts +++ b/packages/monorepo-scripts/src/constants.ts @@ -4,4 +4,5 @@ export const constants = { monorepoRootPath: path.join(__dirname, '../../..'), stagingWebsite: 'http://staging-0xproject.s3-website-us-east-1.amazonaws.com', lernaExecutable: './node_modules/lerna/bin/lerna.js', + githubPersonalAccessToken: process.env.GITHUB_PERSONAL_ACCESS_TOKEN_0X_JS, }; diff --git a/packages/monorepo-scripts/src/postpublish_utils.ts b/packages/monorepo-scripts/src/postpublish_utils.ts index ca4c92f5d..df2bcb128 100644 --- a/packages/monorepo-scripts/src/postpublish_utils.ts +++ b/packages/monorepo-scripts/src/postpublish_utils.ts @@ -10,7 +10,6 @@ import { constants } from './constants'; import { utils } from './utils'; const publishReleaseAsync = promisify(publishRelease); -const githubPersonalAccessToken = process.env.GITHUB_PERSONAL_ACCESS_TOKEN_0X_JS; const generatedDocsDirectoryName = 'generated_docs'; export interface PostpublishConfigs { @@ -97,7 +96,7 @@ export const postpublishUtils = { const finalAssets = this.adjustAssetPaths(cwd, assets); utils.log('POSTPUBLISH: Releasing ', releaseName, '...'); const result = await publishReleaseAsync({ - token: githubPersonalAccessToken, + token: constants.githubPersonalAccessToken, owner: '0xProject', repo: '0x-monorepo', tag, diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 2ae9bbb60..6c728467a 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -123,7 +123,7 @@ async function checkPublishRequiredSetupAsync(): Promise { } // Check to see if Git personal token setup - if (_.isUndefined(process.env.GITHUB_PERSONAL_ACCESS_TOKEN_0X_JS)) { + 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.', ); -- cgit v1.2.3 From 7f46e9af2cef99667da798205bd0dd6fa590f897 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 20 Apr 2018 10:00:37 +0900 Subject: Use path for platform independence --- 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 154a86069..3aaf881cb 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: './node_modules/lerna/bin/lerna.js', + lernaExecutable: path.join('node_modules', 'lerna', 'bin', 'lerna.js'), githubPersonalAccessToken: process.env.GITHUB_PERSONAL_ACCESS_TOKEN_0X_JS, }; -- cgit v1.2.3 From b6fb8dbb528a28cfc3d9395262fa39e3eecca2d5 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 20 Apr 2018 10:03:53 +0900 Subject: Remove outside declaration --- packages/monorepo-scripts/src/utils.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/utils.ts b/packages/monorepo-scripts/src/utils.ts index 3a16bf91d..b1bb78ab2 100644 --- a/packages/monorepo-scripts/src/utils.ts +++ b/packages/monorepo-scripts/src/utils.ts @@ -44,9 +44,8 @@ export const utils = { return updatedPackages; }, getChangelogJSONIfExists(changelogPath: string) { - let changelogJSON: string; try { - changelogJSON = fs.readFileSync(changelogPath, 'utf-8'); + const changelogJSON = fs.readFileSync(changelogPath, 'utf-8'); return changelogJSON; } catch (err) { return undefined; -- cgit v1.2.3 From 1f82c7eadfe9e9cddb56b40562a2f0f69cc7dfd9 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 20 Apr 2018 10:04:22 +0900 Subject: Remove unnecessary additional params --- packages/monorepo-scripts/src/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/utils.ts b/packages/monorepo-scripts/src/utils.ts index b1bb78ab2..4412f753a 100644 --- a/packages/monorepo-scripts/src/utils.ts +++ b/packages/monorepo-scripts/src/utils.ts @@ -55,7 +55,7 @@ export const utils = { const changelogIfExists = this.getChangelogJSONIfExists(changelogPath); if (_.isUndefined(changelogIfExists)) { // If none exists, create new, empty one. - const emptyChangelogJSON = JSON.stringify([], null, 4); + const emptyChangelogJSON = JSON.stringify([]); fs.writeFileSync(changelogPath, emptyChangelogJSON); return emptyChangelogJSON; } -- cgit v1.2.3 From a3cc5c1dd7e88aea50859560f7d751435cb577bd Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 24 Apr 2018 10:32:44 +0900 Subject: Add hack comment about the use of sudo --- packages/monorepo-scripts/src/publish.ts | 2 ++ 1 file changed, 2 insertions(+) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 6c728467a..0ca3ea7a1 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -116,6 +116,8 @@ package.ts. Please add an entry for it and try again.`, async function checkPublishRequiredSetupAsync(): Promise { // 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 N 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.'); -- cgit v1.2.3 From ffd9b791003f4718a0dcc469e9806450c73200aa Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 24 Apr 2018 10:43:44 +0900 Subject: Check for Yarn instead of npm --- packages/monorepo-scripts/src/publish.ts | 8 ++++---- 1 file changed, 4 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 0ca3ea7a1..bc580c87f 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -132,13 +132,13 @@ async function checkPublishRequiredSetupAsync(): Promise { return false; } - // Check NPM version is 5.X - const result = await execAsync(`npm --version`); + // 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 < 5) { - utils.log('You npm version must be v5.x or higher. Upgrade your npm and try again.'); + if (majorVersion < 1) { + utils.log('Your yarn version must be v1.x or higher. Upgrade yarn and try again.'); return false; } -- cgit v1.2.3 From 28ee9e247e7549dccf8c51d8923c0fb3c625bd09 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 2 May 2018 20:00:06 +0300 Subject: Add order-utils to monorepo-scripts --- packages/monorepo-scripts/src/publish.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index bc580c87f..e37e1d232 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -35,6 +35,7 @@ const packageNameToWebsitePath: { [name: string]: string } = { deployer: 'deployer', 'sol-cov': 'sol-cov', subproviders: 'subproviders', + 'order-utils': 'order-utils', }; (async () => { -- cgit v1.2.3 From a6f72de09d7b2c9738b78d2097baa9906838fbe9 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 8 May 2018 15:42:07 +0200 Subject: Rename deployer to sol-compiler --- packages/monorepo-scripts/src/find_unused_dependencies.ts | 2 +- packages/monorepo-scripts/src/publish.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/find_unused_dependencies.ts b/packages/monorepo-scripts/src/find_unused_dependencies.ts index bfc38044c..df303f6ce 100644 --- a/packages/monorepo-scripts/src/find_unused_dependencies.ts +++ b/packages/monorepo-scripts/src/find_unused_dependencies.ts @@ -10,7 +10,7 @@ import { constants } from './constants'; import { utils } from './utils'; // For some reason, `depcheck` hangs on some packages. Add them here. -const IGNORE_PACKAGES = ['@0xproject/deployer']; +const IGNORE_PACKAGES = ['@0xproject/sol-compiler']; (async () => { utils.log('*** NOTE: Not all deps listed here are actually not required. ***'); diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index e37e1d232..2011dc393 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -32,7 +32,7 @@ const packageNameToWebsitePath: { [name: string]: string } = { contracts: 'contracts', connect: 'connect', 'json-schemas': 'json-schemas', - deployer: 'deployer', + 'sol-compiler': 'sol-compiler', 'sol-cov': 'sol-cov', subproviders: 'subproviders', 'order-utils': 'order-utils', -- cgit v1.2.3 From f854f3ee2bd74bbb61ed465099168b4d391f92c8 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 10 May 2018 15:20:00 +0200 Subject: Remove unused deployer docs configs --- packages/monorepo-scripts/src/publish.ts | 2 +- packages/monorepo-scripts/src/test_installation.ts | 2 +- 2 files changed, 2 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 2011dc393..a5be40014 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -214,7 +214,7 @@ async function updateChangeLogsAsync(updatedPublicLernaPackages: LernaPackage[]) } // Save updated CHANGELOG.json - fs.writeFileSync(changelogJSONPath, JSON.stringify(changelogs, null, 4)); + fs.writeFileSync(changelogJSONPath, JSON.stringify(changelogs, null, '\t')); await utils.prettifyAsync(changelogJSONPath, constants.monorepoRootPath); utils.log(`${packageName}: Updated CHANGELOG.json`); // Generate updated CHANGELOG.md diff --git a/packages/monorepo-scripts/src/test_installation.ts b/packages/monorepo-scripts/src/test_installation.ts index 78e0f0929..e84221f9d 100644 --- a/packages/monorepo-scripts/src/test_installation.ts +++ b/packages/monorepo-scripts/src/test_installation.ts @@ -46,7 +46,7 @@ import { utils } from './utils'; include: ['index.ts'], }; const tsconfigFilePath = path.join(testDirectory, 'tsconfig.json'); - fs.writeFileSync(tsconfigFilePath, JSON.stringify(tsConfig, null, 4)); + fs.writeFileSync(tsconfigFilePath, JSON.stringify(tsConfig, null, '\t')); utils.log(`Compiling ${packageName}`); const tscBinaryPath = path.join(monorepoRootPath, './node_modules/typescript/bin/tsc'); await execAsync(tscBinaryPath, { cwd: testDirectory }); -- cgit v1.2.3 From 478f6ed011185b66ac87323c6d9ad1f598060760 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 14 May 2018 19:23:50 +0200 Subject: Move from using lerna multi-package commands to wsrun, update README's accordingly --- 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 a5be40014..31c85e3cc 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -75,7 +75,7 @@ const packageNameToWebsitePath: { [name: string]: string } = { async function confirmDocPagesRenderAsync(packages: LernaPackage[]) { // push docs to staging utils.log("Upload all docJson's to S3 staging..."); - await execAsync(`yarn lerna:stage_docs`, { cwd: constants.monorepoRootPath }); + await execAsync(`yarn stage_docs`, { cwd: constants.monorepoRootPath }); // deploy website to staging utils.log('Deploy website to staging...'); -- cgit v1.2.3 From d0905eda496864096f5a64b1e2c1c05b575be904 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 14 May 2018 21:48:46 +0200 Subject: Fix TSLint issues --- packages/monorepo-scripts/src/postpublish_utils.ts | 10 +++++----- packages/monorepo-scripts/src/publish.ts | 8 ++++---- packages/monorepo-scripts/src/utils.ts | 4 ++-- 3 files changed, 11 insertions(+), 11 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 df2bcb128..5fbff938e 100644 --- a/packages/monorepo-scripts/src/postpublish_utils.ts +++ b/packages/monorepo-scripts/src/postpublish_utils.ts @@ -74,7 +74,7 @@ export const postpublishUtils = { utils.log(`POSTPUBLISH: No S3Bucket config found for ${packageJSON.name}. Skipping doc JSON generation.`); } }, - async publishDocsToStagingAsync(packageJSON: any, tsConfigJSON: any, cwd: string) { + async publishDocsToStagingAsync(packageJSON: any, tsConfigJSON: any, cwd: string): Promise { const configs = this.generateConfig(packageJSON, tsConfigJSON, cwd); if (_.isUndefined(configs.docPublishConfigs.s3StagingBucketPath)) { utils.log('config.postpublish.docPublishConfigs.s3StagingBucketPath entry in package.json not found!'); @@ -109,7 +109,7 @@ export const postpublishUtils = { assets, }); }, - getReleaseNotes(packageName: string, version: string) { + getReleaseNotes(packageName: string, version: string): string { const packageNameWithNamespace = packageName.replace('@0xproject/', ''); const changelogJSONPath = path.join( constants.monorepoRootPath, @@ -135,14 +135,14 @@ export const postpublishUtils = { }); return notes; }, - getTag(packageName: string, version: string) { + getTag(packageName: string, version: string): string { return `${packageName}@${version}`; }, getReleaseName(subPackageName: string, version: string): string { const releaseName = `${subPackageName} v${version}`; return releaseName; }, - adjustAssetPaths(cwd: string, assets: string[]) { + adjustAssetPaths(cwd: string, assets: string[]): string[] { const finalAssets: string[] = []; _.each(assets, (asset: string) => { finalAssets.push(`${cwd}/${asset}`); @@ -164,7 +164,7 @@ export const postpublishUtils = { }); return fileIncludesAdjusted; }, - async generateAndUploadDocsAsync(cwd: string, fileIncludes: string[], version: string, S3BucketPath: string) { + async generateAndUploadDocsAsync(cwd: string, fileIncludes: string[], version: string, S3BucketPath: string): Promise { const fileIncludesAdjusted = this.adjustFileIncludePaths(fileIncludes, cwd); const projectFiles = fileIncludesAdjusted.join(' '); const jsonFilePath = `${cwd}/${generatedDocsDirectoryName}/index.json`; diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 31c85e3cc..5c26475c9 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -72,7 +72,7 @@ const packageNameToWebsitePath: { [name: string]: string } = { process.exit(1); }); -async function confirmDocPagesRenderAsync(packages: LernaPackage[]) { +async function confirmDocPagesRenderAsync(packages: LernaPackage[]): Promise { // push docs to staging utils.log("Upload all docJson's to S3 staging..."); await execAsync(`yarn stage_docs`, { cwd: constants.monorepoRootPath }); @@ -162,7 +162,7 @@ async function checkPublishRequiredSetupAsync(): Promise { return true; } -async function pushChangelogsToGithubAsync() { +async function pushChangelogsToGithubAsync(): Promise { await execAsync(`git add . --all`, { cwd: constants.monorepoRootPath }); await execAsync(`git commit -m "Updated CHANGELOGS"`, { cwd: constants.monorepoRootPath }); await execAsync(`git push`, { cwd: constants.monorepoRootPath }); @@ -228,7 +228,7 @@ async function updateChangeLogsAsync(updatedPublicLernaPackages: LernaPackage[]) return packageToVersionChange; } -async function lernaPublishAsync(packageToVersionChange: { [name: string]: string }) { +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', '--registry=https://registry.npmjs.org/'], { @@ -269,7 +269,7 @@ async function lernaPublishAsync(packageToVersionChange: { [name: string]: strin }); } -function updateVersionNumberIfNeeded(currentVersion: string, proposedNextVersion: string) { +function updateVersionNumberIfNeeded(currentVersion: string, proposedNextVersion: string): string { if (proposedNextVersion === currentVersion) { return utils.getNextPatchVersion(currentVersion); } diff --git a/packages/monorepo-scripts/src/utils.ts b/packages/monorepo-scripts/src/utils.ts index 4412f753a..480788ad8 100644 --- a/packages/monorepo-scripts/src/utils.ts +++ b/packages/monorepo-scripts/src/utils.ts @@ -17,7 +17,7 @@ export const utils = { const newPatchVersion = `${versionSegments[0]}.${versionSegments[1]}.${newPatch}`; return newPatchVersion; }, - async prettifyAsync(filePath: string, cwd: string) { + async prettifyAsync(filePath: string, cwd: string): Promise { await execAsync(`prettier --write ${filePath} --config .prettierrc`, { cwd, }); @@ -43,7 +43,7 @@ export const utils = { } return updatedPackages; }, - getChangelogJSONIfExists(changelogPath: string) { + getChangelogJSONIfExists(changelogPath: string): string|undefined { try { const changelogJSON = fs.readFileSync(changelogPath, 'utf-8'); return changelogJSON; -- cgit v1.2.3 From 5422bf57332f69d7b45e884c19a9f20d60bdec5b Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 14 May 2018 21:48:46 +0200 Subject: Fix TSLint issues --- packages/monorepo-scripts/src/postpublish_utils.ts | 10 +++++----- packages/monorepo-scripts/src/publish.ts | 8 ++++---- packages/monorepo-scripts/src/utils.ts | 4 ++-- 3 files changed, 11 insertions(+), 11 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 df2bcb128..5fbff938e 100644 --- a/packages/monorepo-scripts/src/postpublish_utils.ts +++ b/packages/monorepo-scripts/src/postpublish_utils.ts @@ -74,7 +74,7 @@ export const postpublishUtils = { utils.log(`POSTPUBLISH: No S3Bucket config found for ${packageJSON.name}. Skipping doc JSON generation.`); } }, - async publishDocsToStagingAsync(packageJSON: any, tsConfigJSON: any, cwd: string) { + async publishDocsToStagingAsync(packageJSON: any, tsConfigJSON: any, cwd: string): Promise { const configs = this.generateConfig(packageJSON, tsConfigJSON, cwd); if (_.isUndefined(configs.docPublishConfigs.s3StagingBucketPath)) { utils.log('config.postpublish.docPublishConfigs.s3StagingBucketPath entry in package.json not found!'); @@ -109,7 +109,7 @@ export const postpublishUtils = { assets, }); }, - getReleaseNotes(packageName: string, version: string) { + getReleaseNotes(packageName: string, version: string): string { const packageNameWithNamespace = packageName.replace('@0xproject/', ''); const changelogJSONPath = path.join( constants.monorepoRootPath, @@ -135,14 +135,14 @@ export const postpublishUtils = { }); return notes; }, - getTag(packageName: string, version: string) { + getTag(packageName: string, version: string): string { return `${packageName}@${version}`; }, getReleaseName(subPackageName: string, version: string): string { const releaseName = `${subPackageName} v${version}`; return releaseName; }, - adjustAssetPaths(cwd: string, assets: string[]) { + adjustAssetPaths(cwd: string, assets: string[]): string[] { const finalAssets: string[] = []; _.each(assets, (asset: string) => { finalAssets.push(`${cwd}/${asset}`); @@ -164,7 +164,7 @@ export const postpublishUtils = { }); return fileIncludesAdjusted; }, - async generateAndUploadDocsAsync(cwd: string, fileIncludes: string[], version: string, S3BucketPath: string) { + async generateAndUploadDocsAsync(cwd: string, fileIncludes: string[], version: string, S3BucketPath: string): Promise { const fileIncludesAdjusted = this.adjustFileIncludePaths(fileIncludes, cwd); const projectFiles = fileIncludesAdjusted.join(' '); const jsonFilePath = `${cwd}/${generatedDocsDirectoryName}/index.json`; diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index a5be40014..9fa0230c8 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -72,7 +72,7 @@ const packageNameToWebsitePath: { [name: string]: string } = { process.exit(1); }); -async function confirmDocPagesRenderAsync(packages: LernaPackage[]) { +async function confirmDocPagesRenderAsync(packages: LernaPackage[]): Promise { // push docs to staging utils.log("Upload all docJson's to S3 staging..."); await execAsync(`yarn lerna:stage_docs`, { cwd: constants.monorepoRootPath }); @@ -162,7 +162,7 @@ async function checkPublishRequiredSetupAsync(): Promise { return true; } -async function pushChangelogsToGithubAsync() { +async function pushChangelogsToGithubAsync(): Promise { await execAsync(`git add . --all`, { cwd: constants.monorepoRootPath }); await execAsync(`git commit -m "Updated CHANGELOGS"`, { cwd: constants.monorepoRootPath }); await execAsync(`git push`, { cwd: constants.monorepoRootPath }); @@ -228,7 +228,7 @@ async function updateChangeLogsAsync(updatedPublicLernaPackages: LernaPackage[]) return packageToVersionChange; } -async function lernaPublishAsync(packageToVersionChange: { [name: string]: string }) { +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', '--registry=https://registry.npmjs.org/'], { @@ -269,7 +269,7 @@ async function lernaPublishAsync(packageToVersionChange: { [name: string]: strin }); } -function updateVersionNumberIfNeeded(currentVersion: string, proposedNextVersion: string) { +function updateVersionNumberIfNeeded(currentVersion: string, proposedNextVersion: string): string { if (proposedNextVersion === currentVersion) { return utils.getNextPatchVersion(currentVersion); } diff --git a/packages/monorepo-scripts/src/utils.ts b/packages/monorepo-scripts/src/utils.ts index 4412f753a..480788ad8 100644 --- a/packages/monorepo-scripts/src/utils.ts +++ b/packages/monorepo-scripts/src/utils.ts @@ -17,7 +17,7 @@ export const utils = { const newPatchVersion = `${versionSegments[0]}.${versionSegments[1]}.${newPatch}`; return newPatchVersion; }, - async prettifyAsync(filePath: string, cwd: string) { + async prettifyAsync(filePath: string, cwd: string): Promise { await execAsync(`prettier --write ${filePath} --config .prettierrc`, { cwd, }); @@ -43,7 +43,7 @@ export const utils = { } return updatedPackages; }, - getChangelogJSONIfExists(changelogPath: string) { + getChangelogJSONIfExists(changelogPath: string): string|undefined { try { const changelogJSON = fs.readFileSync(changelogPath, 'utf-8'); return changelogJSON; -- cgit v1.2.3 From c520b7f1fb599b98878e4755d509b566ab959b05 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Mon, 14 May 2018 15:44:09 -0700 Subject: Apply prettier to some files which were not formatted correctly --- packages/monorepo-scripts/src/postpublish_utils.ts | 7 ++++++- packages/monorepo-scripts/src/utils.ts | 2 +- 2 files changed, 7 insertions(+), 2 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 5fbff938e..22614f01b 100644 --- a/packages/monorepo-scripts/src/postpublish_utils.ts +++ b/packages/monorepo-scripts/src/postpublish_utils.ts @@ -164,7 +164,12 @@ export const postpublishUtils = { }); return fileIncludesAdjusted; }, - async generateAndUploadDocsAsync(cwd: string, fileIncludes: string[], version: string, S3BucketPath: string): Promise { + async generateAndUploadDocsAsync( + cwd: string, + fileIncludes: string[], + version: string, + S3BucketPath: string, + ): Promise { const fileIncludesAdjusted = this.adjustFileIncludePaths(fileIncludes, cwd); const projectFiles = fileIncludesAdjusted.join(' '); const jsonFilePath = `${cwd}/${generatedDocsDirectoryName}/index.json`; diff --git a/packages/monorepo-scripts/src/utils.ts b/packages/monorepo-scripts/src/utils.ts index 480788ad8..c2d92c86a 100644 --- a/packages/monorepo-scripts/src/utils.ts +++ b/packages/monorepo-scripts/src/utils.ts @@ -43,7 +43,7 @@ export const utils = { } return updatedPackages; }, - getChangelogJSONIfExists(changelogPath: string): string|undefined { + getChangelogJSONIfExists(changelogPath: string): string | undefined { try { const changelogJSON = fs.readFileSync(changelogPath, 'utf-8'); return changelogJSON; -- cgit v1.2.3 From 839db68571037f6fff8273aaade6ea0bd14ea8a5 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 16 May 2018 14:59:10 +0200 Subject: Fix TSLint rules --- packages/monorepo-scripts/src/postpublish_utils.ts | 1 + packages/monorepo-scripts/src/publish.ts | 4 ++-- 2 files changed, 3 insertions(+), 2 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 22614f01b..f5785343d 100644 --- a/packages/monorepo-scripts/src/postpublish_utils.ts +++ b/packages/monorepo-scripts/src/postpublish_utils.ts @@ -158,6 +158,7 @@ export const postpublishUtils = { // HACK: tsconfig.json needs wildcard directory endings as `/**/*` // but TypeDoc needs it as `/**` in order to pick up files at the root if (_.endsWith(includePath, '/**/*')) { + // tslint:disable-next-line:custom-no-magic-numbers includePath = includePath.slice(0, -2); } return includePath; diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 5c26475c9..73106821a 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -285,8 +285,8 @@ function shouldAddNewChangelogEntry(currentVersion: string, changelogs: Changelo return true; } const lastEntry = changelogs[0]; - const lastEntryCurrentVersion = lastEntry.version === currentVersion; - return lastEntryCurrentVersion; + const isLastEntryCurrentVersion = lastEntry.version === currentVersion; + return isLastEntryCurrentVersion; } function generateChangelogMd(changelogs: Changelog[]): string { -- cgit v1.2.3 From 06e5fc233c512d152d61c4acbed8d9344e769abe Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 1 Jun 2018 13:12:45 -0700 Subject: Refactor changelog utils to a separate module --- packages/monorepo-scripts/src/deps_versions.ts | 2 +- .../src/find_unused_dependencies.ts | 2 +- packages/monorepo-scripts/src/postpublish_utils.ts | 2 +- packages/monorepo-scripts/src/publish.ts | 62 ++++----------------- packages/monorepo-scripts/src/remove_tags.ts | 4 +- packages/monorepo-scripts/src/test_installation.ts | 2 +- packages/monorepo-scripts/src/types.ts | 8 ++- packages/monorepo-scripts/src/utils.ts | 64 ---------------------- .../monorepo-scripts/src/utils/changelog_utils.ts | 55 +++++++++++++++++++ packages/monorepo-scripts/src/utils/utils.ts | 64 ++++++++++++++++++++++ 10 files changed, 140 insertions(+), 125 deletions(-) delete mode 100644 packages/monorepo-scripts/src/utils.ts create mode 100644 packages/monorepo-scripts/src/utils/changelog_utils.ts create mode 100644 packages/monorepo-scripts/src/utils/utils.ts (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/deps_versions.ts b/packages/monorepo-scripts/src/deps_versions.ts index 07292a160..f090d12e9 100644 --- a/packages/monorepo-scripts/src/deps_versions.ts +++ b/packages/monorepo-scripts/src/deps_versions.ts @@ -5,7 +5,7 @@ import * as fs from 'fs'; import { sync as globSync } from 'glob'; import * as _ from 'lodash'; -import { utils } from './utils'; +import { utils } from './utils/utils'; interface Dependencies { [depName: string]: string; diff --git a/packages/monorepo-scripts/src/find_unused_dependencies.ts b/packages/monorepo-scripts/src/find_unused_dependencies.ts index df303f6ce..71e707224 100644 --- a/packages/monorepo-scripts/src/find_unused_dependencies.ts +++ b/packages/monorepo-scripts/src/find_unused_dependencies.ts @@ -7,7 +7,7 @@ import * as _ from 'lodash'; import { exec as execAsync } from 'promisify-child-process'; import { constants } from './constants'; -import { utils } from './utils'; +import { utils } from './utils/utils'; // For some reason, `depcheck` hangs on some packages. Add them here. const IGNORE_PACKAGES = ['@0xproject/sol-compiler']; diff --git a/packages/monorepo-scripts/src/postpublish_utils.ts b/packages/monorepo-scripts/src/postpublish_utils.ts index f5785343d..dbbde894d 100644 --- a/packages/monorepo-scripts/src/postpublish_utils.ts +++ b/packages/monorepo-scripts/src/postpublish_utils.ts @@ -7,7 +7,7 @@ import * as publishRelease from 'publish-release'; import semverSort = require('semver-sort'); import { constants } from './constants'; -import { utils } from './utils'; +import { utils } from './utils/utils'; const publishReleaseAsync = promisify(publishRelease); const generatedDocsDirectoryName = 'generated_docs'; diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 73106821a..022fe172e 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -13,14 +13,14 @@ import semverDiff = require('semver-diff'); import semverSort = require('semver-sort'); import { constants } from './constants'; -import { Changelog, Changes, PackageToVersionChange, SemVerIndex, UpdatedPackage } from './types'; -import { utils } from './utils'; +import { Changelog, PackageToVersionChange, SemVerIndex, VersionChangelog } from './types'; +import { changelogUtils } from './utils/changelog_utils'; +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 TODAYS_TIMESTAMP = moment().unix(); -const LERNA_EXECUTABLE = './node_modules/lerna/bin/lerna.js'; const semverNameToIndex: { [semver: string]: number } = { patch: SemVerIndex.Patch, minor: SemVerIndex.Minor, @@ -118,7 +118,7 @@ async function checkPublishRequiredSetupAsync(): Promise { // 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 N setup). + // 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.'); @@ -175,7 +175,7 @@ async function updateChangeLogsAsync(updatedPublicLernaPackages: LernaPackage[]) const packageName = lernaPackage.package.name; const changelogJSONPath = path.join(lernaPackage.location, 'CHANGELOG.json'); const changelogJSON = utils.getChangelogJSONOrCreateIfMissing(changelogJSONPath); - let changelogs: Changelog[]; + let changelogs: Changelog; try { changelogs = JSON.parse(changelogJSON); } catch (err) { @@ -185,11 +185,11 @@ async function updateChangeLogsAsync(updatedPublicLernaPackages: LernaPackage[]) } const currentVersion = lernaPackage.package.version; - const shouldAddNewEntry = shouldAddNewChangelogEntry(currentVersion, changelogs); + const shouldAddNewEntry = changelogUtils.shouldAddNewChangelogEntry(currentVersion, changelogs); if (shouldAddNewEntry) { // Create a new entry for a patch version with generic changelog entry. const nextPatchVersion = utils.getNextPatchVersion(currentVersion); - const newChangelogEntry: Changelog = { + const newChangelogEntry: VersionChangelog = { timestamp: TODAYS_TIMESTAMP, version: nextPatchVersion, changes: [ @@ -218,7 +218,7 @@ async function updateChangeLogsAsync(updatedPublicLernaPackages: LernaPackage[]) await utils.prettifyAsync(changelogJSONPath, constants.monorepoRootPath); utils.log(`${packageName}: Updated CHANGELOG.json`); // Generate updated CHANGELOG.md - const changelogMd = generateChangelogMd(changelogs); + const changelogMd = changelogUtils.generateChangelogMd(changelogs); const changelogMdPath = path.join(lernaPackage.location, 'CHANGELOG.md'); fs.writeFileSync(changelogMdPath, changelogMd); await utils.prettifyAsync(changelogMdPath, constants.monorepoRootPath); @@ -231,7 +231,8 @@ async function updateChangeLogsAsync(updatedPublicLernaPackages: LernaPackage[]) 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', '--registry=https://registry.npmjs.org/'], { + const PACKAGE_REGISTRY = 'https://registry.npmjs.org/'; + const child = spawn('lerna', ['publish', `--registry=${PACKAGE_REGISTRY}`], { cwd: constants.monorepoRootPath, }); let shouldPrintOutput = false; @@ -279,46 +280,3 @@ function updateVersionNumberIfNeeded(currentVersion: string, proposedNextVersion } return proposedNextVersion; } - -function shouldAddNewChangelogEntry(currentVersion: string, changelogs: Changelog[]): boolean { - if (_.isEmpty(changelogs)) { - return true; - } - const lastEntry = changelogs[0]; - const isLastEntryCurrentVersion = lastEntry.version === currentVersion; - return isLastEntryCurrentVersion; -} - -function generateChangelogMd(changelogs: Changelog[]): string { - let changelogMd = ` - -CHANGELOG - `; - - _.each(changelogs, changelog => { - if (_.isUndefined(changelog.timestamp)) { - throw new Error( - 'All CHANGELOG.json entries must be updated to include a timestamp before generating their MD version', - ); - } - const date = moment(`${changelog.timestamp}`, 'X').format('MMMM D, YYYY'); - const title = `\n## v${changelog.version} - _${date}_\n\n`; - changelogMd += title; - - let changes = ''; - _.each(changelog.changes, change => { - let line = ` * ${change.note}`; - if (!_.isUndefined(change.pr)) { - line += ` (#${change.pr})`; - } - line += '\n'; - changes += line; - }); - changelogMd += `${changes}`; - }); - - return changelogMd; -} diff --git a/packages/monorepo-scripts/src/remove_tags.ts b/packages/monorepo-scripts/src/remove_tags.ts index 6d09729c7..affdf2751 100644 --- a/packages/monorepo-scripts/src/remove_tags.ts +++ b/packages/monorepo-scripts/src/remove_tags.ts @@ -8,7 +8,7 @@ import semverSort = require('semver-sort'); import { constants } from './constants'; import { Changelog } from './types'; -import { utils } from './utils'; +import { utils } from './utils/utils'; (async () => { const shouldIncludePrivate = true; @@ -24,7 +24,7 @@ import { utils } from './utils'; let latestChangelogVersion: string; if (!_.isUndefined(changelogJSONIfExists)) { - let changelogs: Changelog[]; + let changelogs: Changelog; try { changelogs = JSON.parse(changelogJSONIfExists); } catch (err) { diff --git a/packages/monorepo-scripts/src/test_installation.ts b/packages/monorepo-scripts/src/test_installation.ts index e84221f9d..b67154667 100644 --- a/packages/monorepo-scripts/src/test_installation.ts +++ b/packages/monorepo-scripts/src/test_installation.ts @@ -7,7 +7,7 @@ import * as path from 'path'; import { exec as execAsync } from 'promisify-child-process'; import * as rimraf from 'rimraf'; -import { utils } from './utils'; +import { utils } from './utils/utils'; (async () => { const monorepoRootPath = path.join(__dirname, '../../..'); diff --git a/packages/monorepo-scripts/src/types.ts b/packages/monorepo-scripts/src/types.ts index 28d00d710..36fb923b3 100644 --- a/packages/monorepo-scripts/src/types.ts +++ b/packages/monorepo-scripts/src/types.ts @@ -4,15 +4,17 @@ export interface UpdatedPackage { private: boolean; } -export interface Changes { +export interface Change { note: string; pr?: number; } -export interface Changelog { +export type Changelog = VersionChangelog[]; + +export interface VersionChangelog { timestamp?: number; version: string; - changes: Changes[]; + changes: Change[]; } export enum SemVerIndex { diff --git a/packages/monorepo-scripts/src/utils.ts b/packages/monorepo-scripts/src/utils.ts deleted file mode 100644 index c2d92c86a..000000000 --- a/packages/monorepo-scripts/src/utils.ts +++ /dev/null @@ -1,64 +0,0 @@ -import * as fs from 'fs'; -import lernaGetPackages = require('lerna-get-packages'); -import * as _ from 'lodash'; -import { exec as execAsync, spawn } from 'promisify-child-process'; - -import { constants } from './constants'; -import { UpdatedPackage } from './types'; - -export const utils = { - log(...args: any[]): void { - console.log(...args); // tslint:disable-line:no-console - }, - getNextPatchVersion(currentVersion: string): string { - const versionSegments = currentVersion.split('.'); - const patch = _.parseInt(_.last(versionSegments) as string); - const newPatch = patch + 1; - const newPatchVersion = `${versionSegments[0]}.${versionSegments[1]}.${newPatch}`; - return newPatchVersion; - }, - async prettifyAsync(filePath: string, cwd: string): Promise { - await execAsync(`prettier --write ${filePath} --config .prettierrc`, { - cwd, - }); - }, - async getUpdatedLernaPackagesAsync(shouldIncludePrivate: boolean): Promise { - const updatedPublicPackages = await this.getLernaUpdatedPackagesAsync(shouldIncludePrivate); - const updatedPackageNames = _.map(updatedPublicPackages, pkg => pkg.name); - - const allLernaPackages = lernaGetPackages(constants.monorepoRootPath); - const updatedPublicLernaPackages = _.filter(allLernaPackages, pkg => { - return _.includes(updatedPackageNames, pkg.package.name); - }); - return updatedPublicLernaPackages; - }, - async getLernaUpdatedPackagesAsync(shouldIncludePrivate: boolean): Promise { - const result = await execAsync(`${constants.lernaExecutable} updated --json`, { - cwd: constants.monorepoRootPath, - }); - const updatedPackages = JSON.parse(result.stdout); - if (!shouldIncludePrivate) { - const updatedPublicPackages = _.filter(updatedPackages, updatedPackage => !updatedPackage.private); - return updatedPublicPackages; - } - return updatedPackages; - }, - getChangelogJSONIfExists(changelogPath: string): string | undefined { - try { - const changelogJSON = fs.readFileSync(changelogPath, 'utf-8'); - return changelogJSON; - } catch (err) { - return undefined; - } - }, - getChangelogJSONOrCreateIfMissing(changelogPath: string): string { - const changelogIfExists = this.getChangelogJSONIfExists(changelogPath); - if (_.isUndefined(changelogIfExists)) { - // If none exists, create new, empty one. - const emptyChangelogJSON = JSON.stringify([]); - fs.writeFileSync(changelogPath, emptyChangelogJSON); - return emptyChangelogJSON; - } - return changelogIfExists; - }, -}; diff --git a/packages/monorepo-scripts/src/utils/changelog_utils.ts b/packages/monorepo-scripts/src/utils/changelog_utils.ts new file mode 100644 index 000000000..edfe65a80 --- /dev/null +++ b/packages/monorepo-scripts/src/utils/changelog_utils.ts @@ -0,0 +1,55 @@ +import * as _ from 'lodash'; +import * as moment from 'moment'; + +import { Change, Changelog, VersionChangelog } from '../types'; + +const CHANGELOG_MD_HEADER = ` + + +CHANGELOG +`; + +export const changelogUtils = { + getChangelogMdTitle(versionChangelog: VersionChangelog): string { + if (_.isUndefined(versionChangelog.timestamp)) { + throw new Error( + 'All CHANGELOG.json entries must be updated to include a timestamp before generating their MD version', + ); + } + const date = moment(`${versionChangelog.timestamp}`, 'X').format('MMMM D, YYYY'); + const title = `\n## v${versionChangelog.version} - _${date}_\n\n`; + return title; + }, + getChangelogMdChange(change: Change): string { + let line = ` * ${change.note}`; + if (!_.isUndefined(change.pr)) { + line += ` (#${change.pr})`; + } + return line; + }, + generateChangelogMd(changelog: Changelog): string { + let changelogMd = CHANGELOG_MD_HEADER; + _.each(changelog, versionChangelog => { + const title = changelogUtils.getChangelogMdTitle(versionChangelog); + changelogMd += title; + const changelogVersionLines = _.map( + versionChangelog.changes, + changelogUtils.getChangelogMdChange.bind(changelogUtils), + ); + changelogMd += `${_.join(changelogVersionLines, '\n')}`; + }); + + return changelogMd; + }, + shouldAddNewChangelogEntry(currentVersion: string, changelog: Changelog): boolean { + if (_.isEmpty(changelog)) { + return true; + } + const lastEntry = changelog[0]; + const isLastEntryCurrentVersion = lastEntry.version === currentVersion; + return isLastEntryCurrentVersion; + }, +}; diff --git a/packages/monorepo-scripts/src/utils/utils.ts b/packages/monorepo-scripts/src/utils/utils.ts new file mode 100644 index 000000000..8f2a0bbaa --- /dev/null +++ b/packages/monorepo-scripts/src/utils/utils.ts @@ -0,0 +1,64 @@ +import * as fs from 'fs'; +import lernaGetPackages = require('lerna-get-packages'); +import * as _ from 'lodash'; +import { exec as execAsync, spawn } from 'promisify-child-process'; + +import { constants } from '../constants'; +import { UpdatedPackage } from '../types'; + +export const utils = { + log(...args: any[]): void { + console.log(...args); // tslint:disable-line:no-console + }, + getNextPatchVersion(currentVersion: string): string { + const versionSegments = currentVersion.split('.'); + const patch = _.parseInt(_.last(versionSegments) as string); + const newPatch = patch + 1; + const newPatchVersion = `${versionSegments[0]}.${versionSegments[1]}.${newPatch}`; + return newPatchVersion; + }, + async prettifyAsync(filePath: string, cwd: string): Promise { + await execAsync(`prettier --write ${filePath} --config .prettierrc`, { + cwd, + }); + }, + async getUpdatedLernaPackagesAsync(shouldIncludePrivate: boolean): Promise { + const updatedPublicPackages = await this.getLernaUpdatedPackagesAsync(shouldIncludePrivate); + const updatedPackageNames = _.map(updatedPublicPackages, pkg => pkg.name); + + const allLernaPackages = lernaGetPackages(constants.monorepoRootPath); + const updatedPublicLernaPackages = _.filter(allLernaPackages, pkg => { + return _.includes(updatedPackageNames, pkg.package.name); + }); + return updatedPublicLernaPackages; + }, + async getLernaUpdatedPackagesAsync(shouldIncludePrivate: boolean): Promise { + const result = await execAsync(`${constants.lernaExecutable} updated --json`, { + cwd: constants.monorepoRootPath, + }); + const updatedPackages = JSON.parse(result.stdout); + if (!shouldIncludePrivate) { + const updatedPublicPackages = _.filter(updatedPackages, updatedPackage => !updatedPackage.private); + return updatedPublicPackages; + } + return updatedPackages; + }, + getChangelogJSONIfExists(changelogPath: string): string | undefined { + try { + const changelogJSON = fs.readFileSync(changelogPath, 'utf-8'); + return changelogJSON; + } catch (err) { + return undefined; + } + }, + getChangelogJSONOrCreateIfMissing(changelogPath: string): string { + const changelogIfExists = this.getChangelogJSONIfExists(changelogPath); + if (_.isUndefined(changelogIfExists)) { + // If none exists, create new, empty one. + const emptyChangelogJSON = JSON.stringify([]); + fs.writeFileSync(changelogPath, emptyChangelogJSON); + return emptyChangelogJSON; + } + return changelogIfExists; + }, +}; -- cgit v1.2.3 From 2f8e52f9057b98b5f60dc3ec3428b024739a2997 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 1 Jun 2018 13:39:04 -0700 Subject: Move prepublish checks before building packages for publishing --- packages/monorepo-scripts/src/prepublish_checks.ts | 55 ++++++++++++++++++++++ packages/monorepo-scripts/src/publish.ts | 53 --------------------- 2 files changed, 55 insertions(+), 53 deletions(-) create mode 100644 packages/monorepo-scripts/src/prepublish_checks.ts (limited to 'packages/monorepo-scripts/src') 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 { + // 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 { - // 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 { await execAsync(`git add . --all`, { cwd: constants.monorepoRootPath }); await execAsync(`git commit -m "Updated CHANGELOGS"`, { cwd: constants.monorepoRootPath }); -- cgit v1.2.3 From d4d03f3d7f437d4199dcfec58cbd98735e5e7d51 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 1 Jun 2018 13:55:40 -0700 Subject: Check that git branch is up to date before publishing --- packages/monorepo-scripts/src/prepublish_checks.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (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 ae58524f5..2c096d8f6 100644 --- a/packages/monorepo-scripts/src/prepublish_checks.ts +++ b/packages/monorepo-scripts/src/prepublish_checks.ts @@ -47,9 +47,25 @@ async function checkPublishRequiredSetupAsync(): Promise { } 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); + utils.log(err.message); process.exit(1); }); -- cgit v1.2.3 From 50552546f392214726e6b969a72c04f320486b16 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 1 Jun 2018 15:46:16 -0700 Subject: Rename changelogs to changelog --- packages/monorepo-scripts/src/publish.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 45dea9796..36970f85b 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -122,9 +122,9 @@ async function updateChangeLogsAsync(updatedPublicLernaPackages: LernaPackage[]) const packageName = lernaPackage.package.name; const changelogJSONPath = path.join(lernaPackage.location, 'CHANGELOG.json'); const changelogJSON = utils.getChangelogJSONOrCreateIfMissing(changelogJSONPath); - let changelogs: Changelog; + let changelog: Changelog; try { - changelogs = JSON.parse(changelogJSON); + changelog = JSON.parse(changelogJSON); } catch (err) { throw new Error( `${lernaPackage.package.name}'s CHANGELOG.json contains invalid JSON. Please fix and try again.`, @@ -132,7 +132,7 @@ async function updateChangeLogsAsync(updatedPublicLernaPackages: LernaPackage[]) } const currentVersion = lernaPackage.package.version; - const shouldAddNewEntry = changelogUtils.shouldAddNewChangelogEntry(currentVersion, changelogs); + const shouldAddNewEntry = changelogUtils.shouldAddNewChangelogEntry(currentVersion, changelog); if (shouldAddNewEntry) { // Create a new entry for a patch version with generic changelog entry. const nextPatchVersion = utils.getNextPatchVersion(currentVersion); @@ -145,27 +145,27 @@ async function updateChangeLogsAsync(updatedPublicLernaPackages: LernaPackage[]) }, ], }; - changelogs = [newChangelogEntry, ...changelogs]; + changelog = [newChangelogEntry, ...changelog]; packageToVersionChange[packageName] = semverDiff(currentVersion, nextPatchVersion); } else { // Update existing entry with timestamp - const lastEntry = changelogs[0]; + const lastEntry = changelog[0]; if (_.isUndefined(lastEntry.timestamp)) { lastEntry.timestamp = TODAYS_TIMESTAMP; } // Check version number is correct. const proposedNextVersion = lastEntry.version; lastEntry.version = updateVersionNumberIfNeeded(currentVersion, proposedNextVersion); - changelogs[0] = lastEntry; + changelog[0] = lastEntry; packageToVersionChange[packageName] = semverDiff(currentVersion, lastEntry.version); } // Save updated CHANGELOG.json - fs.writeFileSync(changelogJSONPath, JSON.stringify(changelogs, null, '\t')); + fs.writeFileSync(changelogJSONPath, JSON.stringify(changelog, null, '\t')); await utils.prettifyAsync(changelogJSONPath, constants.monorepoRootPath); utils.log(`${packageName}: Updated CHANGELOG.json`); // Generate updated CHANGELOG.md - const changelogMd = changelogUtils.generateChangelogMd(changelogs); + const changelogMd = changelogUtils.generateChangelogMd(changelog); const changelogMdPath = path.join(lernaPackage.location, 'CHANGELOG.md'); fs.writeFileSync(changelogMdPath, changelogMd); await utils.prettifyAsync(changelogMdPath, constants.monorepoRootPath); -- cgit v1.2.3 From 9778695b4ad1fd999eb79b01c768a2f2b9938917 Mon Sep 17 00:00:00 2001 From: fragosti Date: Mon, 4 Jun 2018 19:48:21 -0700 Subject: Try enabling no-unused-variable... --- packages/monorepo-scripts/src/deps_versions.ts | 2 ++ packages/monorepo-scripts/src/find_unused_dependencies.ts | 2 -- packages/monorepo-scripts/src/postpublish_utils.ts | 4 +++- packages/monorepo-scripts/src/publish.ts | 1 - packages/monorepo-scripts/src/remove_tags.ts | 1 - packages/monorepo-scripts/src/utils/utils.ts | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/deps_versions.ts b/packages/monorepo-scripts/src/deps_versions.ts index f090d12e9..1053906b7 100644 --- a/packages/monorepo-scripts/src/deps_versions.ts +++ b/packages/monorepo-scripts/src/deps_versions.ts @@ -19,6 +19,7 @@ interface VersionsByDependency { const PACKAGE_JSON_GLOB = '../*/package.json'; +// tslint:disable:no-unused-variable function getDependencies(path: string): Dependencies { const file = fs.readFileSync(path).toString(); const parsed = JSON.parse(file); @@ -52,3 +53,4 @@ _.map(versionsByDependency, (versions: Versions, depName: string) => { }); } }); +// tslint:disable:no-unused-variable diff --git a/packages/monorepo-scripts/src/find_unused_dependencies.ts b/packages/monorepo-scripts/src/find_unused_dependencies.ts index 71e707224..11e48ab13 100644 --- a/packages/monorepo-scripts/src/find_unused_dependencies.ts +++ b/packages/monorepo-scripts/src/find_unused_dependencies.ts @@ -1,10 +1,8 @@ #!/usr/bin/env node import * as depcheckAsync from 'depcheck'; -import * as fs from 'fs'; import lernaGetPackages = require('lerna-get-packages'); import * as _ from 'lodash'; -import { exec as execAsync } from 'promisify-child-process'; import { constants } from './constants'; import { utils } from './utils/utils'; diff --git a/packages/monorepo-scripts/src/postpublish_utils.ts b/packages/monorepo-scripts/src/postpublish_utils.ts index dbbde894d..e60d9e521 100644 --- a/packages/monorepo-scripts/src/postpublish_utils.ts +++ b/packages/monorepo-scripts/src/postpublish_utils.ts @@ -4,7 +4,6 @@ import * as fs from 'fs'; import * as _ from 'lodash'; import * as path from 'path'; import * as publishRelease from 'publish-release'; -import semverSort = require('semver-sort'); import { constants } from './constants'; import { utils } from './utils/utils'; @@ -53,6 +52,7 @@ export const postpublishUtils = { }, async runAsync(packageJSON: any, tsConfigJSON: any, cwd: string): Promise { const configs = this.generateConfig(packageJSON, tsConfigJSON, cwd); + // tslint:disable-next-line:no-unused-variable const release = await this.publishReleaseNotesAsync( configs.cwd, configs.packageName, @@ -93,8 +93,10 @@ export const postpublishUtils = { const notes = this.getReleaseNotes(packageName, version); const releaseName = this.getReleaseName(packageName, version); const tag = this.getTag(packageName, version); + // tslint:disable-next-line:no-unused-variable const finalAssets = this.adjustAssetPaths(cwd, assets); utils.log('POSTPUBLISH: Releasing ', releaseName, '...'); + // tslint:disable-next-line:no-unused-variable const result = await publishReleaseAsync({ token: constants.githubPersonalAccessToken, owner: '0xProject', diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 36970f85b..2efbc8bf2 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -2,7 +2,6 @@ import * as promisify from 'es6-promisify'; import * as fs from 'fs'; -import lernaGetPackages = require('lerna-get-packages'); import * as _ from 'lodash'; import * as moment from 'moment'; import opn = require('opn'); diff --git a/packages/monorepo-scripts/src/remove_tags.ts b/packages/monorepo-scripts/src/remove_tags.ts index affdf2751..50e413495 100644 --- a/packages/monorepo-scripts/src/remove_tags.ts +++ b/packages/monorepo-scripts/src/remove_tags.ts @@ -1,6 +1,5 @@ #!/usr/bin/env node -import lernaGetPackages = require('lerna-get-packages'); import * as _ from 'lodash'; import * as path from 'path'; import { exec as execAsync } from 'promisify-child-process'; diff --git a/packages/monorepo-scripts/src/utils/utils.ts b/packages/monorepo-scripts/src/utils/utils.ts index 8f2a0bbaa..0b8ac4c0b 100644 --- a/packages/monorepo-scripts/src/utils/utils.ts +++ b/packages/monorepo-scripts/src/utils/utils.ts @@ -1,7 +1,7 @@ import * as fs from 'fs'; import lernaGetPackages = require('lerna-get-packages'); import * as _ from 'lodash'; -import { exec as execAsync, spawn } from 'promisify-child-process'; +import { exec as execAsync } from 'promisify-child-process'; import { constants } from '../constants'; import { UpdatedPackage } from '../types'; -- cgit v1.2.3 From db8f018b422461716c4c5916dd0a3a76f245a72e Mon Sep 17 00:00:00 2001 From: fragosti Date: Tue, 5 Jun 2018 11:51:07 -0700 Subject: Some cleanup --- packages/monorepo-scripts/src/postpublish_utils.ts | 14 +++----------- 1 file changed, 3 insertions(+), 11 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 e60d9e521..b55a88539 100644 --- a/packages/monorepo-scripts/src/postpublish_utils.ts +++ b/packages/monorepo-scripts/src/postpublish_utils.ts @@ -52,13 +52,7 @@ export const postpublishUtils = { }, async runAsync(packageJSON: any, tsConfigJSON: any, cwd: string): Promise { const configs = this.generateConfig(packageJSON, tsConfigJSON, cwd); - // tslint:disable-next-line:no-unused-variable - const release = await this.publishReleaseNotesAsync( - configs.cwd, - configs.packageName, - configs.version, - configs.assets, - ); + await this.publishReleaseNotesAsync(configs.cwd, configs.packageName, configs.version, configs.assets); if ( !_.isUndefined(configs.docPublishConfigs.s3BucketPath) || !_.isUndefined(configs.docPublishConfigs.s3StagingBucketPath) @@ -93,11 +87,9 @@ export const postpublishUtils = { const notes = this.getReleaseNotes(packageName, version); const releaseName = this.getReleaseName(packageName, version); const tag = this.getTag(packageName, version); - // tslint:disable-next-line:no-unused-variable - const finalAssets = this.adjustAssetPaths(cwd, assets); + this.adjustAssetPaths(cwd, assets); utils.log('POSTPUBLISH: Releasing ', releaseName, '...'); - // tslint:disable-next-line:no-unused-variable - const result = await publishReleaseAsync({ + await publishReleaseAsync({ token: constants.githubPersonalAccessToken, owner: '0xProject', repo: '0x-monorepo', -- cgit v1.2.3 From 8633fa702436cceeafa52ec39a7fabb5b2650c38 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 18 Jun 2018 16:55:59 +0200 Subject: Add more prepublish checks --- packages/monorepo-scripts/src/prepublish_checks.ts | 96 ++++++++++++++++++++- packages/monorepo-scripts/src/publish.ts | 24 ++---- packages/monorepo-scripts/src/types.ts | 13 +++ .../monorepo-scripts/src/utils/changelog_utils.ts | 55 +++++++++++- packages/monorepo-scripts/src/utils/npm_utils.ts | 28 +++++++ .../monorepo-scripts/src/utils/semver_utils.ts | 56 +++++++++++++ packages/monorepo-scripts/src/utils/utils.ts | 98 +++++++++++++++++----- 7 files changed, 331 insertions(+), 39 deletions(-) create mode 100644 packages/monorepo-scripts/src/utils/npm_utils.ts create mode 100644 packages/monorepo-scripts/src/utils/semver_utils.ts (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 2c096d8f6..64de56ece 100644 --- a/packages/monorepo-scripts/src/prepublish_checks.ts +++ b/packages/monorepo-scripts/src/prepublish_checks.ts @@ -1,9 +1,103 @@ +import * as fs from 'fs'; import * as _ from 'lodash'; +import * as path from 'path'; import { exec as execAsync } from 'promisify-child-process'; import { constants } from './constants'; +import { Changelog, PackageRegistryJson } from './types'; +import { changelogUtils } from './utils/changelog_utils'; +import { npmUtils } from './utils/npm_utils'; +import { semverUtils } from './utils/semver_utils'; import { utils } from './utils/utils'; +async function prepublishChecksAsync(): Promise { + const shouldIncludePrivate = false; + const updatedPublicLernaPackages = await utils.getUpdatedLernaPackagesAsync(shouldIncludePrivate); + + await checkCurrentVersionMatchesLatestPublishedNPMPackageAsync(updatedPublicLernaPackages); + await checkChangelogFormatAsync(updatedPublicLernaPackages); + await checkGitTagsForNextVersionAndDeleteIfExistAsync(updatedPublicLernaPackages); + await checkPublishRequiredSetupAsync(); +} + +async function checkGitTagsForNextVersionAndDeleteIfExistAsync( + updatedPublicLernaPackages: LernaPackage[], +): Promise { + const packageNames = _.map(updatedPublicLernaPackages, lernaPackage => lernaPackage.package.name); + const localGitTags = await utils.getLocalGitTagsAsync(); + const localTagVersionsByPackageName = await utils.getGitTagsByPackageNameAsync(packageNames, localGitTags); + + const remoteGitTags = await utils.getRemoteGitTagsAsync(); + const remoteTagVersionsByPackageName = await utils.getGitTagsByPackageNameAsync(packageNames, remoteGitTags); + + for (const lernaPackage of updatedPublicLernaPackages) { + const currentVersion = lernaPackage.package.version; + const packageName = lernaPackage.package.name; + const packageLocation = lernaPackage.location; + const nextVersion = await utils.getNextPackageVersionAsync(currentVersion, packageName, packageLocation); + + const localTagVersions = localTagVersionsByPackageName[packageName]; + if (_.includes(localTagVersions, nextVersion)) { + const tagName = `${packageName}@${nextVersion}`; + await utils.removeLocalTagAsync(tagName); + } + + const remoteTagVersions = remoteTagVersionsByPackageName[packageName]; + if (_.includes(remoteTagVersions, nextVersion)) { + const tagName = `:refs/tags/${packageName}@${nextVersion}`; + await utils.removeRemoteTagAsync(tagName); + } + } +} + +async function checkCurrentVersionMatchesLatestPublishedNPMPackageAsync( + updatedPublicLernaPackages: LernaPackage[], +): Promise { + for (const lernaPackage of updatedPublicLernaPackages) { + const packageName = lernaPackage.package.name; + const packageVersion = lernaPackage.package.version; + const packageRegistryJsonIfExists = await npmUtils.getPackageRegistryJsonIfExistsAsync(packageName); + if (_.isUndefined(packageRegistryJsonIfExists)) { + continue; // noop for packages not yet published to NPM + } + const allVersionsIncludingUnpublished = npmUtils.getPreviouslyPublishedVersions(packageRegistryJsonIfExists); + const latestNPMVersion = semverUtils.getLatestVersion(allVersionsIncludingUnpublished); + if (packageVersion !== latestNPMVersion) { + throw new Error( + `Found verson ${packageVersion} in package.json but version ${latestNPMVersion} + on NPM (could be unpublished version) for ${packageName}. These versions must match. If you update + the package.json version, make sure to also update the internal dependency versions too.`, + ); + } + } +} + +async function checkChangelogFormatAsync(updatedPublicLernaPackages: LernaPackage[]): Promise { + for (const lernaPackage of updatedPublicLernaPackages) { + const packageName = lernaPackage.package.name; + const changelog = changelogUtils.getChangelogOrCreateIfMissing(packageName, lernaPackage.location); + + const currentVersion = lernaPackage.package.version; + if (!_.isEmpty(changelog)) { + const lastEntry = changelog[0]; + const doesLastEntryHaveTimestamp = !_.isUndefined(lastEntry.timestamp); + if (semverUtils.lessThan(lastEntry.version, currentVersion)) { + throw new Error( + `CHANGELOG version cannot be below current package version. + Update ${packageName}'s CHANGELOG. It's current version is ${currentVersion} + but the latest CHANGELOG entry is: ${lastEntry.version}`, + ); + } else if (semverUtils.greaterThan(lastEntry.version, currentVersion) && doesLastEntryHaveTimestamp) { + // Remove incorrectly added timestamp + delete changelog[0].timestamp; + // Save updated CHANGELOG.json + await changelogUtils.writeChangelogJsonFileAsync(lernaPackage.location, changelog); + utils.log(`${packageName}: Removed timestamp from latest CHANGELOG.json entry.`); + } + } + } +} + async function checkPublishRequiredSetupAsync(): Promise { // check to see if logged into npm before publishing try { @@ -65,7 +159,7 @@ async function checkPublishRequiredSetupAsync(): Promise { } } -checkPublishRequiredSetupAsync().catch(err => { +prepublishChecksAsync().catch(err => { utils.log(err.message); process.exit(1); }); diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 2efbc8bf2..637512a5a 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -119,19 +119,14 @@ async function updateChangeLogsAsync(updatedPublicLernaPackages: LernaPackage[]) const packageToVersionChange: PackageToVersionChange = {}; for (const lernaPackage of updatedPublicLernaPackages) { const packageName = lernaPackage.package.name; - const changelogJSONPath = path.join(lernaPackage.location, 'CHANGELOG.json'); - const changelogJSON = utils.getChangelogJSONOrCreateIfMissing(changelogJSONPath); - let changelog: Changelog; - try { - changelog = JSON.parse(changelogJSON); - } catch (err) { - throw new Error( - `${lernaPackage.package.name}'s CHANGELOG.json contains invalid JSON. Please fix and try again.`, - ); - } + let changelog = changelogUtils.getChangelogOrCreateIfMissing(packageName, lernaPackage.location); const currentVersion = lernaPackage.package.version; - const shouldAddNewEntry = changelogUtils.shouldAddNewChangelogEntry(currentVersion, changelog); + const shouldAddNewEntry = changelogUtils.shouldAddNewChangelogEntry( + lernaPackage.package.name, + currentVersion, + changelog, + ); if (shouldAddNewEntry) { // Create a new entry for a patch version with generic changelog entry. const nextPatchVersion = utils.getNextPatchVersion(currentVersion); @@ -160,14 +155,11 @@ async function updateChangeLogsAsync(updatedPublicLernaPackages: LernaPackage[]) } // Save updated CHANGELOG.json - fs.writeFileSync(changelogJSONPath, JSON.stringify(changelog, null, '\t')); - await utils.prettifyAsync(changelogJSONPath, constants.monorepoRootPath); + await changelogUtils.writeChangelogJsonFileAsync(lernaPackage.location, changelog); utils.log(`${packageName}: Updated CHANGELOG.json`); // Generate updated CHANGELOG.md const changelogMd = changelogUtils.generateChangelogMd(changelog); - const changelogMdPath = path.join(lernaPackage.location, 'CHANGELOG.md'); - fs.writeFileSync(changelogMdPath, changelogMd); - await utils.prettifyAsync(changelogMdPath, constants.monorepoRootPath); + await changelogUtils.writeChangelogMdFileAsync(lernaPackage.location, changelog); utils.log(`${packageName}: Updated CHANGELOG.md`); } diff --git a/packages/monorepo-scripts/src/types.ts b/packages/monorepo-scripts/src/types.ts index 36fb923b3..61bd75732 100644 --- a/packages/monorepo-scripts/src/types.ts +++ b/packages/monorepo-scripts/src/types.ts @@ -27,3 +27,16 @@ export enum SemVerIndex { export interface PackageToVersionChange { [name: string]: string; } + +export interface PackageRegistryJson { + versions: { + [version: string]: any; + }; + time: { + [version: string]: string; + }; +} + +export interface GitTagsByPackageName { + [packageName: string]: string[]; +} diff --git a/packages/monorepo-scripts/src/utils/changelog_utils.ts b/packages/monorepo-scripts/src/utils/changelog_utils.ts index edfe65a80..4e09fc842 100644 --- a/packages/monorepo-scripts/src/utils/changelog_utils.ts +++ b/packages/monorepo-scripts/src/utils/changelog_utils.ts @@ -1,8 +1,15 @@ +import * as fs from 'fs'; import * as _ from 'lodash'; import * as moment from 'moment'; +import * as path from 'path'; +import { exec as execAsync } from 'promisify-child-process'; +import semverSort = require('semver-sort'); +import { constants } from '../constants'; import { Change, Changelog, VersionChangelog } from '../types'; +import { semverUtils } from './semver_utils'; + const CHANGELOG_MD_HEADER = ` @@ -74,7 +74,7 @@ export const changelogUtils = { }, getChangelogOrCreateIfMissing(packageName: string, packageLocation: string): Changelog { const changelogJSONPath = path.join(packageLocation, 'CHANGELOG.json'); - let changelogJsonIfExists = this.getChangelogJSONIfExists(changelogJSONPath); + let changelogJsonIfExists = changelogUtils.getChangelogJSONIfExists(changelogJSONPath); if (_.isUndefined(changelogJsonIfExists)) { // If none exists, create new, empty one. changelogJsonIfExists = '[]'; @@ -91,12 +91,12 @@ export const changelogUtils = { async writeChangelogJsonFileAsync(packageLocation: string, changelog: Changelog): Promise { const changelogJSONPath = path.join(packageLocation, 'CHANGELOG.json'); fs.writeFileSync(changelogJSONPath, JSON.stringify(changelog, null, '\t')); - await this.prettifyAsync(changelogJSONPath, constants.monorepoRootPath); + await changelogUtils.prettifyAsync(changelogJSONPath, constants.monorepoRootPath); }, async writeChangelogMdFileAsync(packageLocation: string, changelogMdString: string): Promise { const changelogMarkdownPath = path.join(packageLocation, 'CHANGELOG.md'); fs.writeFileSync(changelogMarkdownPath, changelogMdString); - await this.prettifyAsync(changelogMarkdownPath, constants.monorepoRootPath); + await changelogUtils.prettifyAsync(changelogMarkdownPath, constants.monorepoRootPath); }, async prettifyAsync(filePath: string, cwd: string): Promise { await execAsync(`prettier --write ${filePath} --config .prettierrc`, { diff --git a/packages/monorepo-scripts/src/utils/utils.ts b/packages/monorepo-scripts/src/utils/utils.ts index f819ab6f1..be3ad950f 100644 --- a/packages/monorepo-scripts/src/utils/utils.ts +++ b/packages/monorepo-scripts/src/utils/utils.ts @@ -13,7 +13,7 @@ export const utils = { console.log(...args); // tslint:disable-line:no-console }, async getUpdatedLernaPackagesAsync(shouldIncludePrivate: boolean): Promise { - const updatedPublicPackages = await this.getLernaUpdatedPackagesAsync(shouldIncludePrivate); + const updatedPublicPackages = await utils.getLernaUpdatedPackagesAsync(shouldIncludePrivate); const updatedPackageNames = _.map(updatedPublicPackages, pkg => pkg.name); const allLernaPackages = lernaGetPackages(constants.monorepoRootPath); @@ -110,7 +110,7 @@ export const utils = { } catch (err) { throw new Error(`Failed to delete local git tag. Got err: ${err}`); } - this.log(`Removed local tag: ${tagName}`); + utils.log(`Removed local tag: ${tagName}`); }, async removeRemoteTagAsync(tagName: string): Promise { try { @@ -120,6 +120,6 @@ export const utils = { } catch (err) { throw new Error(`Failed to delete remote git tag. Got err: ${err}`); } - this.log(`Removed remote tag: ${tagName}`); + utils.log(`Removed remote tag: ${tagName}`); }, }; -- cgit v1.2.3 From 6f540e3e58e6cf921d038f9537d428d28078836f Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 19 Jul 2018 15:50:21 +0200 Subject: Replace lerna-get-packages with our own implementation --- .../src/find_unused_dependencies.ts | 3 +- packages/monorepo-scripts/src/globals.d.ts | 20 +----------- packages/monorepo-scripts/src/prepublish_checks.ts | 1 + packages/monorepo-scripts/src/publish.ts | 2 +- packages/monorepo-scripts/src/test_installation.ts | 3 +- packages/monorepo-scripts/src/types.ts | 14 +++++++++ packages/monorepo-scripts/src/utils/utils.ts | 36 ++++++++++++++++++++-- 7 files changed, 52 insertions(+), 27 deletions(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/find_unused_dependencies.ts b/packages/monorepo-scripts/src/find_unused_dependencies.ts index 11e48ab13..1a36aceee 100644 --- a/packages/monorepo-scripts/src/find_unused_dependencies.ts +++ b/packages/monorepo-scripts/src/find_unused_dependencies.ts @@ -1,7 +1,6 @@ #!/usr/bin/env node import * as depcheckAsync from 'depcheck'; -import lernaGetPackages = require('lerna-get-packages'); import * as _ from 'lodash'; import { constants } from './constants'; @@ -13,7 +12,7 @@ const IGNORE_PACKAGES = ['@0xproject/sol-compiler']; (async () => { utils.log('*** NOTE: Not all deps listed here are actually not required. ***'); utils.log("*** `depcheck` isn't perfect so double check before actually removing any. ***\n"); - const lernaPackages = lernaGetPackages(constants.monorepoRootPath); + const lernaPackages = utils.getLernaPackages(constants.monorepoRootPath); for (const lernaPackage of lernaPackages) { if (_.includes(IGNORE_PACKAGES, lernaPackage.package.name)) { continue; // skip diff --git a/packages/monorepo-scripts/src/globals.d.ts b/packages/monorepo-scripts/src/globals.d.ts index 1693a6dbb..ccdf90d2a 100644 --- a/packages/monorepo-scripts/src/globals.d.ts +++ b/packages/monorepo-scripts/src/globals.d.ts @@ -13,23 +13,5 @@ declare module 'semver-sort' { const desc: (versions: string[]) => string[]; } -declare interface LernaPackage { - location: string; - package: { - private?: boolean; - version: string; - name: string; - main?: string; - scripts?: { [command: string]: string }; - config?: { - additionalTsTypings?: string[]; - }; - }; -} -declare function lernaGetPackages(path: string): LernaPackage[]; -// lerna-get-packages declarations -declare module 'lerna-get-packages' { - export = lernaGetPackages; -} - declare module 'promisify-child-process'; +declare module '@lerna/project'; diff --git a/packages/monorepo-scripts/src/prepublish_checks.ts b/packages/monorepo-scripts/src/prepublish_checks.ts index 3b4ff9082..81b2f414b 100644 --- a/packages/monorepo-scripts/src/prepublish_checks.ts +++ b/packages/monorepo-scripts/src/prepublish_checks.ts @@ -4,6 +4,7 @@ import semver = require('semver'); import semverSort = require('semver-sort'); import { constants } from './constants'; +import { LernaPackage } from './types'; import { changelogUtils } from './utils/changelog_utils'; import { npmUtils } from './utils/npm_utils'; import { utils } from './utils/utils'; diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 72c6c0a71..94b67eab3 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 { PackageToVersionChange, SemVerIndex, VersionChangelog } from './types'; +import { LernaPackage, PackageToVersionChange, SemVerIndex, VersionChangelog } from './types'; import { changelogUtils } from './utils/changelog_utils'; import { utils } from './utils/utils'; diff --git a/packages/monorepo-scripts/src/test_installation.ts b/packages/monorepo-scripts/src/test_installation.ts index b67154667..34d065c58 100644 --- a/packages/monorepo-scripts/src/test_installation.ts +++ b/packages/monorepo-scripts/src/test_installation.ts @@ -1,7 +1,6 @@ #!/usr/bin/env node import * as fs from 'fs'; -import lernaGetPackages = require('lerna-get-packages'); import * as _ from 'lodash'; import * as path from 'path'; import { exec as execAsync } from 'promisify-child-process'; @@ -11,7 +10,7 @@ import { utils } from './utils/utils'; (async () => { const monorepoRootPath = path.join(__dirname, '../../..'); - const lernaPackages = lernaGetPackages(monorepoRootPath); + const lernaPackages = utils.getLernaPackages(monorepoRootPath); const installablePackages = _.filter( lernaPackages, lernaPackage => diff --git a/packages/monorepo-scripts/src/types.ts b/packages/monorepo-scripts/src/types.ts index 61bd75732..052a38d1f 100644 --- a/packages/monorepo-scripts/src/types.ts +++ b/packages/monorepo-scripts/src/types.ts @@ -40,3 +40,17 @@ export interface PackageRegistryJson { export interface GitTagsByPackageName { [packageName: string]: string[]; } + +export interface LernaPackage { + location: string; + package: { + private?: boolean; + version: string; + name: string; + main?: string; + scripts?: { [command: string]: string }; + config?: { + additionalTsTypings?: string[]; + }; + }; +} diff --git a/packages/monorepo-scripts/src/utils/utils.ts b/packages/monorepo-scripts/src/utils/utils.ts index be3ad950f..78bac1e4e 100644 --- a/packages/monorepo-scripts/src/utils/utils.ts +++ b/packages/monorepo-scripts/src/utils/utils.ts @@ -1,10 +1,10 @@ -import lernaGetPackages = require('lerna-get-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, UpdatedPackage } from '../types'; +import { GitTagsByPackageName, LernaPackage, UpdatedPackage } from '../types'; import { changelogUtils } from './changelog_utils'; @@ -12,11 +12,41 @@ export const utils = { log(...args: any[]): void { console.log(...args); // tslint:disable-line:no-console }, + getLernaPackages(rootDir: string): LernaPackage[] { + const rootPackageJsonString = fs.readFileSync(`${rootDir}/package.json`, 'utf8'); + const rootPackageJson = JSON.parse(rootPackageJsonString); + if (_.isUndefined(rootPackageJson.workspaces)) { + throw new Error(`Did not find 'workspaces' key in root package.json`); + } + const lernaPackages = []; + for (const workspace of rootPackageJson.workspaces) { + const workspacePath = workspace.replace('*', ''); + const subpackageNames = fs.readdirSync(`${rootDir}/${workspacePath}`); + for (const subpackageName of subpackageNames) { + if (_.startsWith(subpackageName, '.')) { + continue; + } + const pathToPackageJson = `${rootDir}/${workspacePath}${subpackageName}`; + try { + const packageJsonString = fs.readFileSync(`${pathToPackageJson}/package.json`, 'utf8'); + const packageJson = JSON.parse(packageJsonString); + const lernaPackage = { + location: pathToPackageJson, + package: packageJson, + }; + lernaPackages.push(lernaPackage); + } catch (err) { + utils.log(`Couldn't find a 'package.json' for ${subpackageName}. Skipping...`); + } + } + } + return lernaPackages; + }, async getUpdatedLernaPackagesAsync(shouldIncludePrivate: boolean): Promise { const updatedPublicPackages = await utils.getLernaUpdatedPackagesAsync(shouldIncludePrivate); const updatedPackageNames = _.map(updatedPublicPackages, pkg => pkg.name); - const allLernaPackages = lernaGetPackages(constants.monorepoRootPath); + const allLernaPackages = utils.getLernaPackages(constants.monorepoRootPath); const updatedPublicLernaPackages = _.filter(allLernaPackages, pkg => { return _.includes(updatedPackageNames, pkg.package.name); }); -- cgit v1.2.3 From 74c0fd419b74cdc959add175f575f52306518140 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 19 Jul 2018 15:51:38 +0200 Subject: Upgrade Lerna to 3.0-Beta14 --- 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 3aaf881cb..f08313bd2 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', 'bin', 'lerna.js'), + lernaExecutable: path.join('node_modules', 'lerna', 'cli.js'), githubPersonalAccessToken: process.env.GITHUB_PERSONAL_ACCESS_TOKEN_0X_JS, }; -- cgit v1.2.3 From 7d840c7a1825f9aad16f3ab644e6f31819fefd59 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 19 Jul 2018 16:26:00 +0200 Subject: Remove unused declaration --- packages/monorepo-scripts/src/globals.d.ts | 1 - 1 file changed, 1 deletion(-) (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 ccdf90d2a..cb6a61b55 100644 --- a/packages/monorepo-scripts/src/globals.d.ts +++ b/packages/monorepo-scripts/src/globals.d.ts @@ -14,4 +14,3 @@ declare module 'semver-sort' { } declare module 'promisify-child-process'; -declare module '@lerna/project'; -- cgit v1.2.3 From 1df9370bc21e93267b5432668967118d7001abf2 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 19 Jul 2018 16:26:45 +0200 Subject: Renames to remove mention of Lerna --- .../src/find_unused_dependencies.ts | 10 ++--- packages/monorepo-scripts/src/prepublish_checks.ts | 44 +++++++++++----------- packages/monorepo-scripts/src/publish.ts | 35 ++++++++--------- packages/monorepo-scripts/src/test_installation.ts | 15 +++----- packages/monorepo-scripts/src/types.ts | 4 +- packages/monorepo-scripts/src/utils/utils.ts | 24 ++++++------ 6 files changed, 64 insertions(+), 68 deletions(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/find_unused_dependencies.ts b/packages/monorepo-scripts/src/find_unused_dependencies.ts index 1a36aceee..4bb4b7dc5 100644 --- a/packages/monorepo-scripts/src/find_unused_dependencies.ts +++ b/packages/monorepo-scripts/src/find_unused_dependencies.ts @@ -12,15 +12,15 @@ const IGNORE_PACKAGES = ['@0xproject/sol-compiler']; (async () => { utils.log('*** NOTE: Not all deps listed here are actually not required. ***'); utils.log("*** `depcheck` isn't perfect so double check before actually removing any. ***\n"); - const lernaPackages = utils.getLernaPackages(constants.monorepoRootPath); - for (const lernaPackage of lernaPackages) { - if (_.includes(IGNORE_PACKAGES, lernaPackage.package.name)) { + const packages = utils.getPackages(constants.monorepoRootPath); + for (const pkg of packages) { + if (_.includes(IGNORE_PACKAGES, pkg.packageJson.name)) { continue; // skip } - utils.log(`Checking ${lernaPackage.package.name} for unused deps. This might take a while...`); + utils.log(`Checking ${pkg.packageJson.name} for unused deps. This might take a while...`); const configs = {}; - const { dependencies } = await depcheckAsync(lernaPackage.location, configs); + const { dependencies } = await depcheckAsync(pkg.location, configs); if (!_.isEmpty(dependencies)) { _.each(dependencies, dep => { utils.log(dep); diff --git a/packages/monorepo-scripts/src/prepublish_checks.ts b/packages/monorepo-scripts/src/prepublish_checks.ts index 81b2f414b..431e848ca 100644 --- a/packages/monorepo-scripts/src/prepublish_checks.ts +++ b/packages/monorepo-scripts/src/prepublish_checks.ts @@ -4,35 +4,33 @@ import semver = require('semver'); import semverSort = require('semver-sort'); import { constants } from './constants'; -import { LernaPackage } from './types'; +import { Package } from './types'; import { changelogUtils } from './utils/changelog_utils'; import { npmUtils } from './utils/npm_utils'; import { utils } from './utils/utils'; async function prepublishChecksAsync(): Promise { const shouldIncludePrivate = false; - const updatedPublicLernaPackages = await utils.getUpdatedLernaPackagesAsync(shouldIncludePrivate); + const updatedPublicPackages = await utils.getUpdatedPackagesAsync(shouldIncludePrivate); - await checkCurrentVersionMatchesLatestPublishedNPMPackageAsync(updatedPublicLernaPackages); - await checkChangelogFormatAsync(updatedPublicLernaPackages); - await checkGitTagsForNextVersionAndDeleteIfExistAsync(updatedPublicLernaPackages); + await checkCurrentVersionMatchesLatestPublishedNPMPackageAsync(updatedPublicPackages); + await checkChangelogFormatAsync(updatedPublicPackages); + await checkGitTagsForNextVersionAndDeleteIfExistAsync(updatedPublicPackages); await checkPublishRequiredSetupAsync(); } -async function checkGitTagsForNextVersionAndDeleteIfExistAsync( - updatedPublicLernaPackages: LernaPackage[], -): Promise { - const packageNames = _.map(updatedPublicLernaPackages, lernaPackage => lernaPackage.package.name); +async function checkGitTagsForNextVersionAndDeleteIfExistAsync(updatedPublicPackages: Package[]): Promise { + const packageNames = _.map(updatedPublicPackages, pkg => pkg.packageJson.name); const localGitTags = await utils.getLocalGitTagsAsync(); const localTagVersionsByPackageName = await utils.getGitTagsByPackageNameAsync(packageNames, localGitTags); const remoteGitTags = await utils.getRemoteGitTagsAsync(); const remoteTagVersionsByPackageName = await utils.getGitTagsByPackageNameAsync(packageNames, remoteGitTags); - for (const lernaPackage of updatedPublicLernaPackages) { - const currentVersion = lernaPackage.package.version; - const packageName = lernaPackage.package.name; - const packageLocation = lernaPackage.location; + for (const pkg of updatedPublicPackages) { + const currentVersion = pkg.packageJson.version; + const packageName = pkg.packageJson.name; + const packageLocation = pkg.location; const nextVersion = await utils.getNextPackageVersionAsync(currentVersion, packageName, packageLocation); const remoteTagVersions = remoteTagVersionsByPackageName[packageName]; @@ -50,13 +48,13 @@ async function checkGitTagsForNextVersionAndDeleteIfExistAsync( } async function checkCurrentVersionMatchesLatestPublishedNPMPackageAsync( - updatedPublicLernaPackages: LernaPackage[], + updatedPublicPackages: Package[], ): Promise { utils.log('Check package versions against npmjs.org...'); const versionMismatches = []; - for (const lernaPackage of updatedPublicLernaPackages) { - const packageName = lernaPackage.package.name; - const packageVersion = lernaPackage.package.version; + for (const pkg of updatedPublicPackages) { + const packageName = pkg.packageJson.name; + const packageVersion = pkg.packageJson.version; const packageRegistryJsonIfExists = await npmUtils.getPackageRegistryJsonIfExistsAsync(packageName); if (_.isUndefined(packageRegistryJsonIfExists)) { continue; // noop for packages not yet published to NPM @@ -85,14 +83,14 @@ async function checkCurrentVersionMatchesLatestPublishedNPMPackageAsync( } } -async function checkChangelogFormatAsync(updatedPublicLernaPackages: LernaPackage[]): Promise { +async function checkChangelogFormatAsync(updatedPublicPackages: Package[]): Promise { utils.log('Check CHANGELOGs for inconsistencies...'); const changeLogInconsistencies = []; - for (const lernaPackage of updatedPublicLernaPackages) { - const packageName = lernaPackage.package.name; - const changelog = changelogUtils.getChangelogOrCreateIfMissing(packageName, lernaPackage.location); + for (const pkg of updatedPublicPackages) { + const packageName = pkg.packageJson.name; + const changelog = changelogUtils.getChangelogOrCreateIfMissing(packageName, pkg.location); - const currentVersion = lernaPackage.package.version; + const currentVersion = pkg.packageJson.version; if (!_.isEmpty(changelog)) { const lastEntry = changelog[0]; const doesLastEntryHaveTimestamp = !_.isUndefined(lastEntry.timestamp); @@ -106,7 +104,7 @@ async function checkChangelogFormatAsync(updatedPublicLernaPackages: LernaPackag // Remove incorrectly added timestamp delete changelog[0].timestamp; // Save updated CHANGELOG.json - await changelogUtils.writeChangelogJsonFileAsync(lernaPackage.location, changelog); + await changelogUtils.writeChangelogJsonFileAsync(pkg.location, changelog); utils.log(`${packageName}: Removed timestamp from latest CHANGELOG.json entry.`); } } diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 94b67eab3..c44e1f85e 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 { LernaPackage, PackageToVersionChange, SemVerIndex, VersionChangelog } from './types'; +import { Package, PackageToVersionChange, SemVerIndex, VersionChangelog } from './types'; import { changelogUtils } from './utils/changelog_utils'; import { utils } from './utils/utils'; @@ -34,19 +34,20 @@ const packageNameToWebsitePath: { [name: string]: string } = { 'sol-cov': 'sol-cov', subproviders: 'subproviders', 'order-utils': 'order-utils', + 'ethereum-types': 'ethereum-types', }; (async () => { // Fetch public, updated Lerna packages const shouldIncludePrivate = false; - const updatedPublicLernaPackages = await utils.getUpdatedLernaPackagesAsync(shouldIncludePrivate); + const updatedPublicPackages = await utils.getUpdatedPackagesAsync(shouldIncludePrivate); - await confirmDocPagesRenderAsync(updatedPublicLernaPackages); + await confirmDocPagesRenderAsync(updatedPublicPackages); // Update CHANGELOGs - const updatedPublicLernaPackageNames = _.map(updatedPublicLernaPackages, pkg => pkg.package.name); - utils.log(`Will update CHANGELOGs and publish: \n${updatedPublicLernaPackageNames.join('\n')}\n`); - const packageToVersionChange = await updateChangeLogsAsync(updatedPublicLernaPackages); + 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); // Push changelog changes to Github if (!IS_DRY_RUN) { @@ -65,7 +66,7 @@ const packageNameToWebsitePath: { [name: string]: string } = { process.exit(1); }); -async function confirmDocPagesRenderAsync(packages: LernaPackage[]): Promise { +async function confirmDocPagesRenderAsync(packages: Package[]): Promise { // push docs to staging utils.log("Upload all docJson's to S3 staging..."); await execAsync(`yarn stage_docs`, { cwd: constants.monorepoRootPath }); @@ -76,14 +77,14 @@ async function confirmDocPagesRenderAsync(packages: LernaPackage[]): Promise { - const scriptsIfExists = pkg.package.scripts; + const scriptsIfExists = pkg.packageJson.scripts; if (_.isUndefined(scriptsIfExists)) { throw new Error('Found a public package without any scripts in package.json'); } return !_.isUndefined(scriptsIfExists[DOC_GEN_COMMAND]); }); _.each(packagesWithDocs, pkg => { - const name = pkg.package.name; + const name = pkg.packageJson.name; const nameWithoutPrefix = _.startsWith(name, NPM_NAMESPACE) ? name.split('@0xproject/')[1] : name; const docSegmentIfExists = packageNameToWebsitePath[nameWithoutPrefix]; if (_.isUndefined(docSegmentIfExists)) { @@ -114,15 +115,15 @@ async function pushChangelogsToGithubAsync(): Promise { utils.log(`Pushed CHANGELOG updates to Github`); } -async function updateChangeLogsAsync(updatedPublicLernaPackages: LernaPackage[]): Promise { +async function updateChangeLogsAsync(updatedPublicPackages: Package[]): Promise { const packageToVersionChange: PackageToVersionChange = {}; - for (const lernaPackage of updatedPublicLernaPackages) { - const packageName = lernaPackage.package.name; - let changelog = changelogUtils.getChangelogOrCreateIfMissing(packageName, lernaPackage.location); + for (const pkg of updatedPublicPackages) { + const packageName = pkg.packageJson.name; + let changelog = changelogUtils.getChangelogOrCreateIfMissing(packageName, pkg.location); - const currentVersion = lernaPackage.package.version; + const currentVersion = pkg.packageJson.version; const shouldAddNewEntry = changelogUtils.shouldAddNewChangelogEntry( - lernaPackage.package.name, + pkg.packageJson.name, currentVersion, changelog, ); @@ -157,11 +158,11 @@ async function updateChangeLogsAsync(updatedPublicLernaPackages: LernaPackage[]) } // Save updated CHANGELOG.json - await changelogUtils.writeChangelogJsonFileAsync(lernaPackage.location, changelog); + await changelogUtils.writeChangelogJsonFileAsync(pkg.location, changelog); utils.log(`${packageName}: Updated CHANGELOG.json`); // Generate updated CHANGELOG.md const changelogMd = changelogUtils.generateChangelogMd(changelog); - await changelogUtils.writeChangelogMdFileAsync(lernaPackage.location, changelogMd); + await changelogUtils.writeChangelogMdFileAsync(pkg.location, changelogMd); utils.log(`${packageName}: Updated CHANGELOG.md`); } diff --git a/packages/monorepo-scripts/src/test_installation.ts b/packages/monorepo-scripts/src/test_installation.ts index 34d065c58..668d4ef1d 100644 --- a/packages/monorepo-scripts/src/test_installation.ts +++ b/packages/monorepo-scripts/src/test_installation.ts @@ -10,17 +10,14 @@ import { utils } from './utils/utils'; (async () => { const monorepoRootPath = path.join(__dirname, '../../..'); - const lernaPackages = utils.getLernaPackages(monorepoRootPath); + const packages = utils.getPackages(monorepoRootPath); const installablePackages = _.filter( - lernaPackages, - lernaPackage => - !lernaPackage.package.private && - !_.isUndefined(lernaPackage.package.main) && - lernaPackage.package.main.endsWith('.js'), + packages, + pkg => !pkg.packageJson.private && !_.isUndefined(pkg.packageJson.main) && pkg.packageJson.main.endsWith('.js'), ); - for (const installableLernaPackage of installablePackages) { - const packagePath = installableLernaPackage.location; - const packageName = installableLernaPackage.package.name; + for (const installablePackage of installablePackages) { + const packagePath = installablePackage.location; + const packageName = installablePackage.packageJson.name; utils.log(`Testing ${packageName}`); let result = await execAsync('npm pack', { cwd: packagePath }); const packedPackageFileName = result.stdout.trim(); diff --git a/packages/monorepo-scripts/src/types.ts b/packages/monorepo-scripts/src/types.ts index 052a38d1f..9f991c86c 100644 --- a/packages/monorepo-scripts/src/types.ts +++ b/packages/monorepo-scripts/src/types.ts @@ -41,9 +41,9 @@ export interface GitTagsByPackageName { [packageName: string]: string[]; } -export interface LernaPackage { +export interface Package { location: string; - package: { + packageJson: { private?: boolean; version: string; name: string; diff --git a/packages/monorepo-scripts/src/utils/utils.ts b/packages/monorepo-scripts/src/utils/utils.ts index 78bac1e4e..f04b9b671 100644 --- a/packages/monorepo-scripts/src/utils/utils.ts +++ b/packages/monorepo-scripts/src/utils/utils.ts @@ -4,7 +4,7 @@ import { exec as execAsync } from 'promisify-child-process'; import semver = require('semver'); import { constants } from '../constants'; -import { GitTagsByPackageName, LernaPackage, UpdatedPackage } from '../types'; +import { GitTagsByPackageName, Package, UpdatedPackage } from '../types'; import { changelogUtils } from './changelog_utils'; @@ -12,13 +12,13 @@ export const utils = { log(...args: any[]): void { console.log(...args); // tslint:disable-line:no-console }, - getLernaPackages(rootDir: string): LernaPackage[] { + getPackages(rootDir: string): Package[] { const rootPackageJsonString = fs.readFileSync(`${rootDir}/package.json`, 'utf8'); const rootPackageJson = JSON.parse(rootPackageJsonString); if (_.isUndefined(rootPackageJson.workspaces)) { throw new Error(`Did not find 'workspaces' key in root package.json`); } - const lernaPackages = []; + const packages = []; for (const workspace of rootPackageJson.workspaces) { const workspacePath = workspace.replace('*', ''); const subpackageNames = fs.readdirSync(`${rootDir}/${workspacePath}`); @@ -30,27 +30,27 @@ export const utils = { try { const packageJsonString = fs.readFileSync(`${pathToPackageJson}/package.json`, 'utf8'); const packageJson = JSON.parse(packageJsonString); - const lernaPackage = { + const pkg = { location: pathToPackageJson, - package: packageJson, + packageJson, }; - lernaPackages.push(lernaPackage); + packages.push(pkg); } catch (err) { utils.log(`Couldn't find a 'package.json' for ${subpackageName}. Skipping...`); } } } - return lernaPackages; + return packages; }, - async getUpdatedLernaPackagesAsync(shouldIncludePrivate: boolean): Promise { + async getUpdatedPackagesAsync(shouldIncludePrivate: boolean): Promise { const updatedPublicPackages = await utils.getLernaUpdatedPackagesAsync(shouldIncludePrivate); const updatedPackageNames = _.map(updatedPublicPackages, pkg => pkg.name); - const allLernaPackages = utils.getLernaPackages(constants.monorepoRootPath); - const updatedPublicLernaPackages = _.filter(allLernaPackages, pkg => { - return _.includes(updatedPackageNames, pkg.package.name); + const allPackages = utils.getPackages(constants.monorepoRootPath); + const updatedPackages = _.filter(allPackages, pkg => { + return _.includes(updatedPackageNames, pkg.packageJson.name); }); - return updatedPublicLernaPackages; + return updatedPackages; }, async getLernaUpdatedPackagesAsync(shouldIncludePrivate: boolean): Promise { const result = await execAsync(`${constants.lernaExecutable} updated --json`, { -- cgit v1.2.3 From f9c4d0925ea18290c6a578b2d42aa9d41c1f680f Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 19 Jul 2018 16:32:03 +0200 Subject: Add additional pattern removal and added HACK comment --- packages/monorepo-scripts/src/utils/utils.ts | 4 +++- 1 file changed, 3 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 f04b9b671..862656fbf 100644 --- a/packages/monorepo-scripts/src/utils/utils.ts +++ b/packages/monorepo-scripts/src/utils/utils.ts @@ -20,7 +20,9 @@ export const utils = { } const packages = []; for (const workspace of rootPackageJson.workspaces) { - const workspacePath = workspace.replace('*', ''); + // HACK: Remove allowed wildcards from workspace entries. + // This might be entirely comprehensive. + const workspacePath = workspace.replace('*', '').replace('**/*', ''); const subpackageNames = fs.readdirSync(`${rootDir}/${workspacePath}`); for (const subpackageName of subpackageNames) { if (_.startsWith(subpackageName, '.')) { -- cgit v1.2.3 From 9ab6ab1bf99864510fe2a0ed7296d04e103bde65 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 19 Jul 2018 17:22:26 +0200 Subject: Improve log --- packages/monorepo-scripts/src/utils/utils.ts | 2 +- 1 file changed, 1 insertion(+), 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 862656fbf..8ba59c81d 100644 --- a/packages/monorepo-scripts/src/utils/utils.ts +++ b/packages/monorepo-scripts/src/utils/utils.ts @@ -38,7 +38,7 @@ export const utils = { }; packages.push(pkg); } catch (err) { - utils.log(`Couldn't find a 'package.json' for ${subpackageName}. Skipping...`); + utils.log(`Couldn't find a 'package.json' for ${subpackageName}. Skipping.`); } } } -- cgit v1.2.3 From 3883315447a1681848b19aba1719d8015c7df693 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 19 Jul 2018 21:39:19 +0200 Subject: Make PR numbers links on Github releases --- packages/monorepo-scripts/src/postpublish_utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 85b32ed83..3ecb7b7c5 100644 --- a/packages/monorepo-scripts/src/postpublish_utils.ts +++ b/packages/monorepo-scripts/src/postpublish_utils.ts @@ -128,7 +128,7 @@ export const postpublishUtils = { _.each(latestLog.changes, change => { notes += `* ${change.note}`; if (change.pr) { - notes += ` (${change.pr})`; + notes += ` (#${change.pr})`; } notes += `\n`; }); -- cgit v1.2.3 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 From d836b0f81502baae5cfbd8949560e7f5ec37f780 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 25 Jul 2018 22:34:26 +0200 Subject: Also skip prompt when publishing for real --- packages/monorepo-scripts/src/publish.ts | 4 ++-- 1 file changed, 2 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 d1df4c56e..5992131db 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -184,9 +184,9 @@ async function lernaPublishAsync(packageToNextVersion: { [name: string]: string }).join(','); let lernaPublishCmd = `node ${constants.lernaExecutable} publish --cdVersions=${packageVersionString} --registry=${ configs.NPM_REGISTRY_URL - }`; + } --yes`; if (configs.IS_LOCAL_PUBLISH) { - lernaPublishCmd += ` --skip-git --yes`; + lernaPublishCmd += ` --skip-git`; } utils.log('Lerna is publishing...'); await execAsync(lernaPublishCmd, { cwd: constants.monorepoRootPath }); -- cgit v1.2.3 From 88ee35d5f9a3d5497c6ffcf5f751be40cbaf7a00 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 26 Jul 2018 12:14:13 +0200 Subject: Call 'lerna publish' with spawn so we see stderr and stdout in real-time --- packages/monorepo-scripts/src/publish.ts | 12 ++++++++++-- 1 file changed, 10 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 5992131db..8f140fc5a 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -4,7 +4,7 @@ import * as promisify from 'es6-promisify'; import * as _ from 'lodash'; import * as moment from 'moment'; import opn = require('opn'); -import { exec as execAsync } from 'promisify-child-process'; +import { exec as execAsync, spawn as spawnAsync } from 'promisify-child-process'; import * as prompt from 'prompt'; import semver = require('semver'); import semverSort = require('semver-sort'); @@ -189,7 +189,15 @@ async function lernaPublishAsync(packageToNextVersion: { [name: string]: string lernaPublishCmd += ` --skip-git`; } utils.log('Lerna is publishing...'); - await execAsync(lernaPublishCmd, { cwd: constants.monorepoRootPath }); + const child = await spawnAsync(lernaPublishCmd, { cwd: constants.monorepoRootPath }); + child.stdout.on('data', (data: Buffer) => { + const output = data.toString('utf8'); + utils.log('Stdout: ', output); + }); + child.stderr.on('data', (data: Buffer) => { + const output = data.toString('utf8'); + utils.log('Stderr: ', output); + }); } function updateVersionNumberIfNeeded(currentVersion: string, proposedNextVersion: string): string { -- cgit v1.2.3 From 2ae6a71ca3ddeaa721b9484d9d0448fc9e9c2056 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 26 Jul 2018 13:27:21 +0200 Subject: Revert to using execAsync --- packages/monorepo-scripts/src/publish.ts | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 8f140fc5a..5992131db 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -4,7 +4,7 @@ import * as promisify from 'es6-promisify'; import * as _ from 'lodash'; import * as moment from 'moment'; import opn = require('opn'); -import { exec as execAsync, spawn as spawnAsync } from 'promisify-child-process'; +import { exec as execAsync } from 'promisify-child-process'; import * as prompt from 'prompt'; import semver = require('semver'); import semverSort = require('semver-sort'); @@ -189,15 +189,7 @@ async function lernaPublishAsync(packageToNextVersion: { [name: string]: string lernaPublishCmd += ` --skip-git`; } utils.log('Lerna is publishing...'); - const child = await spawnAsync(lernaPublishCmd, { cwd: constants.monorepoRootPath }); - child.stdout.on('data', (data: Buffer) => { - const output = data.toString('utf8'); - utils.log('Stdout: ', output); - }); - child.stderr.on('data', (data: Buffer) => { - const output = data.toString('utf8'); - utils.log('Stderr: ', output); - }); + await execAsync(lernaPublishCmd, { cwd: constants.monorepoRootPath }); } function updateVersionNumberIfNeeded(currentVersion: string, proposedNextVersion: string): string { -- cgit v1.2.3 From e320f343f8d18a301bc1d74dcb2816e3d1e3be6f Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 26 Jul 2018 14:14:14 +0200 Subject: Add support for testing installations post-publish as well --- packages/monorepo-scripts/src/test_installation.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 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 a9610e5ee..12c0e7603 100644 --- a/packages/monorepo-scripts/src/test_installation.ts +++ b/packages/monorepo-scripts/src/test_installation.ts @@ -9,6 +9,8 @@ import * as rimraf from 'rimraf'; import { utils } from './utils/utils'; (async () => { + const IS_LOCAL_PUBLISH = process.env.IS_LOCAL_PUBLISH === 'true'; + const registry = IS_LOCAL_PUBLISH ? 'http://localhost:4873' : 'https://registry.npmjs.org'; const monorepoRootPath = path.join(__dirname, '../../..'); const packages = utils.getTopologicallySortedPackages(monorepoRootPath); const installablePackages = _.filter( @@ -26,9 +28,9 @@ import { utils } from './utils/utils'; fs.mkdirSync(testDirectory); await execAsync('yarn init --yes', { cwd: testDirectory }); const npmrcFilePath = path.join(testDirectory, '.npmrc'); - fs.writeFileSync(npmrcFilePath, `registry=http://localhost:4873`); + fs.writeFileSync(npmrcFilePath, `registry=${registry}`); utils.log(`Installing ${packageName}@${lastChangelogVersion}`); - await execAsync(`npm install --save ${packageName}@${lastChangelogVersion} --registry=http://localhost:4873`, { + await execAsync(`npm install --save ${packageName}@${lastChangelogVersion} --registry=${registry}`, { cwd: testDirectory, }); const indexFilePath = path.join(testDirectory, 'index.ts'); -- cgit v1.2.3 From d3be4f2852ca5bb35e50d27403715354b7485c4b Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 26 Jul 2018 14:22:51 +0200 Subject: Add ending slash --- packages/monorepo-scripts/src/test_installation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 12c0e7603..55ff12083 100644 --- a/packages/monorepo-scripts/src/test_installation.ts +++ b/packages/monorepo-scripts/src/test_installation.ts @@ -10,7 +10,7 @@ import { utils } from './utils/utils'; (async () => { const IS_LOCAL_PUBLISH = process.env.IS_LOCAL_PUBLISH === 'true'; - const registry = IS_LOCAL_PUBLISH ? 'http://localhost:4873' : 'https://registry.npmjs.org'; + const registry = IS_LOCAL_PUBLISH ? 'http://localhost:4873/' : 'https://registry.npmjs.org/'; const monorepoRootPath = path.join(__dirname, '../../..'); const packages = utils.getTopologicallySortedPackages(monorepoRootPath); const installablePackages = _.filter( -- cgit v1.2.3 From 9947e643d0b201a0dad122fbe1a6f4a226469944 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 26 Jul 2018 14:23:07 +0200 Subject: Print version that will be tested --- packages/monorepo-scripts/src/test_installation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 55ff12083..1d9e3569d 100644 --- a/packages/monorepo-scripts/src/test_installation.ts +++ b/packages/monorepo-scripts/src/test_installation.ts @@ -23,7 +23,7 @@ import { utils } from './utils/utils'; const changelogPath = path.join(installablePackage.location, 'CHANGELOG.json'); const lastChangelogVersion = JSON.parse(fs.readFileSync(changelogPath).toString())[0].version; const packageName = installablePackage.packageJson.name; - utils.log(`Testing ${packageName}`); + utils.log(`Testing ${packageName}@${lastChangelogVersion}`); const testDirectory = path.join(monorepoRootPath, '../test-env'); fs.mkdirSync(testDirectory); await execAsync('yarn init --yes', { cwd: testDirectory }); -- cgit v1.2.3 From af4071e119b4cb651ae311ea1200fdd76f8123e7 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 26 Jul 2018 14:23:45 +0200 Subject: Delete any remenants of test-env dir before creating a new one --- packages/monorepo-scripts/src/test_installation.ts | 1 + 1 file changed, 1 insertion(+) (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 1d9e3569d..b10db5a06 100644 --- a/packages/monorepo-scripts/src/test_installation.ts +++ b/packages/monorepo-scripts/src/test_installation.ts @@ -25,6 +25,7 @@ import { utils } from './utils/utils'; const packageName = installablePackage.packageJson.name; utils.log(`Testing ${packageName}@${lastChangelogVersion}`); const testDirectory = path.join(monorepoRootPath, '../test-env'); + rimraf.sync(testDirectory); fs.mkdirSync(testDirectory); await execAsync('yarn init --yes', { cwd: testDirectory }); const npmrcFilePath = path.join(testDirectory, '.npmrc'); -- cgit v1.2.3 From 55dbb0ece06d17a9db7b93a0ffa274ff65298002 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 26 Jul 2018 14:42:07 +0200 Subject: Always append monorepo root path so script can be called from anywhere --- packages/monorepo-scripts/src/postpublish_utils.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 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 37861f0dd..77def309e 100644 --- a/packages/monorepo-scripts/src/postpublish_utils.ts +++ b/packages/monorepo-scripts/src/postpublish_utils.ts @@ -96,7 +96,7 @@ export const postpublishUtils = { const notes = postpublishUtils.getReleaseNotes(packageName, version); const releaseName = postpublishUtils.getReleaseName(packageName, version); const tag = postpublishUtils.getTag(packageName, version); - postpublishUtils.adjustAssetPaths(cwd, assets); + postpublishUtils.adjustAssetPaths(assets); utils.log('POSTPUBLISH: Releasing ', releaseName, '...'); await publishReleaseAsync({ token: constants.githubPersonalAccessToken, @@ -145,10 +145,12 @@ export const postpublishUtils = { const releaseName = `${subPackageName} v${version}`; return releaseName; }, - adjustAssetPaths(cwd: string, assets: string[]): string[] { + // Asset paths should described from the monorepo root. This method prefixes + // the supplied path with the absolute path to the monorepo root. + adjustAssetPaths(assets: string[]): string[] { const finalAssets: string[] = []; _.each(assets, (asset: string) => { - finalAssets.push(`${cwd}/${asset}`); + finalAssets.push(`${constants.monorepoRootPath}/${asset}`); }); return finalAssets; }, -- cgit v1.2.3 From 331b1cb9a0edd8809c82393ed482674e61a76636 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 26 Jul 2018 15:27:50 +0200 Subject: Fix lint issue --- packages/monorepo-scripts/src/postpublish_utils.ts | 3 +-- 1 file changed, 1 insertion(+), 2 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 77def309e..8e445a045 100644 --- a/packages/monorepo-scripts/src/postpublish_utils.ts +++ b/packages/monorepo-scripts/src/postpublish_utils.ts @@ -57,7 +57,6 @@ export const postpublishUtils = { } const postpublishConfigs = postpublishUtils.generateConfig(packageJSON, tsConfigJSON, cwd); await postpublishUtils.publishReleaseNotesAsync( - postpublishConfigs.cwd, postpublishConfigs.packageName, postpublishConfigs.version, postpublishConfigs.assets, @@ -92,7 +91,7 @@ export const postpublishUtils = { postpublishConfigs.docPublishConfigs.s3StagingBucketPath, ); }, - async publishReleaseNotesAsync(cwd: string, packageName: string, version: string, assets: string[]): Promise { + async publishReleaseNotesAsync(packageName: string, version: string, assets: string[]): Promise { const notes = postpublishUtils.getReleaseNotes(packageName, version); const releaseName = postpublishUtils.getReleaseName(packageName, version); const tag = postpublishUtils.getTag(packageName, version); -- cgit v1.2.3 From e3cfa6363daf8b46b231fb38fc1bf6c8e13db17b Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 26 Jul 2018 15:32:30 +0200 Subject: Change test:installation so it also causes run-time errors to appear --- packages/monorepo-scripts/src/test_installation.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 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 b10db5a06..4c92d0aa2 100644 --- a/packages/monorepo-scripts/src/test_installation.ts +++ b/packages/monorepo-scripts/src/test_installation.ts @@ -13,11 +13,14 @@ import { utils } from './utils/utils'; const registry = IS_LOCAL_PUBLISH ? 'http://localhost:4873/' : 'https://registry.npmjs.org/'; const monorepoRootPath = path.join(__dirname, '../../..'); const packages = utils.getTopologicallySortedPackages(monorepoRootPath); - const installablePackages = _.filter( + const preInstallablePackages = _.filter( packages, pkg => !pkg.packageJson.private && !_.isUndefined(pkg.packageJson.main) && pkg.packageJson.main.endsWith('.js'), ); utils.log('Testing packages:'); + const installablePackages = _.filter(preInstallablePackages, pkg => { + return pkg.packageJson.name === '0x.js'; + }); _.map(installablePackages, pkg => utils.log(`* ${pkg.packageJson.name}`)); for (const installablePackage of installablePackages) { const changelogPath = path.join(installablePackage.location, 'CHANGELOG.json'); @@ -35,7 +38,7 @@ import { utils } from './utils/utils'; cwd: testDirectory, }); const indexFilePath = path.join(testDirectory, 'index.ts'); - fs.writeFileSync(indexFilePath, `import * as Package from '${packageName}';\n`); + fs.writeFileSync(indexFilePath, `import * as Package from '${packageName}';\nconsole.log(Package);\n`); const tsConfig = { compilerOptions: { typeRoots: ['node_modules/@0xproject/typescript-typings/types', 'node_modules/@types'], @@ -55,7 +58,11 @@ import { utils } from './utils/utils'; const tscBinaryPath = path.join(monorepoRootPath, './node_modules/typescript/bin/tsc'); await execAsync(tscBinaryPath, { cwd: testDirectory }); utils.log(`Successfully compiled with ${packageName} as a dependency`); - rimraf.sync(testDirectory); + const transpiledIndexFilePath = path.join(testDirectory, 'index.js'); + utils.log(`Running test script with ${packageName} imported`); + await execAsync(`node ${transpiledIndexFilePath}`); + utils.log(`Successfilly ran test script with ${packageName} imported`); + // rimraf.sync(testDirectory); } })().catch(err => { utils.log(err.stderr); -- cgit v1.2.3 From 735bc2f1789384c33c38db011148e5a98e7ba74e Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 26 Jul 2018 15:32:53 +0200 Subject: Re-enable deleted the dir after test runs --- packages/monorepo-scripts/src/test_installation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 4c92d0aa2..d1f5ce655 100644 --- a/packages/monorepo-scripts/src/test_installation.ts +++ b/packages/monorepo-scripts/src/test_installation.ts @@ -62,7 +62,7 @@ import { utils } from './utils/utils'; utils.log(`Running test script with ${packageName} imported`); await execAsync(`node ${transpiledIndexFilePath}`); utils.log(`Successfilly ran test script with ${packageName} imported`); - // rimraf.sync(testDirectory); + rimraf.sync(testDirectory); } })().catch(err => { utils.log(err.stderr); -- cgit v1.2.3 From a90f434df5718f45b8eb367a8fabde97ee3d0513 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 26 Jul 2018 15:58:35 +0200 Subject: Split running packages that cannot be run in a node.js script --- packages/monorepo-scripts/src/test_installation.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (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 d1f5ce655..bbaf9b056 100644 --- a/packages/monorepo-scripts/src/test_installation.ts +++ b/packages/monorepo-scripts/src/test_installation.ts @@ -8,6 +8,14 @@ import * as rimraf from 'rimraf'; import { utils } from './utils/utils'; +// Packages might not be runnable if they are command-line tools or only run in browsers. +const UNRUNNABLE_PACKAGES = [ + '@0xproject/abi-gen', + '@0xproject/sra-report', + '@0xproject/react-shared', + '@0xproject/react-docs', +]; + (async () => { const IS_LOCAL_PUBLISH = process.env.IS_LOCAL_PUBLISH === 'true'; const registry = IS_LOCAL_PUBLISH ? 'http://localhost:4873/' : 'https://registry.npmjs.org/'; @@ -19,7 +27,7 @@ import { utils } from './utils/utils'; ); utils.log('Testing packages:'); const installablePackages = _.filter(preInstallablePackages, pkg => { - return pkg.packageJson.name === '0x.js'; + return !_.includes(UNRUNNABLE_PACKAGES, pkg.packageJson.name); }); _.map(installablePackages, pkg => utils.log(`* ${pkg.packageJson.name}`)); for (const installablePackage of installablePackages) { -- cgit v1.2.3 From 0187e0c47df98bac67da135b55e2630e25ffd513 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 26 Jul 2018 16:20:20 +0200 Subject: Still test unrunnable packages for compilation issues --- packages/monorepo-scripts/src/test_installation.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 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 bbaf9b056..a8ddf0c58 100644 --- a/packages/monorepo-scripts/src/test_installation.ts +++ b/packages/monorepo-scripts/src/test_installation.ts @@ -21,14 +21,11 @@ const UNRUNNABLE_PACKAGES = [ const registry = IS_LOCAL_PUBLISH ? 'http://localhost:4873/' : 'https://registry.npmjs.org/'; const monorepoRootPath = path.join(__dirname, '../../..'); const packages = utils.getTopologicallySortedPackages(monorepoRootPath); - const preInstallablePackages = _.filter( + const installablePackages = _.filter( packages, pkg => !pkg.packageJson.private && !_.isUndefined(pkg.packageJson.main) && pkg.packageJson.main.endsWith('.js'), ); utils.log('Testing packages:'); - const installablePackages = _.filter(preInstallablePackages, pkg => { - return !_.includes(UNRUNNABLE_PACKAGES, pkg.packageJson.name); - }); _.map(installablePackages, pkg => utils.log(`* ${pkg.packageJson.name}`)); for (const installablePackage of installablePackages) { const changelogPath = path.join(installablePackage.location, 'CHANGELOG.json'); @@ -66,10 +63,13 @@ const UNRUNNABLE_PACKAGES = [ const tscBinaryPath = path.join(monorepoRootPath, './node_modules/typescript/bin/tsc'); await execAsync(tscBinaryPath, { cwd: testDirectory }); utils.log(`Successfully compiled with ${packageName} as a dependency`); - const transpiledIndexFilePath = path.join(testDirectory, 'index.js'); - utils.log(`Running test script with ${packageName} imported`); - await execAsync(`node ${transpiledIndexFilePath}`); - utils.log(`Successfilly ran test script with ${packageName} imported`); + const isUnrunnablePkg = _.includes(UNRUNNABLE_PACKAGES, packageName); + if (!isUnrunnablePkg) { + const transpiledIndexFilePath = path.join(testDirectory, 'index.js'); + utils.log(`Running test script with ${packageName} imported`); + await execAsync(`node ${transpiledIndexFilePath}`); + utils.log(`Successfilly ran test script with ${packageName} imported`); + } rimraf.sync(testDirectory); } })().catch(err => { -- cgit v1.2.3 From 797fd38e00e48abddc03be214984f81bf7b1c29c Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Wed, 8 Aug 2018 14:01:12 -0700 Subject: feat(monorepo-scripts): Add confirmation prompt before publishing --- packages/monorepo-scripts/src/publish.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'packages/monorepo-scripts/src') diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 5992131db..6ff0c9bef 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -31,12 +31,25 @@ const packageNameToWebsitePath: { [name: string]: string } = { 'ethereum-types': 'ethereum-types', }; +async function confirmAsync(message: string): Promise { + prompt.start(); + const result = await promisify(prompt.get)([message]); + const didConfirm = result[message] === 'y'; + if (!didConfirm) { + utils.log('Publish process aborted.'); + process.exit(0); + } +} + (async () => { // Fetch public, updated Lerna packages const shouldIncludePrivate = true; const allUpdatedPackages = await utils.getUpdatedPackagesAsync(shouldIncludePrivate); if (!configs.IS_LOCAL_PUBLISH) { + await confirmAsync( + 'THIS IS NOT A TEST PUBLISH! You are about to publish one or more packages to npm. Are you sure you want to continue? (y/n)', + ); await confirmDocPagesRenderAsync(allUpdatedPackages); } @@ -107,14 +120,7 @@ package.ts. Please add an entry for it and try again.`, opn(link); }); - prompt.start(); - const message = 'Do all the doc pages render properly? (yn)'; - const result = await promisify(prompt.get)([message]); - const didConfirm = result[message] === 'y'; - if (!didConfirm) { - utils.log('Publish process aborted.'); - process.exit(0); - } + await confirmAsync('Do all the doc pages render properly? (y/n)'); } async function pushChangelogsToGithubAsync(): Promise { -- cgit v1.2.3 From 5ccf41c56693aa45988001260b68fdad2124b12c Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Wed, 8 Aug 2018 14:01:57 -0700 Subject: fix(monorepo-scripts): Fix typo in git tag command --- packages/monorepo-scripts/src/utils/utils.ts | 2 +- 1 file changed, 1 insertion(+), 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 d9bae3ea9..26ac801bd 100644 --- a/packages/monorepo-scripts/src/utils/utils.ts +++ b/packages/monorepo-scripts/src/utils/utils.ts @@ -117,7 +117,7 @@ export const utils = { return tags; }, async getLocalGitTagsAsync(): Promise { - const result = await execAsync(`git tags`, { + const result = await execAsync(`git tag`, { cwd: constants.monorepoRootPath, }); const tagsString = result.stdout; -- cgit v1.2.3 From 283175df9827be38f8cc9f18d3914e3661456fc4 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Mon, 13 Aug 2018 16:49:50 -0700 Subject: Run publish/installation tests in CircleCI (#951) feat(monorepo-scripts): Run publish tests in CircleCI --- packages/monorepo-scripts/src/test_installation.ts | 163 +++++++++++++++------ 1 file changed, 117 insertions(+), 46 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 a8ddf0c58..87c4ad1d7 100644 --- a/packages/monorepo-scripts/src/test_installation.ts +++ b/packages/monorepo-scripts/src/test_installation.ts @@ -2,10 +2,13 @@ import * as fs from 'fs'; import * as _ from 'lodash'; +import * as mkdirp from 'mkdirp'; import * as path from 'path'; import { exec as execAsync } from 'promisify-child-process'; import * as rimraf from 'rimraf'; +import { promisify } from 'util'; +import { Package } from './types'; import { utils } from './utils/utils'; // Packages might not be runnable if they are command-line tools or only run in browsers. @@ -16,64 +19,132 @@ const UNRUNNABLE_PACKAGES = [ '@0xproject/react-docs', ]; +const mkdirpAsync = promisify(mkdirp); +const rimrafAsync = promisify(rimraf); +const writeFileAsync = promisify(fs.writeFile); + +interface PackageErr { + packageName: string; + error: ExecError; +} + +interface ExecError { + message: string; + stack: string; + stderr: string; + stdout: string; +} + +// returns the index for the given package name. +function findPackageIndex(packages: Package[], packageName: string): number { + return _.findIndex(packages, pkg => pkg.packageJson.name === packageName); +} + +function logIfDefined(x: any): void { + if (!_.isUndefined(x)) { + utils.log(x); + } +} + (async () => { const IS_LOCAL_PUBLISH = process.env.IS_LOCAL_PUBLISH === 'true'; const registry = IS_LOCAL_PUBLISH ? 'http://localhost:4873/' : 'https://registry.npmjs.org/'; const monorepoRootPath = path.join(__dirname, '../../..'); - const packages = utils.getTopologicallySortedPackages(monorepoRootPath); + const packages = utils.getPackages(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}`)); + // Run all package tests asynchronously and push promises into an array so + // we can wait for all of them to resolve. + const promises: Array> = []; + const errors: PackageErr[] = []; 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; - utils.log(`Testing ${packageName}@${lastChangelogVersion}`); - const testDirectory = path.join(monorepoRootPath, '../test-env'); - rimraf.sync(testDirectory); - fs.mkdirSync(testDirectory); - await execAsync('yarn init --yes', { cwd: testDirectory }); - const npmrcFilePath = path.join(testDirectory, '.npmrc'); - fs.writeFileSync(npmrcFilePath, `registry=${registry}`); - utils.log(`Installing ${packageName}@${lastChangelogVersion}`); - await execAsync(`npm install --save ${packageName}@${lastChangelogVersion} --registry=${registry}`, { - cwd: testDirectory, + const packagePromise = testInstallPackageAsync(monorepoRootPath, registry, installablePackage).catch(error => { + errors.push({ packageName: installablePackage.packageJson.name, error }); }); - const indexFilePath = path.join(testDirectory, 'index.ts'); - fs.writeFileSync(indexFilePath, `import * as Package from '${packageName}';\nconsole.log(Package);\n`); - const tsConfig = { - compilerOptions: { - typeRoots: ['node_modules/@0xproject/typescript-typings/types', 'node_modules/@types'], - module: 'commonjs', - target: 'es5', - lib: ['es2017', 'dom'], - declaration: true, - noImplicitReturns: true, - pretty: true, - strict: true, - }, - include: ['index.ts'], - }; - const tsconfigFilePath = path.join(testDirectory, 'tsconfig.json'); - fs.writeFileSync(tsconfigFilePath, JSON.stringify(tsConfig, null, '\t')); - utils.log(`Compiling ${packageName}`); - const tscBinaryPath = path.join(monorepoRootPath, './node_modules/typescript/bin/tsc'); - await execAsync(tscBinaryPath, { cwd: testDirectory }); - utils.log(`Successfully compiled with ${packageName} as a dependency`); - const isUnrunnablePkg = _.includes(UNRUNNABLE_PACKAGES, packageName); - if (!isUnrunnablePkg) { - const transpiledIndexFilePath = path.join(testDirectory, 'index.js'); - utils.log(`Running test script with ${packageName} imported`); - await execAsync(`node ${transpiledIndexFilePath}`); - utils.log(`Successfilly ran test script with ${packageName} imported`); - } - rimraf.sync(testDirectory); + promises.push(packagePromise); + } + await Promise.all(promises); + if (errors.length > 0) { + // We sort error messages according to package topology so that we can + // them in a more intuitive order. E.g. if package A has an error and + // package B imports it, the tests for both package A and package B will + // fail. But package B only fails because of an error in package A. + // Since the error in package A is the root cause, we log it first. + const topologicallySortedPackages = utils.getTopologicallySortedPackages(monorepoRootPath); + const topologicallySortedErrors = _.sortBy(errors, packageErr => + findPackageIndex(topologicallySortedPackages, packageErr.packageName), + ); + _.forEach(topologicallySortedErrors, packageError => { + utils.log(`ERROR in package ${packageError.packageName}:`); + logIfDefined(packageError.error.message); + logIfDefined(packageError.error.stderr); + logIfDefined(packageError.error.stdout); + logIfDefined(packageError.error.stack); + }); + process.exit(0); } })().catch(err => { - utils.log(err.stderr); - utils.log(err.stdout); - process.exit(1); + utils.log(`Unexpected error: ${err.message}`); + process.exit(0); }); + +async function testInstallPackageAsync( + monorepoRootPath: string, + registry: string, + installablePackage: Package, +): Promise { + const changelogPath = path.join(installablePackage.location, 'CHANGELOG.json'); + const lastChangelogVersion = JSON.parse(fs.readFileSync(changelogPath).toString())[0].version; + const packageName = installablePackage.packageJson.name; + utils.log(`Testing ${packageName}@${lastChangelogVersion}`); + const packageDirName = path.join(...(packageName + '-test').split('/')); + const testDirectory = path.join( + monorepoRootPath, + 'packages', + 'monorepo-scripts', + '.installation-test', + packageDirName, + ); + await rimrafAsync(testDirectory); + await mkdirpAsync(testDirectory); + await execAsync('yarn init --yes', { cwd: testDirectory }); + const npmrcFilePath = path.join(testDirectory, '.npmrc'); + await writeFileAsync(npmrcFilePath, `registry=${registry}`); + utils.log(`Installing ${packageName}@${lastChangelogVersion}`); + await execAsync(`npm install --save ${packageName}@${lastChangelogVersion} --registry=${registry}`, { + cwd: testDirectory, + }); + const indexFilePath = path.join(testDirectory, 'index.ts'); + await writeFileAsync(indexFilePath, `import * as Package from '${packageName}';\nconsole.log(Package);\n`); + const tsConfig = { + compilerOptions: { + typeRoots: ['node_modules/@0xproject/typescript-typings/types', 'node_modules/@types'], + module: 'commonjs', + target: 'es5', + lib: ['es2017', 'dom'], + declaration: true, + noImplicitReturns: true, + pretty: true, + strict: true, + }, + include: ['index.ts'], + }; + const tsconfigFilePath = path.join(testDirectory, 'tsconfig.json'); + await writeFileAsync(tsconfigFilePath, JSON.stringify(tsConfig, null, '\t')); + utils.log(`Compiling ${packageName}`); + const tscBinaryPath = path.join(monorepoRootPath, './node_modules/typescript/bin/tsc'); + await execAsync(tscBinaryPath, { cwd: testDirectory }); + utils.log(`Successfully compiled with ${packageName} as a dependency`); + const isUnrunnablePkg = _.includes(UNRUNNABLE_PACKAGES, packageName); + if (!isUnrunnablePkg) { + const transpiledIndexFilePath = path.join(testDirectory, 'index.js'); + utils.log(`Running test script with ${packageName} imported`); + await execAsync(`node ${transpiledIndexFilePath}`); + utils.log(`Successfilly ran test script with ${packageName} imported`); + } + await rimrafAsync(testDirectory); +} -- cgit v1.2.3