aboutsummaryrefslogtreecommitdiffstats
path: root/packages/monorepo-scripts/src/utils
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2019-02-04 17:12:49 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2019-02-04 17:38:02 +0800
commit6943bbcacbd9a1df0cdddb2696a768aec4b3d2c4 (patch)
tree768bb7240b510a8e9f0c735ae658497583160627 /packages/monorepo-scripts/src/utils
parent1d3fff32a29b4e958cd32acb016577683df95d3d (diff)
downloaddexon-0x-contracts-6943bbcacbd9a1df0cdddb2696a768aec4b3d2c4.tar
dexon-0x-contracts-6943bbcacbd9a1df0cdddb2696a768aec4b3d2c4.tar.gz
dexon-0x-contracts-6943bbcacbd9a1df0cdddb2696a768aec4b3d2c4.tar.bz2
dexon-0x-contracts-6943bbcacbd9a1df0cdddb2696a768aec4b3d2c4.tar.lz
dexon-0x-contracts-6943bbcacbd9a1df0cdddb2696a768aec4b3d2c4.tar.xz
dexon-0x-contracts-6943bbcacbd9a1df0cdddb2696a768aec4b3d2c4.tar.zst
dexon-0x-contracts-6943bbcacbd9a1df0cdddb2696a768aec4b3d2c4.zip
Temp
Diffstat (limited to 'packages/monorepo-scripts/src/utils')
-rw-r--r--packages/monorepo-scripts/src/utils/doc_generate_and_upload_utils.ts3
-rw-r--r--packages/monorepo-scripts/src/utils/utils.ts14
2 files changed, 11 insertions, 6 deletions
diff --git a/packages/monorepo-scripts/src/utils/doc_generate_and_upload_utils.ts b/packages/monorepo-scripts/src/utils/doc_generate_and_upload_utils.ts
index 1a4294e9c..c0e86ad44 100644
--- a/packages/monorepo-scripts/src/utils/doc_generate_and_upload_utils.ts
+++ b/packages/monorepo-scripts/src/utils/doc_generate_and_upload_utils.ts
@@ -1,3 +1,4 @@
+import { PackageJSON } from '@0x/types';
import { existsSync, readFileSync, writeFileSync } from 'fs';
import * as _ from 'lodash';
import * as path from 'path';
@@ -6,7 +7,7 @@ import * as ts from 'typescript';
import { constants } from '../constants';
import { docGenConfigs } from '../doc_gen_configs';
-import { ExportInfo, ExportNameToTypedocNames, ExportPathToExportedItems, PackageJSON } from '../types';
+import { ExportInfo, ExportNameToTypedocNames, ExportPathToExportedItems } from '../types';
import { utils } from './utils';
diff --git a/packages/monorepo-scripts/src/utils/utils.ts b/packages/monorepo-scripts/src/utils/utils.ts
index 28c5658f3..20a6932c3 100644
--- a/packages/monorepo-scripts/src/utils/utils.ts
+++ b/packages/monorepo-scripts/src/utils/utils.ts
@@ -1,3 +1,4 @@
+import { PackageJSON } from '@0x/types';
import batchPackages = require('@lerna/batch-packages');
import * as fs from 'fs';
import * as _ from 'lodash';
@@ -5,7 +6,7 @@ import { exec as execAsync } from 'promisify-child-process';
import semver = require('semver');
import { constants } from '../constants';
-import { GitTagsByPackageName, Package, PackageJSON, UpdatedPackage } from '../types';
+import { GitTagsByPackageName, Package, UpdatedPackage } from '../types';
import { changelogUtils } from './changelog_utils';
@@ -13,6 +14,11 @@ export const utils = {
log(...args: any[]): void {
console.log(...args); // tslint:disable-line:no-console
},
+ readJSONFile<T>(path: string): T {
+ const JSONString = fs.readFileSync(path, 'utf8');
+ const parsed: T = JSON.parse(JSONString);
+ return parsed;
+ },
getTopologicallySortedPackages(rootDir: string): Package[] {
const packages = utils.getPackages(rootDir);
const batchedPackages: PackageJSON[] = _.flatten(batchPackages(_.map(packages, pkg => pkg.packageJson), false));
@@ -23,8 +29,7 @@ export const utils = {
return topsortedPackages;
},
getPackages(rootDir: string): Package[] {
- const rootPackageJsonString = fs.readFileSync(`${rootDir}/package.json`, 'utf8');
- const rootPackageJson = JSON.parse(rootPackageJsonString);
+ const rootPackageJson = utils.readJSONFile<PackageJSON>(`${rootDir}/package.json`);
if (_.isUndefined(rootPackageJson.workspaces)) {
throw new Error(`Did not find 'workspaces' key in root package.json`);
}
@@ -40,8 +45,7 @@ export const utils = {
}
const pathToPackageJson = `${rootDir}/${workspacePath}${subpackageName}`;
try {
- const packageJsonString = fs.readFileSync(`${pathToPackageJson}/package.json`, 'utf8');
- const packageJson = JSON.parse(packageJsonString);
+ const packageJson = utils.readJSONFile<PackageJSON>(`${pathToPackageJson}/package.json`);
const pkg = {
location: pathToPackageJson,
packageJson,