diff options
Diffstat (limited to 'packages/monorepo-scripts')
-rw-r--r-- | packages/monorepo-scripts/package.json | 1 | ||||
-rw-r--r-- | packages/monorepo-scripts/src/deps_versions.ts | 16 | ||||
-rw-r--r-- | packages/monorepo-scripts/src/publish.ts | 8 | ||||
-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, 28 insertions, 35 deletions
diff --git a/packages/monorepo-scripts/package.json b/packages/monorepo-scripts/package.json index fddcc13f8..24dca0004 100644 --- a/packages/monorepo-scripts/package.json +++ b/packages/monorepo-scripts/package.json @@ -47,6 +47,7 @@ "typescript": "3.0.1" }, "dependencies": { + "@0x/types": "^2.0.1", "@0x/utils": "^4.0.2", "@lerna/batch-packages": "^3.0.0-beta.18", "@types/depcheck": "^0.6.0", diff --git a/packages/monorepo-scripts/src/deps_versions.ts b/packages/monorepo-scripts/src/deps_versions.ts index 0d01a2e3c..bb7e50f51 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, PackageJSONConfig } from '@0x/types'; import chalk from 'chalk'; -import * as fs from 'fs'; import { sync as globSync } from 'glob'; import * as path from 'path'; @@ -24,9 +24,10 @@ interface ParsedDependencies { const PACKAGE_JSON_GLOB = '../../*/package.json'; -const config = JSON.parse(fs.readFileSync(path.join(__dirname, '../../../package.json')).toString()).config; -const dependenciesWithIgnoredVersions: string[] = config.ignoreDependencyVersions.split(' '); -const packagesWithIgnoredVersions: string[] = config.ignoreDependencyVersionsForPackage.split(' '); +const config = utils.readJSONFile<PackageJSON>(path.join(__dirname, '../../../package.json')) + .config as PackageJSONConfig; // tslint:disable-line no-unnecessary-type-assertion +const dependenciesWithIgnoredVersions: string[] = (config.ignoreDependencyVersions as string).split(' '); +const packagesWithIgnoredVersions: string[] = (config.ignoreDependencyVersionsForPackage as string).split(' '); if (require.main === module) { const dependencies = parseDependencies(); @@ -44,11 +45,10 @@ if (require.main === module) { } 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 196b4c2ff..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'); @@ -47,7 +47,7 @@ async function confirmAsync(message: string): Promise<void> { await confirmAsync( 'THIS IS NOT A TEST PUBLISH! You are about to publish one or more packages to npm. Are you sure you want to continue? (y/n)', ); - // await confirmDocPagesRenderAsync(packagesWithDocs); + await confirmDocPagesRenderAsync(packagesWithDocs); } // Update CHANGELOGs @@ -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, |