aboutsummaryrefslogtreecommitdiffstats
path: root/packages/monorepo-scripts/src/utils/utils.ts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-06-02 08:13:02 +0800
committerFabio Berger <me@fabioberger.com>2018-06-02 08:13:02 +0800
commitd3c64bd5b493dc1779a24c7c051c255106a4292a (patch)
treed1c818e64b75c1f4fed1c7d797892fb0d35dd779 /packages/monorepo-scripts/src/utils/utils.ts
parent7024a7468a549a96cf120e6b7e287e79d7ad2d61 (diff)
parent62e60e2ba6d07b9b892b4f2e92a5421c54f5fa20 (diff)
downloaddexon-0x-contracts-d3c64bd5b493dc1779a24c7c051c255106a4292a.tar
dexon-0x-contracts-d3c64bd5b493dc1779a24c7c051c255106a4292a.tar.gz
dexon-0x-contracts-d3c64bd5b493dc1779a24c7c051c255106a4292a.tar.bz2
dexon-0x-contracts-d3c64bd5b493dc1779a24c7c051c255106a4292a.tar.lz
dexon-0x-contracts-d3c64bd5b493dc1779a24c7c051c255106a4292a.tar.xz
dexon-0x-contracts-d3c64bd5b493dc1779a24c7c051c255106a4292a.tar.zst
dexon-0x-contracts-d3c64bd5b493dc1779a24c7c051c255106a4292a.zip
Merge branch 'v2-prototype' into refactor/order-utils/for-v2
* v2-prototype: Set contract expiration time to a constant 10 minutes Remove unused promises array Make erc20_wrapper and erc721_wrapper serial Rename changelogs to changelog Add CHANGELOG entry Check that git branch is up to date before publishing Move prepublish checks before building packages for publishing Refactor changelog utils to a separate module
Diffstat (limited to 'packages/monorepo-scripts/src/utils/utils.ts')
-rw-r--r--packages/monorepo-scripts/src/utils/utils.ts64
1 files changed, 64 insertions, 0 deletions
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<void> {
+ await execAsync(`prettier --write ${filePath} --config .prettierrc`, {
+ cwd,
+ });
+ },
+ async getUpdatedLernaPackagesAsync(shouldIncludePrivate: boolean): Promise<LernaPackage[]> {
+ 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<UpdatedPackage[]> {
+ 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;
+ },
+};