Add support for custom environment file

This commit is contained in:
Brandon Millman 2018-03-06 00:44:18 -08:00
parent 551771235b
commit ddad09a936
2 changed files with 25 additions and 15 deletions

View File

@ -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,

View File

@ -1,4 +1,5 @@
import { SignedOrder, ZeroEx } from '0x.js';
import { HttpClient } from '@0xproject/connect';
import { Schema, schemas as schemasByName } from '@0xproject/json-schemas';
import * as _ from 'lodash';
@ -18,7 +19,7 @@ export const postmanEnvironmentFactory = {
* - Contract addresses based on the network id for making specific queries (ex. baseTokenAddress=ZRX_address)
* - Order properties for making specific queries (ex. maker=orderMaker)
*/
createPostmanEnvironment(url: string, networkId: number, order: SignedOrder) {
async createPostmanEnvironmentAsync(url: string, networkId: number) {
const schemas: Schema[] = _.values(schemasByName);
const schemaEnvironmentValues = _.compact(
_.map(schemas, (schema: Schema) => {
@ -40,16 +41,22 @@ export const postmanEnvironmentFactory = {
const contractAddress = _.get(contractAddresses, key);
return createEnvironmentValue(key, contractAddress);
});
const httpClient = new HttpClient(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 allEnvironmentValues = _.concat(
schemaEnvironmentValues,
contractAddressEnvironmentValues,
createEnvironmentValue('schemaKeys', JSON.stringify(schemaKeys)),
createEnvironmentValue('url', url),
createEnvironmentValue('order', JSON.stringify(order)),
createEnvironmentValue('orderMaker', order.maker),
createEnvironmentValue('orderTaker', order.taker),
createEnvironmentValue('orderFeeRecipient', order.feeRecipient),
createEnvironmentValue('orderHash', ZeroEx.getOrderHashHex(order)),
createEnvironmentValue('order', JSON.stringify(firstOrder)),
createEnvironmentValue('orderMaker', firstOrder.maker),
createEnvironmentValue('orderTaker', firstOrder.taker),
createEnvironmentValue('orderFeeRecipient', firstOrder.feeRecipient),
createEnvironmentValue('orderHash', ZeroEx.getOrderHashHex(firstOrder)),
);
const environment = {
values: allEnvironmentValues,