Add temp comment, clean up code
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
#!/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');
|
||||
@@ -6,13 +11,14 @@ import * as _ from 'lodash';
|
||||
import * as moment from 'moment';
|
||||
import * as path from 'path';
|
||||
|
||||
import { constants } from './constants';
|
||||
import { Changelog, Changes, UpdatedPackage } from './types';
|
||||
import { utils } from './utils';
|
||||
|
||||
const MONOREPO_ROOT_PATH = path.join(__dirname, '../../..');
|
||||
const HEADER_PRAGMA = '##';
|
||||
|
||||
(async () => {
|
||||
const allLernaPackages = lernaGetPackages(MONOREPO_ROOT_PATH);
|
||||
const allLernaPackages = lernaGetPackages(constants.monorepoRootPath);
|
||||
const publicLernaPackages = _.filter(allLernaPackages, pkg => !pkg.package.private);
|
||||
_.each(publicLernaPackages, lernaPackage => {
|
||||
const changelogMdIfExists = getChangelogMdIfExists(lernaPackage.package.name, lernaPackage.location);
|
||||
@@ -20,14 +26,20 @@ const MONOREPO_ROOT_PATH = path.join(__dirname, '../../..');
|
||||
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 lines = (changelogMdIfExists as string).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, '## ')) {
|
||||
if (_.startsWith(line, `${HEADER_PRAGMA} `)) {
|
||||
let version = line.substr(4).split(' - ')[0];
|
||||
if (version === '0.x.x') {
|
||||
version = utils.getNextPatchVersion(lernaPackage.package.version);
|
||||
@@ -47,7 +59,7 @@ const MONOREPO_ROOT_PATH = path.join(__dirname, '../../..');
|
||||
if (!_.includes(dateStr, 'TBD')) {
|
||||
changelog.isPublished = true;
|
||||
}
|
||||
(changelogs as any).push(changelog);
|
||||
changelogs.push(changelog);
|
||||
} else if (_.includes(line, '* ')) {
|
||||
const note = line.split('* ')[1].split(' (#')[0];
|
||||
const prChunk = line.split(' (#')[1];
|
||||
@@ -55,10 +67,12 @@ const MONOREPO_ROOT_PATH = path.join(__dirname, '../../..');
|
||||
if (!_.isUndefined(prChunk)) {
|
||||
pr = prChunk.split(')')[0];
|
||||
}
|
||||
const changes = {
|
||||
const changes: Changes = {
|
||||
note,
|
||||
pr,
|
||||
};
|
||||
if (!_.isUndefined(pr)) {
|
||||
changes.pr = _.parseInt(pr);
|
||||
}
|
||||
changelog.changes.push(changes);
|
||||
}
|
||||
}
|
||||
@@ -77,7 +91,6 @@ function getChangelogMdIfExists(packageName: string, location: string): string |
|
||||
changelogMd = fs.readFileSync(changelogPath, 'utf-8');
|
||||
return changelogMd;
|
||||
} catch (err) {
|
||||
// If none exists, create new, empty one.
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user