Add support for custom environment file
This commit is contained in:
parent
551771235b
commit
ddad09a936
@ -1,6 +1,5 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
import { assert } from '@0xproject/assert';
|
import { assert } from '@0xproject/assert';
|
||||||
import { HttpClient } from '@0xproject/connect';
|
|
||||||
import { Schema, schemas } from '@0xproject/json-schemas';
|
import { Schema, schemas } from '@0xproject/json-schemas';
|
||||||
import { promisify } from '@0xproject/utils';
|
import { promisify } from '@0xproject/utils';
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
@ -38,6 +37,13 @@ const args = yargs
|
|||||||
type: 'number',
|
type: 'number',
|
||||||
default: DEFAULT_NETWORK_ID,
|
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', {
|
.option('export-collection', {
|
||||||
alias: ['ec'],
|
alias: ['ec'],
|
||||||
describe: 'The relative path to write the postman collection file used by the collection run',
|
describe: 'The relative path to write the postman collection file used by the collection run',
|
||||||
@ -53,7 +59,7 @@ const args = yargs
|
|||||||
demandOption: false,
|
demandOption: false,
|
||||||
})
|
})
|
||||||
.example(
|
.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',
|
'Full usage example',
|
||||||
).argv;
|
).argv;
|
||||||
// perform extra validation on command line arguments
|
// perform extra validation on command line arguments
|
||||||
@ -69,12 +75,6 @@ if (!_.includes(SUPPORTED_NETWORK_IDS, args.networkId)) {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
const mainAsync = async () => {
|
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)
|
const newmanReporterOptions = !_.isUndefined(args.output)
|
||||||
? {
|
? {
|
||||||
reporters: 'json',
|
reporters: 'json',
|
||||||
@ -87,9 +87,12 @@ const mainAsync = async () => {
|
|||||||
: {
|
: {
|
||||||
reporters: 'cli',
|
reporters: 'cli',
|
||||||
};
|
};
|
||||||
|
const environment = !_.isUndefined(args.environment)
|
||||||
|
? args.environment
|
||||||
|
: await postmanEnvironmentFactory.createPostmanEnvironmentAsync(args.endpointUrl, args.networkId);
|
||||||
const newmanRunOptions = {
|
const newmanRunOptions = {
|
||||||
collection: sraReportCollectionJSON,
|
collection: sraReportCollectionJSON,
|
||||||
environment: postmanEnvironmentFactory.createPostmanEnvironment(args.endpointUrl, args.networkId, firstOrder),
|
environment,
|
||||||
exportCollection: args.exportCollection,
|
exportCollection: args.exportCollection,
|
||||||
exportEnvironment: args.exportEnvironment,
|
exportEnvironment: args.exportEnvironment,
|
||||||
...newmanReporterOptions,
|
...newmanReporterOptions,
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { SignedOrder, ZeroEx } from '0x.js';
|
import { SignedOrder, ZeroEx } from '0x.js';
|
||||||
|
import { HttpClient } from '@0xproject/connect';
|
||||||
import { Schema, schemas as schemasByName } from '@0xproject/json-schemas';
|
import { Schema, schemas as schemasByName } from '@0xproject/json-schemas';
|
||||||
import * as _ from 'lodash';
|
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)
|
* - Contract addresses based on the network id for making specific queries (ex. baseTokenAddress=ZRX_address)
|
||||||
* - Order properties for making specific queries (ex. maker=orderMaker)
|
* - 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 schemas: Schema[] = _.values(schemasByName);
|
||||||
const schemaEnvironmentValues = _.compact(
|
const schemaEnvironmentValues = _.compact(
|
||||||
_.map(schemas, (schema: Schema) => {
|
_.map(schemas, (schema: Schema) => {
|
||||||
@ -40,16 +41,22 @@ export const postmanEnvironmentFactory = {
|
|||||||
const contractAddress = _.get(contractAddresses, key);
|
const contractAddress = _.get(contractAddresses, key);
|
||||||
return createEnvironmentValue(key, contractAddress);
|
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(
|
const allEnvironmentValues = _.concat(
|
||||||
schemaEnvironmentValues,
|
schemaEnvironmentValues,
|
||||||
contractAddressEnvironmentValues,
|
contractAddressEnvironmentValues,
|
||||||
createEnvironmentValue('schemaKeys', JSON.stringify(schemaKeys)),
|
createEnvironmentValue('schemaKeys', JSON.stringify(schemaKeys)),
|
||||||
createEnvironmentValue('url', url),
|
createEnvironmentValue('url', url),
|
||||||
createEnvironmentValue('order', JSON.stringify(order)),
|
createEnvironmentValue('order', JSON.stringify(firstOrder)),
|
||||||
createEnvironmentValue('orderMaker', order.maker),
|
createEnvironmentValue('orderMaker', firstOrder.maker),
|
||||||
createEnvironmentValue('orderTaker', order.taker),
|
createEnvironmentValue('orderTaker', firstOrder.taker),
|
||||||
createEnvironmentValue('orderFeeRecipient', order.feeRecipient),
|
createEnvironmentValue('orderFeeRecipient', firstOrder.feeRecipient),
|
||||||
createEnvironmentValue('orderHash', ZeroEx.getOrderHashHex(order)),
|
createEnvironmentValue('orderHash', ZeroEx.getOrderHashHex(firstOrder)),
|
||||||
);
|
);
|
||||||
const environment = {
|
const environment = {
|
||||||
values: allEnvironmentValues,
|
values: allEnvironmentValues,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user