mirror of
https://github.com/bmadcode/BMAD-METHOD.git
synced 2025-12-29 16:14:59 +00:00
fix: installer improvement
This commit is contained in:
@@ -47,7 +47,7 @@ class FileManager {
|
||||
}
|
||||
}
|
||||
|
||||
async copyGlobPattern(pattern, sourceDir, destDir) {
|
||||
async copyGlobPattern(pattern, sourceDir, destDir, rootValue = null) {
|
||||
const files = glob.sync(pattern, { cwd: sourceDir });
|
||||
const copied = [];
|
||||
|
||||
@@ -55,7 +55,17 @@ class FileManager {
|
||||
const sourcePath = path.join(sourceDir, file);
|
||||
const destPath = path.join(destDir, file);
|
||||
|
||||
if (await this.copyFile(sourcePath, destPath)) {
|
||||
// Use root replacement if rootValue is provided and file needs it
|
||||
const needsRootReplacement = rootValue && (file.endsWith('.md') || file.endsWith('.yaml') || file.endsWith('.yml'));
|
||||
|
||||
let success = false;
|
||||
if (needsRootReplacement) {
|
||||
success = await this.copyFileWithRootReplacement(sourcePath, destPath, rootValue);
|
||||
} else {
|
||||
success = await this.copyFile(sourcePath, destPath);
|
||||
}
|
||||
|
||||
if (success) {
|
||||
copied.push(file);
|
||||
}
|
||||
}
|
||||
@@ -299,6 +309,71 @@ class FileManager {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async copyFileWithRootReplacement(source, destination, rootValue) {
|
||||
try {
|
||||
// Read the source file content
|
||||
const fs = require('fs').promises;
|
||||
const content = await fs.readFile(source, 'utf8');
|
||||
|
||||
// Replace {root} with the specified root value
|
||||
const updatedContent = content.replace(/\{root\}/g, rootValue);
|
||||
|
||||
// Ensure directory exists
|
||||
await this.ensureDirectory(path.dirname(destination));
|
||||
|
||||
// Write the updated content
|
||||
await fs.writeFile(destination, updatedContent, 'utf8');
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
await initializeModules();
|
||||
console.error(chalk.red(`Failed to copy ${source} with root replacement:`), error.message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async copyDirectoryWithRootReplacement(source, destination, rootValue, fileExtensions = ['.md', '.yaml', '.yml']) {
|
||||
try {
|
||||
await initializeModules(); // Ensure chalk is initialized
|
||||
await this.ensureDirectory(destination);
|
||||
|
||||
// Get all files in source directory
|
||||
const files = glob.sync('**/*', {
|
||||
cwd: source,
|
||||
nodir: true
|
||||
});
|
||||
|
||||
let replacedCount = 0;
|
||||
|
||||
for (const file of files) {
|
||||
const sourcePath = path.join(source, file);
|
||||
const destPath = path.join(destination, file);
|
||||
|
||||
// Check if this file type should have {root} replacement
|
||||
const shouldReplace = fileExtensions.some(ext => file.endsWith(ext));
|
||||
|
||||
if (shouldReplace) {
|
||||
if (await this.copyFileWithRootReplacement(sourcePath, destPath, rootValue)) {
|
||||
replacedCount++;
|
||||
}
|
||||
} else {
|
||||
// Regular copy for files that don't need replacement
|
||||
await this.copyFile(sourcePath, destPath);
|
||||
}
|
||||
}
|
||||
|
||||
if (replacedCount > 0) {
|
||||
console.log(chalk.dim(` Processed ${replacedCount} files with {root} replacement`));
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
await initializeModules();
|
||||
console.error(chalk.red(`Failed to copy directory ${source} with root replacement:`), error.message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new FileManager();
|
||||
|
||||
Reference in New Issue
Block a user