diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2019-02-04 17:12:49 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2019-02-04 17:38:02 +0800 |
commit | 6943bbcacbd9a1df0cdddb2696a768aec4b3d2c4 (patch) | |
tree | 768bb7240b510a8e9f0c735ae658497583160627 /packages/monorepo-scripts | |
parent | 1d3fff32a29b4e958cd32acb016577683df95d3d (diff) | |
download | dexon-0x-contracts-6943bbcacbd9a1df0cdddb2696a768aec4b3d2c4.tar.gz dexon-0x-contracts-6943bbcacbd9a1df0cdddb2696a768aec4b3d2c4.tar.zst dexon-0x-contracts-6943bbcacbd9a1df0cdddb2696a768aec4b3d2c4.zip |
Temp
Diffstat (limited to 'packages/monorepo-scripts')
-rw-r--r-- | packages/monorepo-scripts/package.json | 8 | ||||
-rw-r--r-- | packages/monorepo-scripts/src/deps_versions.ts | 9 | ||||
-rw-r--r-- | packages/monorepo-scripts/src/publish.ts | 6 | ||||
-rw-r--r-- | packages/monorepo-scripts/src/test_installation.ts | 4 | ||||
-rw-r--r-- | packages/monorepo-scripts/src/types.ts | 17 | ||||
-rw-r--r-- | packages/monorepo-scripts/src/utils/doc_generate_and_upload_utils.ts | 3 | ||||
-rw-r--r-- | packages/monorepo-scripts/src/utils/utils.ts | 14 |
7 files changed, 30 insertions, 31 deletions
diff --git a/packages/monorepo-scripts/package.json b/packages/monorepo-scripts/package.json index 187a80c93..e6273fd60 100644 --- a/packages/monorepo-scripts/package.json +++ b/packages/monorepo-scripts/package.json @@ -8,6 +8,9 @@ "description": "Helper scripts for the monorepo", "main": "lib/index.js", "types": "lib/index.d.ts", + "bin": { + "contracts-gen": "bin/contracts-gen.js" + }, "scripts": { "build": "tsc -b", "build:ci": "yarn build", @@ -36,6 +39,7 @@ "@types/mkdirp": "^0.5.2", "@types/node": "*", "@types/opn": "^5.1.0", + "@types/prettier": "^1.15.2", "@types/rimraf": "^2.0.2", "@types/semver": "5.5.0", "@types/yargs": "^10.0.0", @@ -48,17 +52,20 @@ }, "dependencies": { "@0x/utils": "^3.0.1", + "@0x/types": "^1.5.2", "@lerna/batch-packages": "^3.0.0-beta.18", "@types/depcheck": "^0.6.0", "async-child-process": "^1.1.1", "chalk": "^2.3.0", "es6-promisify": "^5.0.0", + "ethereum-types": "^1.1.6", "glob": "^7.1.2", "isomorphic-fetch": "2.2.1", "lodash": "^4.17.5", "mkdirp": "^0.5.1", "moment": "2.21.0", "opn": "^5.3.0", + "prettier": "^1.16.3", "promisify-child-process": "^1.0.5", "prompt": "^1.0.0", "publish-release": "0xproject/publish-release", @@ -66,6 +73,7 @@ "semver": "5.5.0", "semver-diff": "^2.1.0", "semver-sort": "0.0.4", + "snake-case": "^2.1.0", "typedoc": "0.13.0", "yargs": "^10.0.3" }, diff --git a/packages/monorepo-scripts/src/deps_versions.ts b/packages/monorepo-scripts/src/deps_versions.ts index 1053906b7..d15bb6b4d 100644 --- a/packages/monorepo-scripts/src/deps_versions.ts +++ b/packages/monorepo-scripts/src/deps_versions.ts @@ -1,7 +1,7 @@ #!/usr/bin/env node +import { PackageJSON } from '@0x/types'; import chalk from 'chalk'; -import * as fs from 'fs'; import { sync as globSync } from 'glob'; import * as _ from 'lodash'; @@ -21,11 +21,10 @@ const PACKAGE_JSON_GLOB = '../*/package.json'; // tslint:disable:no-unused-variable function getDependencies(path: string): Dependencies { - const file = fs.readFileSync(path).toString(); - const parsed = JSON.parse(file); + const packageJSON = utils.readJSONFile<PackageJSON>(path); const dependencies = { - ...parsed.dependencies, - ...parsed.devDependencies, + ...packageJSON.dependencies, + ...packageJSON.devDependencies, }; return dependencies; } diff --git a/packages/monorepo-scripts/src/publish.ts b/packages/monorepo-scripts/src/publish.ts index 105d87dcd..ddb2811f2 100644 --- a/packages/monorepo-scripts/src/publish.ts +++ b/packages/monorepo-scripts/src/publish.ts @@ -1,8 +1,8 @@ #!/usr/bin/env node +import { PackageJSON } from '@0x/types'; import { logUtils } from '@0x/utils'; import * as promisify from 'es6-promisify'; -import * as fs from 'fs'; import * as _ from 'lodash'; import * as moment from 'moment'; import opn = require('opn'); @@ -141,8 +141,8 @@ async function publishImagesToDockerHubAsync(allUpdatedPackages: Package[]): Pro function getPackagesWithDocs(allUpdatedPackages: Package[]): Package[] { const rootPackageJsonPath = `${constants.monorepoRootPath}/package.json`; - const rootPackageJson = JSON.parse(fs.readFileSync(rootPackageJsonPath).toString()); - const packagesWithDocPagesStringIfExist = _.get(rootPackageJson, 'config.packagesWithDocPages', undefined); + const rootPackageJSON = utils.readJSONFile<PackageJSON>(rootPackageJsonPath); + const packagesWithDocPagesStringIfExist = _.get(rootPackageJSON, 'config.packagesWithDocPages', undefined); if (_.isUndefined(packagesWithDocPagesStringIfExist)) { return []; // None to generate & publish } diff --git a/packages/monorepo-scripts/src/test_installation.ts b/packages/monorepo-scripts/src/test_installation.ts index 822f48967..ec145cd32 100644 --- a/packages/monorepo-scripts/src/test_installation.ts +++ b/packages/monorepo-scripts/src/test_installation.ts @@ -8,7 +8,7 @@ import { exec as execAsync } from 'promisify-child-process'; import * as rimraf from 'rimraf'; import { promisify } from 'util'; -import { Package } from './types'; +import { Changelog, Package } from './types'; import { utils } from './utils/utils'; // Packages might not be runnable if they are command-line tools or only run in browsers. @@ -100,7 +100,7 @@ async function testInstallPackageAsync( installablePackage: Package, ): Promise<void> { const changelogPath = path.join(installablePackage.location, 'CHANGELOG.json'); - const lastChangelogVersion = JSON.parse(fs.readFileSync(changelogPath).toString())[0].version; + const lastChangelogVersion = utils.readJSONFile<Changelog>(changelogPath)[0].version; const packageName = installablePackage.packageJson.name; utils.log(`Testing ${packageName}@${lastChangelogVersion}`); const packageDirName = path.join(...`${packageName}-test`.split('/')); diff --git a/packages/monorepo-scripts/src/types.ts b/packages/monorepo-scripts/src/types.ts index 4af4fd257..e285d9082 100644 --- a/packages/monorepo-scripts/src/types.ts +++ b/packages/monorepo-scripts/src/types.ts @@ -1,3 +1,5 @@ +import { PackageJSON } from '@0x/types'; + export interface UpdatedPackage { name: string; version: string; @@ -34,21 +36,6 @@ export interface GitTagsByPackageName { [packageName: string]: string[]; } -export interface PackageJSON { - private?: boolean; - version: string; - name: string; - main?: string; - scripts?: { [command: string]: string }; - config?: { - postpublish?: { - assets?: string[]; - docOmitExports?: string[]; - dockerHubRepo?: string; - }; - }; -} - export interface Package { location: string; packageJson: PackageJSON; 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, |