From 42ecc087cbd3558258107fbce645441955416497 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Thu, 22 Feb 2018 00:30:35 -0800 Subject: Implement initial sra-report command line tool --- packages/sra-report/src/index.ts | 108 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 packages/sra-report/src/index.ts (limited to 'packages/sra-report/src/index.ts') diff --git a/packages/sra-report/src/index.ts b/packages/sra-report/src/index.ts new file mode 100644 index 000000000..fe100bd42 --- /dev/null +++ b/packages/sra-report/src/index.ts @@ -0,0 +1,108 @@ +#!/usr/bin/env node + +import { assert } from '@0xproject/assert'; +import { schemas } from '@0xproject/json-schemas'; +import chalk from 'chalk'; +import * as _ from 'lodash'; +import * as newman from 'newman'; +import * as yargs from 'yargs'; + +import * as sraReportCollectionJSON from '../postman_configs/collections/sra_report.postman_collection.json'; +import * as kovanTokensEnvironmentJSON from '../postman_configs/environments/kovan_tokens.postman_environment.json'; +import * as mainnetTokensEnvironmentJSON from '../postman_configs/environments/mainnet_tokens.postman_environment.json'; + +import { Schema } from './types'; +import { utils } from './utils'; + +const DEFAULT_NETWORK_ID = 1; +const SUPPORTED_NETWORK_IDS = [1, 42]; + +// extract command line arguments +const args = yargs + .option('url', { + alias: ['u'], + describe: 'API endpoint to test for standard relayer API compliance', + type: 'string', + demandOption: true, + }) + .option('output', { + alias: ['o', 'out'], + describe: 'Folder where to write the reports', + type: 'string', + normalize: true, + demandOption: false, + }) + .option('network-id', { + alias: ['n'], + describe: 'ID of the network that the API is serving orders from', + type: 'number', + default: DEFAULT_NETWORK_ID, + }) + .example("$0 --url 'http://api.example.com' --out 'src/contracts/generated/' --network-id 42", 'Full usage example') + .argv; +// perform extra validation on command line arguments +try { + assert.isHttpUrl('args', args.url); +} catch (err) { + utils.log(`${chalk.red(`Invalid url format:`)} ${args.url}`); + process.exit(1); +} +if (!_.includes(SUPPORTED_NETWORK_IDS, args.networkId)) { + utils.log(`${chalk.red(`Unsupported network id:`)} ${args.networkId}`); + utils.log(`${chalk.bold(`Supported network ids:`)} ${SUPPORTED_NETWORK_IDS}`); + process.exit(1); +} +// run newman +newman.run( + { + collection: sraReportCollectionJSON, + reporters: 'cli', + globals: createGlobals(args.url, _.values(schemas)), + environment: getEnvironment(args.networkId), + }, + (err: Error) => { + if (err) { + throw err; + } + utils.log('collection run complete!'); + }, +); +function createGlobals(url: string, schemaList: Schema[]) { + const urlGlobalsValue = { + key: 'url', + value: args.url, + enabled: true, + type: 'text', + }; + const schemaGlobalsValues = _.map(schemaList, (schema: Schema) => { + return { + key: convertSchemaIdToKey(schema.id), + value: JSON.stringify(schema), + enabled: true, + type: 'text', + }; + }); + const globalsValues = _.concat(schemaGlobalsValues, urlGlobalsValue); + const globals = { + values: globalsValues, + }; + return globals; +} +function convertSchemaIdToKey(schemaId: string) { + let result = schemaId; + if (_.startsWith(result, '/')) { + result = result.substr(1); + } + result = `${result}Schema`; + return result; +} +function getEnvironment(networkId: number) { + switch (networkId) { + case 1: + return mainnetTokensEnvironmentJSON; + case 42: + return kovanTokensEnvironmentJSON; + default: + return {}; + } +} -- cgit v1.2.3 From 7afe00f06a0cf0bf4f079dcc86e2241cc3dc9832 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Fri, 23 Feb 2018 11:56:50 -0800 Subject: Use Schema interface from @0xproject/json-schemas --- packages/sra-report/src/index.ts | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'packages/sra-report/src/index.ts') diff --git a/packages/sra-report/src/index.ts b/packages/sra-report/src/index.ts index fe100bd42..a24de377a 100644 --- a/packages/sra-report/src/index.ts +++ b/packages/sra-report/src/index.ts @@ -1,7 +1,7 @@ #!/usr/bin/env node import { assert } from '@0xproject/assert'; -import { schemas } from '@0xproject/json-schemas'; +import { Schema, schemas } from '@0xproject/json-schemas'; import chalk from 'chalk'; import * as _ from 'lodash'; import * as newman from 'newman'; @@ -11,7 +11,6 @@ import * as sraReportCollectionJSON from '../postman_configs/collections/sra_rep import * as kovanTokensEnvironmentJSON from '../postman_configs/environments/kovan_tokens.postman_environment.json'; import * as mainnetTokensEnvironmentJSON from '../postman_configs/environments/mainnet_tokens.postman_environment.json'; -import { Schema } from './types'; import { utils } from './utils'; const DEFAULT_NETWORK_ID = 1; @@ -74,14 +73,18 @@ function createGlobals(url: string, schemaList: Schema[]) { enabled: true, type: 'text', }; - const schemaGlobalsValues = _.map(schemaList, (schema: Schema) => { - return { - key: convertSchemaIdToKey(schema.id), - value: JSON.stringify(schema), - enabled: true, - type: 'text', - }; - }); + const schemaGlobalsValues = _.compact(_.map(schemaList, (schema: Schema) => { + if (_.isUndefined(schema.id)) { + return undefined; + } else { + return { + key: convertSchemaIdToKey(schema.id), + value: JSON.stringify(schema), + enabled: true, + type: 'text', + }; + } + })); const globalsValues = _.concat(schemaGlobalsValues, urlGlobalsValue); const globals = { values: globalsValues, -- cgit v1.2.3 From 55f38b9c35bb8b988eb22ee47d4d671475f05a0e Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Fri, 23 Feb 2018 12:58:36 -0800 Subject: Add an array of schemaKeys to the globals --- packages/sra-report/src/index.ts | 44 ++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 13 deletions(-) (limited to 'packages/sra-report/src/index.ts') diff --git a/packages/sra-report/src/index.ts b/packages/sra-report/src/index.ts index a24de377a..58734182e 100644 --- a/packages/sra-report/src/index.ts +++ b/packages/sra-report/src/index.ts @@ -13,6 +13,13 @@ import * as mainnetTokensEnvironmentJSON from '../postman_configs/environments/m import { utils } from './utils'; +interface GlobalsValue { + key: string; + value: string; + enabled: boolean; + type: string; +} + const DEFAULT_NETWORK_ID = 1; const SUPPORTED_NETWORK_IDS = [1, 42]; @@ -73,19 +80,30 @@ function createGlobals(url: string, schemaList: Schema[]) { enabled: true, type: 'text', }; - const schemaGlobalsValues = _.compact(_.map(schemaList, (schema: Schema) => { - if (_.isUndefined(schema.id)) { - return undefined; - } else { - return { - key: convertSchemaIdToKey(schema.id), - value: JSON.stringify(schema), - enabled: true, - type: 'text', - }; - } - })); - const globalsValues = _.concat(schemaGlobalsValues, urlGlobalsValue); + const schemaGlobalsValues = _.compact( + _.map(schemaList, (schema: Schema) => { + if (_.isUndefined(schema.id)) { + return undefined; + } else { + return { + key: convertSchemaIdToKey(schema.id), + value: JSON.stringify(schema), + enabled: true, + type: 'text', + }; + } + }), + ); + const schemaKeys = _.map(schemaGlobalsValues, (globalsValue: GlobalsValue) => { + return globalsValue.key; + }); + const schemaKeysGlobalsValue = { + key: 'schemaKeys', + value: JSON.stringify(schemaKeys), + enabled: true, + type: 'text', + }; + const globalsValues = _.concat(schemaGlobalsValues, urlGlobalsValue, schemaKeysGlobalsValue); const globals = { values: globalsValues, }; -- cgit v1.2.3 From 9c8501a84e92faf3ef015ae8ab4d1da9354f9a9d Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Tue, 27 Feb 2018 11:51:05 -0800 Subject: Refactor environment factory and promisify newman --- packages/sra-report/src/index.ts | 87 ++++++---------------------------------- 1 file changed, 13 insertions(+), 74 deletions(-) (limited to 'packages/sra-report/src/index.ts') diff --git a/packages/sra-report/src/index.ts b/packages/sra-report/src/index.ts index 58734182e..d273d74a4 100644 --- a/packages/sra-report/src/index.ts +++ b/packages/sra-report/src/index.ts @@ -2,23 +2,18 @@ import { assert } from '@0xproject/assert'; import { Schema, schemas } from '@0xproject/json-schemas'; +import { promisify } from '@0xproject/utils'; import chalk from 'chalk'; import * as _ from 'lodash'; import * as newman from 'newman'; import * as yargs from 'yargs'; import * as sraReportCollectionJSON from '../postman_configs/collections/sra_report.postman_collection.json'; -import * as kovanTokensEnvironmentJSON from '../postman_configs/environments/kovan_tokens.postman_environment.json'; -import * as mainnetTokensEnvironmentJSON from '../postman_configs/environments/mainnet_tokens.postman_environment.json'; +import { postmanEnvironmentFactory } from './postman_environment_factory'; import { utils } from './utils'; -interface GlobalsValue { - key: string; - value: string; - enabled: boolean; - type: string; -} +const newmanRunAsync = promisify(newman.run); const DEFAULT_NETWORK_ID = 1; const SUPPORTED_NETWORK_IDS = [1, 42]; @@ -58,72 +53,16 @@ if (!_.includes(SUPPORTED_NETWORK_IDS, args.networkId)) { utils.log(`${chalk.bold(`Supported network ids:`)} ${SUPPORTED_NETWORK_IDS}`); process.exit(1); } -// run newman -newman.run( - { + +const mainAsync = async () => { + const newmanRunOptions = { collection: sraReportCollectionJSON, reporters: 'cli', - globals: createGlobals(args.url, _.values(schemas)), - environment: getEnvironment(args.networkId), - }, - (err: Error) => { - if (err) { - throw err; - } - utils.log('collection run complete!'); - }, -); -function createGlobals(url: string, schemaList: Schema[]) { - const urlGlobalsValue = { - key: 'url', - value: args.url, - enabled: true, - type: 'text', - }; - const schemaGlobalsValues = _.compact( - _.map(schemaList, (schema: Schema) => { - if (_.isUndefined(schema.id)) { - return undefined; - } else { - return { - key: convertSchemaIdToKey(schema.id), - value: JSON.stringify(schema), - enabled: true, - type: 'text', - }; - } - }), - ); - const schemaKeys = _.map(schemaGlobalsValues, (globalsValue: GlobalsValue) => { - return globalsValue.key; - }); - const schemaKeysGlobalsValue = { - key: 'schemaKeys', - value: JSON.stringify(schemaKeys), - enabled: true, - type: 'text', - }; - const globalsValues = _.concat(schemaGlobalsValues, urlGlobalsValue, schemaKeysGlobalsValue); - const globals = { - values: globalsValues, + globals: postmanEnvironmentFactory.createGlobalEnvironment(args.url), + environment: postmanEnvironmentFactory.createNetworkEnvironment(args.networkId), }; - return globals; -} -function convertSchemaIdToKey(schemaId: string) { - let result = schemaId; - if (_.startsWith(result, '/')) { - result = result.substr(1); - } - result = `${result}Schema`; - return result; -} -function getEnvironment(networkId: number) { - switch (networkId) { - case 1: - return mainnetTokensEnvironmentJSON; - case 42: - return kovanTokensEnvironmentJSON; - default: - return {}; - } -} + await newmanRunAsync(newmanRunOptions); +}; + +mainAsync() + .catch(err => utils.log); -- cgit v1.2.3 From e48a3edacba891a18e641e01708e3d73fd6588ac Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Tue, 27 Feb 2018 14:06:33 -0800 Subject: Get orderHash via 0x connect --- packages/sra-report/src/index.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'packages/sra-report/src/index.ts') diff --git a/packages/sra-report/src/index.ts b/packages/sra-report/src/index.ts index d273d74a4..bd0615480 100644 --- a/packages/sra-report/src/index.ts +++ b/packages/sra-report/src/index.ts @@ -1,6 +1,8 @@ #!/usr/bin/env node +import { ZeroEx } from '0x.js'; import { assert } from '@0xproject/assert'; +import { HttpClient } from '@0xproject/connect'; import { Schema, schemas } from '@0xproject/json-schemas'; import { promisify } from '@0xproject/utils'; import chalk from 'chalk'; @@ -14,7 +16,6 @@ import { postmanEnvironmentFactory } from './postman_environment_factory'; import { utils } from './utils'; const newmanRunAsync = promisify(newman.run); - const DEFAULT_NETWORK_ID = 1; const SUPPORTED_NETWORK_IDS = [1, 42]; @@ -55,14 +56,20 @@ if (!_.includes(SUPPORTED_NETWORK_IDS, args.networkId)) { } const mainAsync = async () => { + const httpClient = new HttpClient(args.url); + const orders = await httpClient.getOrdersAsync(); + const firstOrder = _.head(orders); + if (_.isUndefined(firstOrder)) { + throw new Error('Could not get any orders from /orders endpoint'); + } + const orderHash = ZeroEx.getOrderHashHex(firstOrder); const newmanRunOptions = { collection: sraReportCollectionJSON, reporters: 'cli', - globals: postmanEnvironmentFactory.createGlobalEnvironment(args.url), + globals: postmanEnvironmentFactory.createGlobalEnvironment(args.url, orderHash), environment: postmanEnvironmentFactory.createNetworkEnvironment(args.networkId), }; await newmanRunAsync(newmanRunOptions); }; -mainAsync() - .catch(err => utils.log); +mainAsync().catch(utils.log); -- cgit v1.2.3 From 0987c9a7cfb1936469062b4cb6222158b5e110b7 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Tue, 27 Feb 2018 17:12:45 -0800 Subject: Write to provided output directory --- packages/sra-report/src/index.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'packages/sra-report/src/index.ts') diff --git a/packages/sra-report/src/index.ts b/packages/sra-report/src/index.ts index bd0615480..fade07095 100644 --- a/packages/sra-report/src/index.ts +++ b/packages/sra-report/src/index.ts @@ -63,13 +63,27 @@ const mainAsync = async () => { throw new Error('Could not get any orders from /orders endpoint'); } const orderHash = ZeroEx.getOrderHashHex(firstOrder); - const newmanRunOptions = { + const newmanEnvironmentOptions = { collection: sraReportCollectionJSON, - reporters: 'cli', globals: postmanEnvironmentFactory.createGlobalEnvironment(args.url, orderHash), environment: postmanEnvironmentFactory.createNetworkEnvironment(args.networkId), }; + const newmanReporterOptions = !_.isUndefined(args.output) + ? { + reporters: 'json', + reporter: { + json: { + export: args.output, + }, + }, + } + : { + reporters: 'cli', + }; + const newmanRunOptions = { + ...newmanEnvironmentOptions, + ...newmanReporterOptions, + }; await newmanRunAsync(newmanRunOptions); }; - mainAsync().catch(utils.log); -- cgit v1.2.3 From a3c7af95e17dda91efaff83824c43f8ffb28f078 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Tue, 27 Feb 2018 17:25:42 -0800 Subject: Add stringified order object into globals --- packages/sra-report/src/index.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'packages/sra-report/src/index.ts') diff --git a/packages/sra-report/src/index.ts b/packages/sra-report/src/index.ts index fade07095..bee9db192 100644 --- a/packages/sra-report/src/index.ts +++ b/packages/sra-report/src/index.ts @@ -1,6 +1,4 @@ #!/usr/bin/env node - -import { ZeroEx } from '0x.js'; import { assert } from '@0xproject/assert'; import { HttpClient } from '@0xproject/connect'; import { Schema, schemas } from '@0xproject/json-schemas'; @@ -62,10 +60,9 @@ const mainAsync = async () => { if (_.isUndefined(firstOrder)) { throw new Error('Could not get any orders from /orders endpoint'); } - const orderHash = ZeroEx.getOrderHashHex(firstOrder); const newmanEnvironmentOptions = { collection: sraReportCollectionJSON, - globals: postmanEnvironmentFactory.createGlobalEnvironment(args.url, orderHash), + globals: postmanEnvironmentFactory.createGlobalEnvironment(args.url, firstOrder), environment: postmanEnvironmentFactory.createNetworkEnvironment(args.networkId), }; const newmanReporterOptions = !_.isUndefined(args.output) -- cgit v1.2.3 From 08ab81c54c1e845a4239648e8cea65a930fcc99d Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Mon, 5 Mar 2018 15:24:55 -0800 Subject: Rename isHttpUrl to isWebUri in assert package --- packages/sra-report/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/sra-report/src/index.ts') diff --git a/packages/sra-report/src/index.ts b/packages/sra-report/src/index.ts index bee9db192..327c495ae 100644 --- a/packages/sra-report/src/index.ts +++ b/packages/sra-report/src/index.ts @@ -42,7 +42,7 @@ const args = yargs .argv; // perform extra validation on command line arguments try { - assert.isHttpUrl('args', args.url); + assert.isWebUri('args', args.url); } catch (err) { utils.log(`${chalk.red(`Invalid url format:`)} ${args.url}`); process.exit(1); -- cgit v1.2.3 From cf342dd00eaae8667984e77eb565040c132f160a Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Mon, 5 Mar 2018 15:31:42 -0800 Subject: Change url command line option to endpoint-url --- packages/sra-report/src/index.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'packages/sra-report/src/index.ts') diff --git a/packages/sra-report/src/index.ts b/packages/sra-report/src/index.ts index 327c495ae..c74b5cb40 100644 --- a/packages/sra-report/src/index.ts +++ b/packages/sra-report/src/index.ts @@ -19,9 +19,9 @@ const SUPPORTED_NETWORK_IDS = [1, 42]; // extract command line arguments const args = yargs - .option('url', { - alias: ['u'], - describe: 'API endpoint to test for standard relayer API compliance', + .option('endpoint-url', { + alias: ['e'], + describe: 'API endpoint url to test for standard relayer API compliance', type: 'string', demandOption: true, }) @@ -38,13 +38,13 @@ const args = yargs type: 'number', default: DEFAULT_NETWORK_ID, }) - .example("$0 --url 'http://api.example.com' --out 'src/contracts/generated/' --network-id 42", 'Full usage example') + .example("$0 --endpoint-url 'http://api.example.com' --out 'src/contracts/generated/' --network-id 42", 'Full usage example') .argv; // perform extra validation on command line arguments try { - assert.isWebUri('args', args.url); + assert.isWebUri('args', args.endpointUrl); } catch (err) { - utils.log(`${chalk.red(`Invalid url format:`)} ${args.url}`); + utils.log(`${chalk.red(`Invalid url format:`)} ${args.endpointUrl}`); process.exit(1); } if (!_.includes(SUPPORTED_NETWORK_IDS, args.networkId)) { @@ -54,7 +54,7 @@ if (!_.includes(SUPPORTED_NETWORK_IDS, args.networkId)) { } const mainAsync = async () => { - const httpClient = new HttpClient(args.url); + const httpClient = new HttpClient(args.endpointUrl); const orders = await httpClient.getOrdersAsync(); const firstOrder = _.head(orders); if (_.isUndefined(firstOrder)) { @@ -62,7 +62,7 @@ const mainAsync = async () => { } const newmanEnvironmentOptions = { collection: sraReportCollectionJSON, - globals: postmanEnvironmentFactory.createGlobalEnvironment(args.url, firstOrder), + globals: postmanEnvironmentFactory.createGlobalEnvironment(args.endpointUrl, firstOrder), environment: postmanEnvironmentFactory.createNetworkEnvironment(args.networkId), }; const newmanReporterOptions = !_.isUndefined(args.output) -- cgit v1.2.3 From 38a4ccd9f24cd1cd583c17ebc200238e1770e5f8 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Mon, 5 Mar 2018 16:13:47 -0800 Subject: Change all globals in environment variables --- packages/sra-report/src/index.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'packages/sra-report/src/index.ts') diff --git a/packages/sra-report/src/index.ts b/packages/sra-report/src/index.ts index c74b5cb40..4e93708ee 100644 --- a/packages/sra-report/src/index.ts +++ b/packages/sra-report/src/index.ts @@ -60,11 +60,6 @@ const mainAsync = async () => { if (_.isUndefined(firstOrder)) { throw new Error('Could not get any orders from /orders endpoint'); } - const newmanEnvironmentOptions = { - collection: sraReportCollectionJSON, - globals: postmanEnvironmentFactory.createGlobalEnvironment(args.endpointUrl, firstOrder), - environment: postmanEnvironmentFactory.createNetworkEnvironment(args.networkId), - }; const newmanReporterOptions = !_.isUndefined(args.output) ? { reporters: 'json', @@ -78,7 +73,8 @@ const mainAsync = async () => { reporters: 'cli', }; const newmanRunOptions = { - ...newmanEnvironmentOptions, + collection: sraReportCollectionJSON, + environment: postmanEnvironmentFactory.createPostmanEnvironment(args.endpointUrl, args.networkId, firstOrder), ...newmanReporterOptions, }; await newmanRunAsync(newmanRunOptions); -- cgit v1.2.3 From eb201c4084834e06fc8376434e8a7f793f916c24 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Tue, 6 Mar 2018 00:18:58 -0800 Subject: Add options for exporting environment and collection files --- packages/sra-report/src/index.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'packages/sra-report/src/index.ts') diff --git a/packages/sra-report/src/index.ts b/packages/sra-report/src/index.ts index 4e93708ee..37c7a8f04 100644 --- a/packages/sra-report/src/index.ts +++ b/packages/sra-report/src/index.ts @@ -27,7 +27,7 @@ const args = yargs }) .option('output', { alias: ['o', 'out'], - describe: 'Folder where to write the reports', + describe: 'The relative path to write the report generated by the collection run, prints to console by default', type: 'string', normalize: true, demandOption: false, @@ -38,7 +38,21 @@ const args = yargs type: 'number', default: DEFAULT_NETWORK_ID, }) - .example("$0 --endpoint-url 'http://api.example.com' --out 'src/contracts/generated/' --network-id 42", 'Full usage example') + .option('export-collection', { + alias: ['ec'], + describe: 'The relative path to write the postman collection file used by the collection run', + type: 'string', + normalize: true, + demandOption: false, + }) + .option('export-environment', { + alias: ['ee'], + describe: 'The relative path to write the postman environment file used by the collection run', + type: 'string', + normalize: true, + demandOption: false, + }) + .example("$0 --endpoint-url 'http://api.example.com' --out 'path/to/report.json' --network-id 42 --export-environment 'path/to/environment.json' --export-collection 'path/to/collection.json'", 'Full usage example') .argv; // perform extra validation on command line arguments try { @@ -52,7 +66,6 @@ if (!_.includes(SUPPORTED_NETWORK_IDS, args.networkId)) { utils.log(`${chalk.bold(`Supported network ids:`)} ${SUPPORTED_NETWORK_IDS}`); process.exit(1); } - const mainAsync = async () => { const httpClient = new HttpClient(args.endpointUrl); const orders = await httpClient.getOrdersAsync(); @@ -75,6 +88,8 @@ const mainAsync = async () => { const newmanRunOptions = { collection: sraReportCollectionJSON, environment: postmanEnvironmentFactory.createPostmanEnvironment(args.endpointUrl, args.networkId, firstOrder), + exportCollection: args.exportCollection, + exportEnvironment: args.exportEnvironment, ...newmanReporterOptions, }; await newmanRunAsync(newmanRunOptions); -- cgit v1.2.3 From 551771235bc80209a1f3aafff56438621885f61a Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Tue, 6 Mar 2018 00:20:36 -0800 Subject: Prettier --- packages/sra-report/src/index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'packages/sra-report/src/index.ts') diff --git a/packages/sra-report/src/index.ts b/packages/sra-report/src/index.ts index 37c7a8f04..4419a3ec8 100644 --- a/packages/sra-report/src/index.ts +++ b/packages/sra-report/src/index.ts @@ -52,8 +52,10 @@ const args = yargs normalize: true, demandOption: false, }) - .example("$0 --endpoint-url 'http://api.example.com' --out 'path/to/report.json' --network-id 42 --export-environment 'path/to/environment.json' --export-collection 'path/to/collection.json'", 'Full usage example') - .argv; + .example( + "$0 --endpoint-url 'http://api.example.com' --out 'path/to/report.json' --network-id 42 --export-environment 'path/to/environment.json' --export-collection 'path/to/collection.json'", + 'Full usage example', + ).argv; // perform extra validation on command line arguments try { assert.isWebUri('args', args.endpointUrl); -- cgit v1.2.3 From ddad09a93639f9060db69d131a52ef8dbaf4a3fe Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Tue, 6 Mar 2018 00:44:18 -0800 Subject: Add support for custom environment file --- packages/sra-report/src/index.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'packages/sra-report/src/index.ts') diff --git a/packages/sra-report/src/index.ts b/packages/sra-report/src/index.ts index 4419a3ec8..d292f15e1 100644 --- a/packages/sra-report/src/index.ts +++ b/packages/sra-report/src/index.ts @@ -1,6 +1,5 @@ #!/usr/bin/env node import { assert } from '@0xproject/assert'; -import { HttpClient } from '@0xproject/connect'; import { Schema, schemas } from '@0xproject/json-schemas'; import { promisify } from '@0xproject/utils'; import chalk from 'chalk'; @@ -38,6 +37,13 @@ const args = yargs type: 'number', default: DEFAULT_NETWORK_ID, }) + .option('environment', { + alias: ['env'], + describe: 'File path to an environment file for the collection run', + type: 'string', + normalize: true, + demandOption: false, + }) .option('export-collection', { alias: ['ec'], describe: 'The relative path to write the postman collection file used by the collection run', @@ -53,7 +59,7 @@ const args = yargs demandOption: false, }) .example( - "$0 --endpoint-url 'http://api.example.com' --out 'path/to/report.json' --network-id 42 --export-environment 'path/to/environment.json' --export-collection 'path/to/collection.json'", + "$0 --endpoint-url 'http://api.example.com' --out 'path/to/report.json' --network-id 42 --environment 'path/to/custom/environment.json' --export-collection 'path/to/collection.json' --export-environment 'path/to/environment.json'", 'Full usage example', ).argv; // perform extra validation on command line arguments @@ -69,12 +75,6 @@ if (!_.includes(SUPPORTED_NETWORK_IDS, args.networkId)) { process.exit(1); } const mainAsync = async () => { - const httpClient = new HttpClient(args.endpointUrl); - const orders = await httpClient.getOrdersAsync(); - const firstOrder = _.head(orders); - if (_.isUndefined(firstOrder)) { - throw new Error('Could not get any orders from /orders endpoint'); - } const newmanReporterOptions = !_.isUndefined(args.output) ? { reporters: 'json', @@ -87,9 +87,12 @@ const mainAsync = async () => { : { reporters: 'cli', }; + const environment = !_.isUndefined(args.environment) + ? args.environment + : await postmanEnvironmentFactory.createPostmanEnvironmentAsync(args.endpointUrl, args.networkId); const newmanRunOptions = { collection: sraReportCollectionJSON, - environment: postmanEnvironmentFactory.createPostmanEnvironment(args.endpointUrl, args.networkId, firstOrder), + environment, exportCollection: args.exportCollection, exportEnvironment: args.exportEnvironment, ...newmanReporterOptions, -- cgit v1.2.3 From 696f49497b98d3069f1e70d07b4c83414d0bbb99 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Tue, 6 Mar 2018 14:46:32 -0800 Subject: Flesh out README --- packages/sra-report/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/sra-report/src/index.ts') diff --git a/packages/sra-report/src/index.ts b/packages/sra-report/src/index.ts index d292f15e1..83fb25d6c 100644 --- a/packages/sra-report/src/index.ts +++ b/packages/sra-report/src/index.ts @@ -39,7 +39,7 @@ const args = yargs }) .option('environment', { alias: ['env'], - describe: 'File path to an environment file for the collection run', + describe: 'The relative path to a postman environment file for the collection run', type: 'string', normalize: true, demandOption: false, -- cgit v1.2.3 From caf1a22084e9b633f903c493841129c43b8b598b Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Thu, 8 Mar 2018 08:24:37 -0800 Subject: Add support for ropsten and rinkeby --- packages/sra-report/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/sra-report/src/index.ts') diff --git a/packages/sra-report/src/index.ts b/packages/sra-report/src/index.ts index 83fb25d6c..d23549916 100644 --- a/packages/sra-report/src/index.ts +++ b/packages/sra-report/src/index.ts @@ -14,7 +14,7 @@ import { utils } from './utils'; const newmanRunAsync = promisify(newman.run); const DEFAULT_NETWORK_ID = 1; -const SUPPORTED_NETWORK_IDS = [1, 42]; +const SUPPORTED_NETWORK_IDS = [1, 3, 4, 42]; // extract command line arguments const args = yargs -- cgit v1.2.3