domains / / bmad-code-org/bmad-method
Normalize Generated Output
When generating files/metadata, make output deterministic and cross-platform by normalizing both *paths* and *text line endings*, and by keeping shared formatting rules/filters centralized.
When generating files/metadata, make output deterministic and cross-platform by normalizing both paths and text line endings, and by keeping shared formatting rules/filters centralized.
Rules
- Normalize path separators in generated strings used in manifests/CSVs/etc. (e.g., convert
path.septo/). - Normalize line endings when emitting text files (e.g., Markdown). Build strings with
\n, then convert toos.EOL(or keep\nconsistently if the consumer expects it). - Centralize shared constants used in generation/copy/patch logic (e.g., exclusion dir sets) so every site uses the same rule.
- Avoid redundant requires/imports—use existing wrappers already in scope to reduce drift.
Example
import os from 'node:os';
import path from 'node:path';
function normalizeForCsv(relativePath) {
return relativePath.split(path.sep).join('/');
}
async function writeTextFileNormalized(fs, filePath, content) {
// Build with explicit \n, then adapt to platform
const platformContent = os.EOL === '\n' ? content : content.replace(/\r?\n/g, os.EOL);
await fs.writeFile(filePath, platformContent, 'utf8');
}