diff options
author | Fabio Berger <me@fabioberger.com> | 2018-03-09 15:39:38 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-03-09 15:39:38 +0800 |
commit | 9699ee4eff8a6594bd862883cac35de80dfbcf56 (patch) | |
tree | 01c5a092bd0180101dcc012e3d21320d9addb073 /packages/sra-report/src/index.ts | |
parent | da277f5b2743c666a9a66e4fadf6678edd44fd69 (diff) | |
parent | 0eeaac1f2b5095441f7cd04bc948515d600d1f3a (diff) | |
download | dexon-sol-tools-9699ee4eff8a6594bd862883cac35de80dfbcf56.tar dexon-sol-tools-9699ee4eff8a6594bd862883cac35de80dfbcf56.tar.gz dexon-sol-tools-9699ee4eff8a6594bd862883cac35de80dfbcf56.tar.bz2 dexon-sol-tools-9699ee4eff8a6594bd862883cac35de80dfbcf56.tar.lz dexon-sol-tools-9699ee4eff8a6594bd862883cac35de80dfbcf56.tar.xz dexon-sol-tools-9699ee4eff8a6594bd862883cac35de80dfbcf56.tar.zst dexon-sol-tools-9699ee4eff8a6594bd862883cac35de80dfbcf56.zip |
Merge branch 'development' into addPackagePublishConfig
* development: (94 commits)
Update CHANGELOG
Add solc 0.4.20 and 0.4.21
Prettier sra-report README
Add new packages to top level README
Updated @0xproject/utils in top level package.json
Publish
Updated CHANGELOGs
Detail tests in the README
Add support for ropsten and rinkeby
Fix yarn.lock
Update list of packages and organize them alphabetically
Fix prettier issues
Add support for going back to previous hashes via the browser back button to wiki
Scroll to previous hashed elements when user clicks back button
Add back strict null checks to react-shared package and fix issues
remove ability to have implicit dependencies and add missing deps
update license
remove no-implicit-this
Add example & screenshot to npmignore
Remove `;` to be nice to windows users
...
Diffstat (limited to 'packages/sra-report/src/index.ts')
-rw-r--r-- | packages/sra-report/src/index.ts | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/packages/sra-report/src/index.ts b/packages/sra-report/src/index.ts new file mode 100644 index 000000000..d23549916 --- /dev/null +++ b/packages/sra-report/src/index.ts @@ -0,0 +1,102 @@ +#!/usr/bin/env node +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 { postmanEnvironmentFactory } from './postman_environment_factory'; +import { utils } from './utils'; + +const newmanRunAsync = promisify<void>(newman.run); +const DEFAULT_NETWORK_ID = 1; +const SUPPORTED_NETWORK_IDS = [1, 3, 4, 42]; + +// extract command line arguments +const args = yargs + .option('endpoint-url', { + alias: ['e'], + describe: 'API endpoint url to test for standard relayer API compliance', + type: 'string', + demandOption: true, + }) + .option('output', { + alias: ['o', 'out'], + describe: 'The relative path to write the report generated by the collection run, prints to console by default', + 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, + }) + .option('environment', { + alias: ['env'], + describe: 'The relative path to a postman 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', + 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 --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 +try { + assert.isWebUri('args', args.endpointUrl); +} catch (err) { + utils.log(`${chalk.red(`Invalid url format:`)} ${args.endpointUrl}`); + 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); +} +const mainAsync = async () => { + const newmanReporterOptions = !_.isUndefined(args.output) + ? { + reporters: 'json', + reporter: { + json: { + export: args.output, + }, + }, + } + : { + reporters: 'cli', + }; + const environment = !_.isUndefined(args.environment) + ? args.environment + : await postmanEnvironmentFactory.createPostmanEnvironmentAsync(args.endpointUrl, args.networkId); + const newmanRunOptions = { + collection: sraReportCollectionJSON, + environment, + exportCollection: args.exportCollection, + exportEnvironment: args.exportEnvironment, + ...newmanReporterOptions, + }; + await newmanRunAsync(newmanRunOptions); +}; +mainAsync().catch(utils.log); |