aboutsummaryrefslogtreecommitdiffstats
path: root/packages/monorepo-scripts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-03-29 20:06:29 +0800
committerFabio Berger <me@fabioberger.com>2018-03-29 20:06:29 +0800
commit743c3dbe01b3ffaa1743c2907cbcab1d7ed78d72 (patch)
tree6c664f9b61aacaafef75233f2e9515dd22a7bbc0 /packages/monorepo-scripts
parent9f1c212596f04b61fedf90d5a896b5f4e44ce729 (diff)
downloaddexon-sol-tools-743c3dbe01b3ffaa1743c2907cbcab1d7ed78d72.tar
dexon-sol-tools-743c3dbe01b3ffaa1743c2907cbcab1d7ed78d72.tar.gz
dexon-sol-tools-743c3dbe01b3ffaa1743c2907cbcab1d7ed78d72.tar.bz2
dexon-sol-tools-743c3dbe01b3ffaa1743c2907cbcab1d7ed78d72.tar.lz
dexon-sol-tools-743c3dbe01b3ffaa1743c2907cbcab1d7ed78d72.tar.xz
dexon-sol-tools-743c3dbe01b3ffaa1743c2907cbcab1d7ed78d72.tar.zst
dexon-sol-tools-743c3dbe01b3ffaa1743c2907cbcab1d7ed78d72.zip
Generate CHANGELOG.json files and add convert_changelog script
Diffstat (limited to 'packages/monorepo-scripts')
-rw-r--r--packages/monorepo-scripts/CHANGELOG.json12
-rw-r--r--packages/monorepo-scripts/package.json3
-rw-r--r--packages/monorepo-scripts/src/convert_changelogs.ts80
-rw-r--r--packages/monorepo-scripts/src/types.ts17
4 files changed, 112 insertions, 0 deletions
diff --git a/packages/monorepo-scripts/CHANGELOG.json b/packages/monorepo-scripts/CHANGELOG.json
new file mode 100644
index 000000000..a8418d03f
--- /dev/null
+++ b/packages/monorepo-scripts/CHANGELOG.json
@@ -0,0 +1,12 @@
+[
+ {
+ "version": "0.1.13",
+ "changes": [
+ {
+ "note": "Add postpublish utils"
+ }
+ ],
+ "timestamp": 1521327600,
+ "isPublished": true
+ }
+] \ No newline at end of file
diff --git a/packages/monorepo-scripts/package.json b/packages/monorepo-scripts/package.json
index 5333e6cad..9dcb8ee14 100644
--- a/packages/monorepo-scripts/package.json
+++ b/packages/monorepo-scripts/package.json
@@ -7,6 +7,7 @@
"scripts": {
"build:watch": "tsc -w",
"deps_versions": "node ./lib/deps_versions.js",
+ "convert_changelogs": "yarn build; node ./lib/convert_changelogs.js",
"lint": "tslint --project . 'src/**/*.ts'",
"clean": "shx rm -rf lib",
"build": "tsc"
@@ -24,6 +25,7 @@
"devDependencies": {
"@0xproject/tslint-config": "0.4.8",
"@types/glob": "^5.0.33",
+ "@types/moment": "2.13.0",
"@types/node": "^8.0.53",
"@types/rimraf": "^2.0.2",
"lerna-get-packages": "^1.0.0",
@@ -37,6 +39,7 @@
"es6-promisify": "^5.0.0",
"glob": "^7.1.2",
"lodash": "^4.17.4",
+ "moment": "2.13.0",
"promisify-child-process": "^1.0.5",
"publish-release": "0xproject/publish-release",
"rimraf": "^2.6.2",
diff --git a/packages/monorepo-scripts/src/convert_changelogs.ts b/packages/monorepo-scripts/src/convert_changelogs.ts
new file mode 100644
index 000000000..419f36ff4
--- /dev/null
+++ b/packages/monorepo-scripts/src/convert_changelogs.ts
@@ -0,0 +1,80 @@
+#!/usr/bin/env node
+
+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 { Changelog, Changes, UpdatedPackage } from './types';
+import { utils } from './utils';
+
+const MONOREPO_ROOT_PATH = path.join(__dirname, '../../..');
+
+(async () => {
+ const allLernaPackages = lernaGetPackages(MONOREPO_ROOT_PATH);
+ const publicLernaPackages = _.filter(allLernaPackages, pkg => !pkg.package.private);
+ _.each(publicLernaPackages, lernaPackage => {
+ 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 as any).split('\n');
+ const changelogs: Changelog[] = [];
+ let changelog: Changelog = {
+ version: '',
+ changes: [],
+ };
+ for (const line of lines) {
+ if (_.startsWith(line, '## ')) {
+ const version = line.substr(4).split(' - ')[0];
+ 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 as any).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 = {
+ note,
+ pr,
+ };
+ changelog.changes.push(changes);
+ }
+ }
+ const changelogJson = JSON.stringify(changelogs, null, '\t');
+ fs.writeFileSync(`${lernaPackage.location}/CHANGELOG.json`, changelogJson);
+ });
+})().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) {
+ // If none exists, create new, empty one.
+ return undefined;
+ }
+}
diff --git a/packages/monorepo-scripts/src/types.ts b/packages/monorepo-scripts/src/types.ts
new file mode 100644
index 000000000..045316ab5
--- /dev/null
+++ b/packages/monorepo-scripts/src/types.ts
@@ -0,0 +1,17 @@
+export interface UpdatedPackage {
+ name: string;
+ version: string;
+ private: boolean;
+}
+
+export interface Changes {
+ note: string;
+ pr?: number;
+}
+
+export interface Changelog {
+ timestamp?: number;
+ version: string;
+ changes: Changes[];
+ isPublished?: boolean;
+}