stackvalidator
Advanced tools
Comparing version 0.1.1 to 0.1.2
34
index.js
@@ -23,8 +23,12 @@ 'use strict'; | ||
const templates = []; | ||
let counter = 0; | ||
klaw(rootPath) | ||
.on('data', item => { | ||
const ext = path.extname(item.path) | ||
const ext = path.extname(item.path); | ||
if (['.yml', '.json'].includes(ext)) { | ||
const contents = fs.readFileSync(item.path).toString(); | ||
if ((/AWSTemplateFormatVersion/g).test(contents)){ | ||
counter = counter + 1; | ||
if (counter > 1000) { | ||
return reject(new Error(`Lots of json and yml files found, is '${rootPath}/*' really the path you want to validate?`)) | ||
} else if ((/AWSTemplateFormatVersion/g).test(contents)){ | ||
templates.push(item); | ||
@@ -34,4 +38,4 @@ } | ||
}) | ||
.on('error', (err, item) => | ||
reject(new Error({ error, item }))) | ||
.on('error', (error, item) => | ||
reject(error)) | ||
.on('end', () => | ||
@@ -67,10 +71,16 @@ resolve({ templates })); | ||
async function validateTemplates(rootPath, delay) { | ||
const { templates } = await readTemplates(rootPath); | ||
const templatePaths = templates.map(template => template.path); | ||
console.log(chalk.yellow(`Found ${templatePaths.length} template${templatePaths.length !== 1 ? 's' : ''}\r\n${rootPath}`)); | ||
console.log(chalk.yellow(templatePaths.join(',\n').replace(new RegExp(rootPath, 'g'), ' └ '))); | ||
console.log(chalk.yellow('---------------------------')); | ||
templatePaths.forEach(template => | ||
queue.add(() => | ||
validateTemplate(template, delay))); | ||
try { | ||
const { templates } = await readTemplates(rootPath); | ||
const templatePaths = templates.map(template => template.path); | ||
console.log(chalk.yellow(`Found ${templatePaths.length} template${templatePaths.length !== 1 ? 's' : ''}\r\n${rootPath}`)); | ||
console.log(chalk.yellow(templatePaths.join(',\n').replace(new RegExp(rootPath, 'g'), ' └ '))); | ||
console.log(chalk.yellow('---------------------------')); | ||
templatePaths.forEach(template => | ||
queue.add(() => | ||
validateTemplate(template, delay))); | ||
} catch (exception) { | ||
console.log(chalk.red(`[ERROR] ${exception.message}`)); | ||
process.exit(1); | ||
} | ||
} | ||
@@ -77,0 +87,0 @@ |
@@ -6,3 +6,3 @@ { | ||
}, | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"author": "Eetu Tuomala", | ||
@@ -9,0 +9,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51659
103