aboutsummaryrefslogtreecommitdiffstats
path: root/packages/monorepo-scripts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-04-04 02:57:42 +0800
committerFabio Berger <me@fabioberger.com>2018-04-04 02:57:42 +0800
commit61809130a6659335c7550cf35c55e20b3e579a6f (patch)
tree19ddd0c0312eed054595c0d3431ecddead18e857 /packages/monorepo-scripts
parentf5e6e0eaf7dfa1b50852e897948e89e18aa1716c (diff)
parent4a9752d7cda05f616d2709e34f4687da813d3090 (diff)
downloaddexon-sol-tools-61809130a6659335c7550cf35c55e20b3e579a6f.tar
dexon-sol-tools-61809130a6659335c7550cf35c55e20b3e579a6f.tar.gz
dexon-sol-tools-61809130a6659335c7550cf35c55e20b3e579a6f.tar.bz2
dexon-sol-tools-61809130a6659335c7550cf35c55e20b3e579a6f.tar.lz
dexon-sol-tools-61809130a6659335c7550cf35c55e20b3e579a6f.tar.xz
dexon-sol-tools-61809130a6659335c7550cf35c55e20b3e579a6f.tar.zst
dexon-sol-tools-61809130a6659335c7550cf35c55e20b3e579a6f.zip
Merge branch 'development' into removeUnusedDeps
* development: Temporarily remove installation test Fix package.json Remove `isPublished` from all CHANGELOG.json filesx 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. Remove temporary convert_changelog script # Conflicts: # packages/monorepo-scripts/package.json
Diffstat (limited to 'packages/monorepo-scripts')
-rw-r--r--packages/monorepo-scripts/CHANGELOG.json3
-rw-r--r--packages/monorepo-scripts/package.json2
-rw-r--r--packages/monorepo-scripts/src/convert_changelogs.ts99
-rw-r--r--packages/monorepo-scripts/src/postpublish_utils.ts44
-rw-r--r--packages/monorepo-scripts/src/publish.ts7
-rw-r--r--packages/monorepo-scripts/src/types.ts1
6 files changed, 20 insertions, 136 deletions
diff --git a/packages/monorepo-scripts/CHANGELOG.json b/packages/monorepo-scripts/CHANGELOG.json
index fdc3b8cce..05e1ce2a2 100644
--- a/packages/monorepo-scripts/CHANGELOG.json
+++ b/packages/monorepo-scripts/CHANGELOG.json
@@ -15,7 +15,6 @@
"note": "Add postpublish utils"
}
],
- "timestamp": 1521298800,
- "isPublished": true
+ "timestamp": 1521298800
}
]
diff --git a/packages/monorepo-scripts/package.json b/packages/monorepo-scripts/package.json
index ccdf6ca2e..b113b4b39 100644
--- a/packages/monorepo-scripts/package.json
+++ b/packages/monorepo-scripts/package.json
@@ -10,11 +10,9 @@
"clean": "shx rm -rf lib",
"build": "tsc",
"test:publish": "run-s build script:publish",
- "convert_changelogs": "run-s build script:convert_changelogs",
"find_unused_deps": "run-s build script:find_unused_deps",
"script:deps_versions": "node ./lib/deps_versions.js",
"script:publish": "IS_DRY_RUN=true node ./lib/publish.js",
- "script:convert_changelogs": "node ./lib/convert_changelogs.js",
"script:find_unused_deps": "node ./lib/find_unused_dependencies.js"
},
"repository": {
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;
- }
-}
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<void> {
- 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 {