From cac52200125be67839dc5e2a39e46a6d765452b3 Mon Sep 17 00:00:00 2001 From: Johannes Bader Date: Thu, 20 Apr 2017 09:42:00 -0700 Subject: [PATCH] Use new AutoRest CLI in order to leverage correct source locations (#1099) * use new AutoRest CLI in order to leverage correct source locations * fixed up getStatus.js --- scripts/getStatus.js | 61 ++++++++++++++++++++++---------------------- test/linter.js | 2 +- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/scripts/getStatus.js b/scripts/getStatus.js index e3de894c4b8b..9d3f0ffea051 100644 --- a/scripts/getStatus.js +++ b/scripts/getStatus.js @@ -2,7 +2,7 @@ // Licensed under the MIT License. See License in the project root for license information. 'use strict'; -var execSync = require('child_process').execSync, +var exec = require('child_process').exec, path = require('path'), fs = require('fs'), glob = require('glob'), @@ -86,35 +86,36 @@ function executePromisesSequentially(promiseFactories) { //runs the linter on a given swagger spec. function runLinter(swagger) { - let cmd = 'autorest -CodeGenerator None -I ' + swagger + ' -JsonValidationMessages true'; - console.log(`\t- Running Linter.`); - let resultString = '', resultObj = []; - try { - resultString = execSync(cmd, { encoding: 'utf8' }); - } catch (err) { - if (err.stdout && !err.stderr) { - resultString = err.stdout; - } else { - console.log(`An error occurred while running the linter on ${swagger}:`); - console.dir(err, { depth: null, colors: true }); - } - } - //console.log('>>>> Actual result...'); - //console.log(resultString); - if (resultString) { - resultString = resultString.trim().substring(resultString.indexOf('[')); - //console.log('>>>>>> Trimmed Result...'); - //console.log(resultString); - try { - resultObj = JSON.parse(resultString); - //console.log('>>>>>> Parsed Result...'); - //console.dir(resultObj, {depth: null, colors: true}); - } catch (e) { - console.log(`An error occurred while executing JSON.parse() on the linter output for ${swagger}:`); - console.dir(e, { depth: null, colors: true }); - } - } - return Promise.resolve(resultObj); + return new Promise((res) => { + let cmd = 'autorest --azure-arm=true --input-file=' + swagger + ' --message-format=json'; + console.log(`\t- Running Linter.`); + exec(cmd, { encoding: 'utf8', maxBuffer: 1024 * 1024 * 64 }, (err, stdout, stderr) => { + let resultObject = []; + if (err) { + console.log(`An error occurred while running the linter on ${swagger}:`); + console.dir(err, { depth: null, colors: true }); + } else { + //console.log('>>>> Actual result...'); + //console.log(resultString); + let resultString = stdout + stderr; + if (resultString.indexOf('{') !== -1) { + resultString = "[" + resultString.substring(resultString.indexOf('{')).trim().replace(/\}\n\{/g, "},\n{") + "]"; + //console.log('>>>>>> Trimmed Result...'); + //console.log(resultString); + try { + resultObject = JSON.parse(resultString); + //console.log('>>>>>> Parsed Result...'); + //console.dir(resultObject, {depth: null, colors: true}); + } catch (e) { + console.log(`An error occurred while executing JSON.parse() on the linter output for ${swagger}:`); + console.dir(resultString); + console.dir(e, { depth: null, colors: true }); + } + } + } + res(resultObject); + }); + }); } //runs the semantic validator on a given swagger spec. diff --git a/test/linter.js b/test/linter.js index 19054816f0d5..3c05b51af818 100644 --- a/test/linter.js +++ b/test/linter.js @@ -15,7 +15,7 @@ describe('AutoRest Linter validation:', function () { // }); _(swaggersToProcess).each(function (swagger) { it(swagger + ' should honor linter validation rules.', function (done) { - var cmd = 'autorest -CodeGenerator None -I ' + swagger + ' -JsonValidationMessages true'; + var cmd = 'autorest --azure-arm=true --input-file=' + swagger + ' --message-format=json'; console.log(`Executing: ${cmd}`); let result; try {