diff options
author | Fabio Berger <me@fabioberger.com> | 2018-04-02 14:49:48 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-04-02 14:49:48 +0800 |
commit | 2a6a71ea6cd89d39142f51530d06e80ffc44e722 (patch) | |
tree | 797eab3dfe0e65036ab84f01e1f3a9c3585b97f7 /packages/monorepo-scripts/src | |
parent | cd23f220a0a3ebd79667a169923284102509400c (diff) | |
download | dexon-0x-contracts-2a6a71ea6cd89d39142f51530d06e80ffc44e722.tar.gz dexon-0x-contracts-2a6a71ea6cd89d39142f51530d06e80ffc44e722.tar.zst dexon-0x-contracts-2a6a71ea6cd89d39142f51530d06e80ffc44e722.zip |
Add prettier run on generated CHANGELOG.json and fix scripts
Diffstat (limited to 'packages/monorepo-scripts/src')
-rw-r--r-- | packages/monorepo-scripts/src/convert_changelogs.ts | 13 | ||||
-rw-r--r-- | packages/monorepo-scripts/src/publish.ts | 15 |
2 files changed, 18 insertions, 10 deletions
diff --git a/packages/monorepo-scripts/src/convert_changelogs.ts b/packages/monorepo-scripts/src/convert_changelogs.ts index c62cf844b..f4c4d51a2 100644 --- a/packages/monorepo-scripts/src/convert_changelogs.ts +++ b/packages/monorepo-scripts/src/convert_changelogs.ts @@ -10,6 +10,7 @@ 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'; @@ -20,7 +21,7 @@ const HEADER_PRAGMA = '##'; (async () => { const allLernaPackages = lernaGetPackages(constants.monorepoRootPath); const publicLernaPackages = _.filter(allLernaPackages, pkg => !pkg.package.private); - _.each(publicLernaPackages, lernaPackage => { + 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.`); @@ -76,9 +77,13 @@ const HEADER_PRAGMA = '##'; changelog.changes.push(changes); } } - const changelogJson = JSON.stringify(changelogs, null, '\t'); - fs.writeFileSync(`${lernaPackage.location}/CHANGELOG.json`, changelogJson); - }); + const changelogJson = JSON.stringify(changelogs); + const changelogJsonPath = `${lernaPackage.location}/CHANGELOG.json`; + fs.writeFileSync(changelogJsonPath, changelogJson); + await execAsync(`prettier --write ${changelogJsonPath} --config .prettierrc`, { + cwd: constants.monorepoRootPath, + }); + } })().catch(err => { utils.log(err.stdout); process.exit(1); diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 2f18f2a9c..2263e2f8c 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -13,7 +13,7 @@ import { constants } from './constants'; import { Changelog, Changes, SemVerIndex, UpdatedPackage } from './types'; import { utils } from './utils'; -const IS_DRY_RUN = process.env.IS_DRY_RUN === 'false'; +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 } = { @@ -30,11 +30,11 @@ const semverNameToIndex: { [semver: string]: number } = { const updatedPublicLernaPackages = _.filter(allLernaPackages, pkg => { return _.includes(updatedPackageNames, pkg.package.name); }); - const relevantPackageNames = _.map(updatedPublicLernaPackages, pkg => pkg.package.name); - utils.log(`Will update CHANGELOGs and publish: \n${relevantPackageNames.join('\n')}\n`); + const updatedPublicLernaPackageNames = _.map(updatedPublicLernaPackages, pkg => pkg.package.name); + utils.log(`Will update CHANGELOGs and publish: \n${updatedPublicLernaPackageNames.join('\n')}\n`); const packageToVersionChange: { [name: string]: string } = {}; - _.each(updatedPublicLernaPackages, lernaPackage => { + 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); @@ -77,14 +77,17 @@ const semverNameToIndex: { [semver: string]: number } = { } // Save updated CHANGELOG.json - fs.writeFileSync(changelogJSONPath, JSON.stringify(changelogs, null, '\t')); + fs.writeFileSync(changelogJSONPath, JSON.stringify(changelogs)); + await execAsync(`prettier --write ${changelogJSONPath} --config .prettierrc`, { + cwd: constants.monorepoRootPath, + }); utils.log(`${packageName}: Updated CHANGELOG.json`); // Generate updated CHANGELOG.md const changelogMd = generateChangelogMd(changelogs); const changelogMdPath = path.join(lernaPackage.location, 'CHANGELOG.md'); fs.writeFileSync(changelogMdPath, changelogMd); utils.log(`${packageName}: Updated CHANGELOG.md`); - }); + } if (!IS_DRY_RUN) { await execAsync(`git add . --all`, { cwd: constants.monorepoRootPath }); |