Add options for exporting environment and collection files
This commit is contained in:
		@@ -27,7 +27,7 @@ const args = yargs
 | 
				
			|||||||
    })
 | 
					    })
 | 
				
			||||||
    .option('output', {
 | 
					    .option('output', {
 | 
				
			||||||
        alias: ['o', 'out'],
 | 
					        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',
 | 
					        type: 'string',
 | 
				
			||||||
        normalize: true,
 | 
					        normalize: true,
 | 
				
			||||||
        demandOption: false,
 | 
					        demandOption: false,
 | 
				
			||||||
@@ -38,7 +38,21 @@ const args = yargs
 | 
				
			|||||||
        type: 'number',
 | 
					        type: 'number',
 | 
				
			||||||
        default: DEFAULT_NETWORK_ID,
 | 
					        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;
 | 
					    .argv;
 | 
				
			||||||
// perform extra validation on command line arguments
 | 
					// perform extra validation on command line arguments
 | 
				
			||||||
try {
 | 
					try {
 | 
				
			||||||
@@ -52,7 +66,6 @@ if (!_.includes(SUPPORTED_NETWORK_IDS, args.networkId)) {
 | 
				
			|||||||
    utils.log(`${chalk.bold(`Supported network ids:`)} ${SUPPORTED_NETWORK_IDS}`);
 | 
					    utils.log(`${chalk.bold(`Supported network ids:`)} ${SUPPORTED_NETWORK_IDS}`);
 | 
				
			||||||
    process.exit(1);
 | 
					    process.exit(1);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
const mainAsync = async () => {
 | 
					const mainAsync = async () => {
 | 
				
			||||||
    const httpClient = new HttpClient(args.endpointUrl);
 | 
					    const httpClient = new HttpClient(args.endpointUrl);
 | 
				
			||||||
    const orders = await httpClient.getOrdersAsync();
 | 
					    const orders = await httpClient.getOrdersAsync();
 | 
				
			||||||
@@ -75,6 +88,8 @@ const mainAsync = async () => {
 | 
				
			|||||||
    const newmanRunOptions = {
 | 
					    const newmanRunOptions = {
 | 
				
			||||||
        collection: sraReportCollectionJSON,
 | 
					        collection: sraReportCollectionJSON,
 | 
				
			||||||
        environment: postmanEnvironmentFactory.createPostmanEnvironment(args.endpointUrl, args.networkId, firstOrder),
 | 
					        environment: postmanEnvironmentFactory.createPostmanEnvironment(args.endpointUrl, args.networkId, firstOrder),
 | 
				
			||||||
 | 
					        exportCollection: args.exportCollection,
 | 
				
			||||||
 | 
					        exportEnvironment: args.exportEnvironment,
 | 
				
			||||||
        ...newmanReporterOptions,
 | 
					        ...newmanReporterOptions,
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    await newmanRunAsync(newmanRunOptions);
 | 
					    await newmanRunAsync(newmanRunOptions);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user