yaml-verify
Advanced tools
Comparing version 1.0.13 to 1.0.14
{ | ||
"name": "yaml-verify", | ||
"version": "1.0.13", | ||
"version": "1.0.14", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "description": "A CLI utility to ensure proper formatting of YAML files.", |
@@ -25,3 +25,3 @@ #!/usr/bin/env node | ||
data.layoutAssignments.forEach((item, index) => { | ||
data.layoutAssignments.forEach((item) => { | ||
const layout = item.layout | ||
@@ -52,3 +52,3 @@ const recordType = item.recordType || 'noRecordType' | ||
value.forEach((item, index) => { | ||
value.forEach((item) => { | ||
const itemKey = JSON.stringify(item) | ||
@@ -107,3 +107,3 @@ | ||
// Update the spinner text to show progress | ||
spinner.text = `Validating YAML files... ${index + batch.length}/${files.length} files processed`; | ||
spinner.text = `Validating YAML files... ${index + batch.length}/${files.length} files processed` | ||
@@ -138,2 +138,11 @@ index += batchSize | ||
// Function to check if the provided path exists | ||
async function checkPathExists(path) { | ||
try { | ||
await fs.promises.stat(path) | ||
} catch (error) { | ||
throw new Error(`Path does not exist: ${path}`) | ||
} | ||
} | ||
// Setting up the CLI utility with commander | ||
@@ -146,13 +155,22 @@ program | ||
showSuccess = program.opts().showSuccess // Update the showSuccess flag based on the command line option | ||
let allFilesPromises = filePaths.map(async (filePath) => { | ||
// Check if all provided paths exist | ||
try { | ||
await Promise.all(filePaths.map(checkPathExists)) | ||
} catch (error) { | ||
console.error(chalk.red(error.message)) | ||
process.exit(1) | ||
} | ||
let allFiles = [] | ||
for (const filePath of filePaths) { | ||
const stat = await fs.promises.stat(filePath) | ||
if (stat.isDirectory()) { | ||
return findYamlFilesAsync(filePath) | ||
const files = await findYamlFilesAsync(filePath) | ||
allFiles = allFiles.concat(files) // Use concat instead of push with spread to avoid call stack issues | ||
} else { | ||
allFiles.push(filePath) | ||
} | ||
return [filePath] | ||
}) | ||
} | ||
let allFilesArrays = await Promise.all(allFilesPromises) | ||
let allFiles = allFilesArrays.flat() | ||
await processFilesInBatches(allFiles).catch((e) => { | ||
@@ -185,5 +203,3 @@ console.error(chalk.red('An error occurred:'), e) | ||
console.log(chalk.yellow('\nProcess interrupted by user. Exiting...')) | ||
// Perform any necessary cleanup here | ||
process.exit(1) // Exit with a non-zero status code to indicate interruption | ||
}) |
10706
186