Skip to content

Commit

Permalink
Use new AutoRest CLI in order to leverage correct source locations (#…
Browse files Browse the repository at this point in the history
…1099)

* use new AutoRest CLI in order to leverage correct source locations

* fixed up getStatus.js
  • Loading branch information
olydis authored Apr 20, 2017
1 parent 0cd4da9 commit cac5220
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 31 deletions.
61 changes: 31 additions & 30 deletions scripts/getStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion test/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit cac5220

Please sign in to comment.