ai-doc-sync
Version:
Tool to synchronize AI documentation to Cursor rules, Cline rules and Devin knowledge base
95 lines (94 loc) • 4.03 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.AiDocSynchronizer = void 0;
const path = __importStar(require("path"));
const fileUtils_1 = require("./utils/fileUtils");
const cursorConverter_1 = require("./converters/cursorConverter");
const clineConverter_1 = require("./converters/clineConverter");
const devinApi_1 = require("./api/devinApi");
class AiDocSynchronizer {
constructor(config) {
this.devinApiClient = null;
this.config = config;
if (config.devinApiToken) {
this.devinApiClient = new devinApi_1.DevinApiClient(config.devinApiToken);
}
}
async synchronize(basePath = process.cwd()) {
const aiDocPath = path.resolve(basePath, this.config.aiDocumentPath);
const markdownFiles = (0, fileUtils_1.findMarkdownFiles)(aiDocPath);
let cursorCount = 0;
let clineCount = 0;
let devinCount = 0;
for (const filePath of markdownFiles) {
const document = (0, fileUtils_1.readMarkdownFile)(filePath);
if (!document)
continue;
if (this.config.cursorRulesPath) {
const cursorRulesDir = path.resolve(basePath, this.config.cursorRulesPath);
const extension = this.config.cursorRuleExtension || 'mdc';
const result = (0, cursorConverter_1.convertToCursorRules)(document, cursorRulesDir, extension);
if (result.success) {
console.log(`Converted to Cursor rule: ${result.outputPath}`);
cursorCount++;
}
else {
console.error(result.error);
}
}
if (this.config.clineRulesPath) {
const clineRulesDir = path.resolve(basePath, this.config.clineRulesPath);
const result = (0, clineConverter_1.convertToClineRules)(document, clineRulesDir);
if (result.success) {
console.log(`Converted to Cline rule: ${result.outputPath}`);
clineCount++;
}
else {
console.error(result.error);
}
}
if (this.devinApiClient) {
const result = await this.devinApiClient.createKnowledge(document);
if (result) {
console.log(`Registered to Devin knowledge base: ${result.id}`);
devinCount++;
}
}
}
return { cursor: cursorCount, cline: clineCount, devin: devinCount };
}
}
exports.AiDocSynchronizer = AiDocSynchronizer;