repoweaver
Version:
A GitHub App that skillfully weaves multiple templates together to create and update repositories with intelligent merge strategies
144 lines • 5.65 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.Bootstrapper = void 0;
const simple_git_1 = require("simple-git");
const path = __importStar(require("path"));
const template_manager_1 = require("./template-manager");
class Bootstrapper {
constructor() {
this.templateManager = new template_manager_1.TemplateManager();
this.git = (0, simple_git_1.simpleGit)();
}
async bootstrap(options) {
const result = {
success: true,
repositoryPath: path.resolve(options.targetPath),
templateResults: [],
totalFilesProcessed: 0,
errors: []
};
try {
// Process each template
for (const template of options.templates) {
const templateResult = await this.templateManager.processTemplate(template, result.repositoryPath, options.excludePatterns);
result.templateResults.push(templateResult);
result.totalFilesProcessed += templateResult.filesProcessed;
if (!templateResult.success) {
result.success = false;
result.errors.push(...templateResult.errors);
}
}
// Initialize git repository if requested
if (options.initGit) {
await this.initializeGitRepository(result.repositoryPath, options.addRemote);
}
}
catch (error) {
result.success = false;
result.errors.push(`Bootstrap failed: ${error}`);
}
finally {
await this.templateManager.cleanup();
}
return result;
}
async updateRepository(options) {
const result = {
success: true,
repositoryPath: path.resolve(options.targetPath),
templateResults: [],
totalFilesProcessed: 0,
errors: []
};
try {
// Check if target is a git repository
const isGitRepo = await this.isGitRepository(result.repositoryPath);
if (!isGitRepo) {
throw new Error('Target directory is not a git repository. Use bootstrap for new repositories.');
}
// Process templates with merge strategy
for (const template of options.templates) {
const templateResult = await this.processTemplateUpdate(template, result.repositoryPath, options.mergeStrategy || 'merge', options.excludePatterns);
result.templateResults.push(templateResult);
result.totalFilesProcessed += templateResult.filesProcessed;
if (!templateResult.success) {
result.success = false;
result.errors.push(...templateResult.errors);
}
}
}
catch (error) {
result.success = false;
result.errors.push(`Update failed: ${error}`);
}
finally {
await this.templateManager.cleanup();
}
return result;
}
async processTemplateUpdate(template, targetPath, mergeStrategy, excludePatterns) {
// For now, delegate to the template manager
// In the future, this could implement more sophisticated merge strategies
return this.templateManager.processTemplate(template, targetPath, excludePatterns);
}
async initializeGitRepository(repositoryPath, remoteUrl) {
const git = (0, simple_git_1.simpleGit)(repositoryPath);
try {
await git.init();
if (remoteUrl) {
await git.addRemote('origin', remoteUrl);
}
// Add all files and make initial commit
await git.add('.');
await git.commit('Initial commit from RepoWeaver');
}
catch (error) {
throw new Error(`Git initialization failed: ${error}`);
}
}
async isGitRepository(repositoryPath) {
try {
const git = (0, simple_git_1.simpleGit)(repositoryPath);
await git.status();
return true;
}
catch {
return false;
}
}
}
exports.Bootstrapper = Bootstrapper;
//# sourceMappingURL=bootstrapper.js.map