aboutsummaryrefslogtreecommitdiffstats
path: root/packages/monorepo-scripts/src
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2018-03-16 00:57:27 +0800
committerBrandon Millman <brandon.millman@gmail.com>2018-03-16 00:57:27 +0800
commit76029cbf0915df36266bd5e51add07755297ddda (patch)
treee1692f8cc4ea4642292c61f65ba3911ded26de8e /packages/monorepo-scripts/src
parentb9c1653c1cf6984d56b7825d8747b48d797fa39e (diff)
parent4a27a7dc581fc6c8a3d4e212ca3712c249a5b417 (diff)
downloaddexon-0x-contracts-76029cbf0915df36266bd5e51add07755297ddda.tar.gz
dexon-0x-contracts-76029cbf0915df36266bd5e51add07755297ddda.tar.zst
dexon-0x-contracts-76029cbf0915df36266bd5e51add07755297ddda.zip
Merge branch 'development' into feature/sra-report/collection-tests
* development: (97 commits) Keep console.log in monorepo-scripts Enable coverage for all other packages with tests Fix parallel coverage results reporting Fix linter issuesx Remove outdated comment Add script copying to build command Add postpublish script to sol-cov Move configuration into package.json configs section Transform input data before encoding for callAsync and getABIEncodedTransactionData Update CHANGELOGs Consolidate all console.log into the @0xproject/utils package Update coverage badge to show development coverage Configure post build hook Notify coveralls after all tasks have finished Address feedback Revert "Report all coverage reports together" Separate published packages and typescript typings on README Consolidate docs generation and uploading logic Use async/await instead of promise syntax Move changelog entry ...
Diffstat (limited to 'packages/monorepo-scripts/src')
-rw-r--r--packages/monorepo-scripts/src/deps_versions.ts10
-rw-r--r--packages/monorepo-scripts/src/globals.d.ts8
-rw-r--r--packages/monorepo-scripts/src/index.ts1
-rw-r--r--packages/monorepo-scripts/src/postpublish_utils.ts161
-rw-r--r--packages/monorepo-scripts/src/utils.ts9
5 files changed, 183 insertions, 6 deletions
diff --git a/packages/monorepo-scripts/src/deps_versions.ts b/packages/monorepo-scripts/src/deps_versions.ts
index 5c9a2d6ff..07292a160 100644
--- a/packages/monorepo-scripts/src/deps_versions.ts
+++ b/packages/monorepo-scripts/src/deps_versions.ts
@@ -5,6 +5,8 @@ import * as fs from 'fs';
import { sync as globSync } from 'glob';
import * as _ from 'lodash';
+import { utils } from './utils';
+
interface Dependencies {
[depName: string]: string;
}
@@ -17,10 +19,6 @@ interface VersionsByDependency {
const PACKAGE_JSON_GLOB = '../*/package.json';
-function log(...args: any[]) {
- console.log(...args); // tslint:disable-line:no-console
-}
-
function getDependencies(path: string): Dependencies {
const file = fs.readFileSync(path).toString();
const parsed = JSON.parse(file);
@@ -48,9 +46,9 @@ _.map(versionsByDependency, (versions: Versions, depName: string) => {
if (_.uniq(_.values(versions)).length === 1) {
delete versionsByDependency[depName];
} else {
- log(chalk.bold(depName));
+ utils.log(chalk.bold(depName));
_.map(versions, (version: string, packageName: string) => {
- log(`├── ${packageName} -> ${version}`);
+ utils.log(`├── ${packageName} -> ${version}`);
});
}
});
diff --git a/packages/monorepo-scripts/src/globals.d.ts b/packages/monorepo-scripts/src/globals.d.ts
new file mode 100644
index 000000000..757ae4097
--- /dev/null
+++ b/packages/monorepo-scripts/src/globals.d.ts
@@ -0,0 +1,8 @@
+declare module 'async-child-process';
+declare module 'publish-release';
+declare module 'es6-promisify';
+
+// semver-sort declarations
+declare module 'semver-sort' {
+ const desc: (versions: string[]) => string[];
+}
diff --git a/packages/monorepo-scripts/src/index.ts b/packages/monorepo-scripts/src/index.ts
new file mode 100644
index 000000000..95c96ebe8
--- /dev/null
+++ b/packages/monorepo-scripts/src/index.ts
@@ -0,0 +1 @@
+export { postpublishUtils } from './postpublish_utils';
diff --git a/packages/monorepo-scripts/src/postpublish_utils.ts b/packages/monorepo-scripts/src/postpublish_utils.ts
new file mode 100644
index 000000000..898b00c47
--- /dev/null
+++ b/packages/monorepo-scripts/src/postpublish_utils.ts
@@ -0,0 +1,161 @@
+import { execAsync } from 'async-child-process';
+import * as promisify from 'es6-promisify';
+import * as _ from 'lodash';
+import * as publishRelease from 'publish-release';
+import semverSort = require('semver-sort');
+
+import { utils } from './utils';
+
+const publishReleaseAsync = promisify(publishRelease);
+const githubPersonalAccessToken = process.env.GITHUB_PERSONAL_ACCESS_TOKEN_0X_JS;
+const generatedDocsDirectoryName = 'generated_docs';
+
+export interface PostpublishConfigs {
+ cwd: string;
+ packageName: string;
+ version: string;
+ assets: string[];
+ docPublishConfigs: DocPublishConfigs;
+}
+
+export interface DocPublishConfigs {
+ fileIncludes: string[];
+ s3BucketPath: string;
+ s3StagingBucketPath: string;
+}
+
+export const postpublishUtils = {
+ generateConfig(packageJSON: any, tsConfigJSON: any, cwd: string): PostpublishConfigs {
+ if (_.isUndefined(packageJSON.name)) {
+ throw new Error('name field required in package.json. Cannot publish release notes to Github.');
+ }
+ if (_.isUndefined(packageJSON.version)) {
+ throw new Error('version field required in package.json. Cannot publish release notes to Github.');
+ }
+ const postpublishConfig = _.get(packageJSON, 'config.postpublish', {});
+ const configs: PostpublishConfigs = {
+ cwd,
+ packageName: packageJSON.name,
+ version: packageJSON.version,
+ assets: _.get(postpublishConfig, 'assets', []),
+ docPublishConfigs: {
+ fileIncludes: [
+ ...tsConfigJSON.include,
+ ..._.get(postpublishConfig, 'docPublishConfigs.extraFileIncludes', []),
+ ],
+ s3BucketPath: _.get(postpublishConfig, 'docPublishConfigs.s3BucketPath'),
+ s3StagingBucketPath: _.get(postpublishConfig, 'docPublishConfigs.s3StagingBucketPath'),
+ },
+ };
+ return configs;
+ },
+ async runAsync(packageJSON: any, tsConfigJSON: any, cwd: string): Promise<void> {
+ const configs = this.generateConfig(packageJSON, tsConfigJSON, cwd);
+ const release = await this.publishReleaseNotesAsync(
+ configs.cwd,
+ configs.packageName,
+ configs.version,
+ configs.assets,
+ );
+ if (
+ !_.isUndefined(configs.docPublishConfigs.s3BucketPath) ||
+ !_.isUndefined(configs.docPublishConfigs.s3StagingBucketPath)
+ ) {
+ utils.log('POSTPUBLISH: Release successful, generating docs...');
+ await postpublishUtils.generateAndUploadDocsAsync(
+ configs.cwd,
+ configs.docPublishConfigs.fileIncludes,
+ configs.version,
+ configs.docPublishConfigs.s3BucketPath,
+ );
+ } else {
+ utils.log(`POSTPUBLISH: No S3Bucket config found for ${packageJSON.name}. Skipping doc JSON generation.`);
+ }
+ },
+ async publishDocsToStagingAsync(packageJSON: any, tsConfigJSON: any, cwd: string) {
+ const configs = this.generateConfig(packageJSON, tsConfigJSON, cwd);
+ if (_.isUndefined(configs.docPublishConfigs.s3StagingBucketPath)) {
+ utils.log('config.postpublish.docPublishConfigs.s3StagingBucketPath entry in package.json not found!');
+ return;
+ }
+
+ utils.log('POSTPUBLISH: Generating docs...');
+ await postpublishUtils.generateAndUploadDocsAsync(
+ configs.cwd,
+ configs.docPublishConfigs.fileIncludes,
+ configs.version,
+ configs.docPublishConfigs.s3StagingBucketPath,
+ );
+ },
+ async publishReleaseNotesAsync(cwd: string, packageName: string, version: string, assets: string[]): Promise<void> {
+ const releaseName = this.getReleaseName(packageName, version);
+ const tag = this.getTag(packageName, version);
+ utils.log('POSTPUBLISH: Releasing ', releaseName, '...');
+ const finalAssets = this.adjustAssetPaths(cwd, assets);
+ const result = await publishReleaseAsync({
+ token: githubPersonalAccessToken,
+ owner: '0xProject',
+ repo: '0x-monorepo',
+ tag,
+ name: releaseName,
+ notes: 'N/A',
+ draft: false,
+ prerelease: false,
+ reuseRelease: true,
+ reuseDraftOnly: false,
+ assets,
+ });
+ },
+ getTag(packageName: string, version: string) {
+ return `${packageName}@${version}`;
+ },
+ getReleaseName(subPackageName: string, version: string): string {
+ const releaseName = `${subPackageName} v${version}`;
+ return releaseName;
+ },
+ adjustAssetPaths(cwd: string, assets: string[]) {
+ const finalAssets: string[] = [];
+ _.each(assets, (asset: string) => {
+ finalAssets.push(`${cwd}/${asset}`);
+ });
+ return finalAssets;
+ },
+ adjustFileIncludePaths(fileIncludes: string[], cwd: string): string[] {
+ const fileIncludesAdjusted = _.map(fileIncludes, fileInclude => {
+ let path = _.startsWith(fileInclude, './') ? `${cwd}/${fileInclude.substr(2)}` : `${cwd}/${fileInclude}`;
+
+ // HACK: tsconfig.json needs wildcard directory endings as `/**/*`
+ // but TypeDoc needs it as `/**` in order to pick up files at the root
+ if (_.endsWith(path, '/**/*')) {
+ path = path.slice(0, -2);
+ }
+ return path;
+ });
+ return fileIncludesAdjusted;
+ },
+ async generateAndUploadDocsAsync(cwd: string, fileIncludes: string[], version: string, S3BucketPath: string) {
+ const fileIncludesAdjusted = this.adjustFileIncludePaths(fileIncludes, cwd);
+ const projectFiles = fileIncludesAdjusted.join(' ');
+ const jsonFilePath = `${cwd}/${generatedDocsDirectoryName}/index.json`;
+ const result = await execAsync(
+ `JSON_FILE_PATH=${jsonFilePath} PROJECT_FILES="${projectFiles}" yarn docs:json`,
+ {
+ cwd,
+ },
+ );
+ if (!_.isEmpty(result.stderr)) {
+ throw new Error(result.stderr);
+ }
+ const fileName = `v${version}.json`;
+ utils.log(`POSTPUBLISH: Doc generation successful, uploading docs... as ${fileName}`);
+ const s3Url = S3BucketPath + fileName;
+ await execAsync(`S3_URL=${s3Url} yarn upload_docs_json`, {
+ cwd,
+ });
+ // Remove the generated docs directory
+ await execAsync(`rm -rf ${generatedDocsDirectoryName}`, {
+ cwd,
+ });
+ utils.log(`POSTPUBLISH: Docs uploaded to S3 bucket: ${S3BucketPath}`);
+ },
+};
diff --git a/packages/monorepo-scripts/src/utils.ts b/packages/monorepo-scripts/src/utils.ts
new file mode 100644
index 000000000..57c1b5af3
--- /dev/null
+++ b/packages/monorepo-scripts/src/utils.ts
@@ -0,0 +1,9 @@
+import { promisify } from '@0xproject/utils';
+import { NewmanRunSummary, run as newmanRun } from 'newman';
+
+export const utils = {
+ log(...args: any[]): void {
+ console.log(...args); // tslint:disable-line:no-console
+ },
+ newmanRunAsync: promisify<NewmanRunSummary>(newmanRun),
+};