UNPKG

@jjdenhertog/ai-driven-development

Version:

AI-driven development workflow with learning capabilities for Claude

119 lines 6.79 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.initCommand = initCommand; const fs_extra_1 = require("fs-extra"); const node_path_1 = require("node:path"); const config_1 = require("../config"); const addCommands_1 = require("../utils/claude/addCommands"); const addToGitignore_1 = require("../utils/git/addToGitignore"); const checkGitInitialized_1 = require("../utils/git/checkGitInitialized"); const isInWorktree_1 = require("../utils/git/isInWorktree"); const logger_1 = require("../utils/logger"); const addTemplates_1 = require("../utils/claude/addTemplates"); const addPrompts_1 = require("../utils/claude/addPrompts"); function initCommand(options) { return __awaiter(this, void 0, void 0, function* () { const { force } = options; try { (0, logger_1.log)('Initializing aidev in current directory...', 'info'); // Check if git is initialized if (!(yield (0, checkGitInitialized_1.checkGitInitialized)())) { (0, logger_1.log)('Git repository not initialized. Please run "git init" first.', 'error'); throw new Error('Git repository not initialized'); } if (yield (0, isInWorktree_1.isInWorktree)()) throw new Error('You are in a worktree. Please exit the work tree folder and try again.'); // Create aidev-storage worktree (0, fs_extra_1.ensureDirSync)(config_1.STORAGE_PATH); (0, addToGitignore_1.addToGitignore)(process.cwd(), config_1.STORAGE_FOLDER); (0, addToGitignore_1.addToGitignore)(process.cwd(), '.aidev-containers', ''); ///////////////////////////////////////////// // // SETUP STORAGE // - Ensure needed folders // - Copy files // ///////////////////////////////////////////// // The templates folder is at the root of the package (../../templates from dist/commands/) // eslint-disable-next-line unicorn/prefer-module // Create subdirectories (0, fs_extra_1.ensureDirSync)((0, node_path_1.join)(config_1.STORAGE_PATH, 'tasks')); (0, fs_extra_1.ensureDirSync)((0, node_path_1.join)(config_1.STORAGE_PATH, 'concept')); // Copy examples folder const examplesSourceDir = (0, node_path_1.join)(config_1.TEMPLATES_ROOT, 'examples'); const examplesTargetDir = (0, node_path_1.join)(config_1.STORAGE_PATH, 'examples'); if (!(0, fs_extra_1.existsSync)(examplesTargetDir)) { (0, fs_extra_1.ensureDirSync)(examplesTargetDir); (0, fs_extra_1.copySync)(examplesSourceDir, examplesTargetDir, { overwrite: true }); (0, logger_1.log)('Copied examples folder', 'success'); } // Copy preferences folder const preferencesSourceDir = (0, node_path_1.join)(config_1.TEMPLATES_ROOT, 'preferences'); const preferencesTargetDir = (0, node_path_1.join)(config_1.STORAGE_PATH, 'preferences'); if (!(0, fs_extra_1.existsSync)(preferencesTargetDir)) { (0, fs_extra_1.ensureDirSync)(preferencesTargetDir); (0, fs_extra_1.copySync)(preferencesSourceDir, preferencesTargetDir, { overwrite: true }); (0, logger_1.log)('Copied preferences folder', 'success'); } (0, addPrompts_1.addPrompts)(); (0, addTemplates_1.addTemplates)(); ///////////////////////////////////////////// // // SETUP CONFIG FILE // - Create .aidev-storage/settings.json // ///////////////////////////////////////////// if (!(0, fs_extra_1.existsSync)(config_1.CONFIG_PATH)) { (0, fs_extra_1.writeFileSync)(config_1.CONFIG_PATH, JSON.stringify({ branchStartingPoint: 'main', mainBranch: 'main' }, null, 2)); (0, logger_1.log)('Config file created', 'success'); } ///////////////////////////////////////////// // // SETUP CLAUDE FILES // - Copy CLAUDE.md // - Copy .devcontainer // - Copy .claude/commands // ///////////////////////////////////////////// // Copy CLAUDE.md to root directory const claudeMdSource = (0, node_path_1.join)(config_1.TEMPLATES_ROOT, 'CLAUDE.md'); const claudeMdTarget = (0, node_path_1.join)(process.cwd(), 'CLAUDE.md'); if ((0, fs_extra_1.existsSync)(claudeMdTarget) && !force) { (0, logger_1.log)('CLAUDE.md already exists in root directory. Not overwriting, run --force to overwrite', 'warn'); } else { (0, fs_extra_1.copySync)(claudeMdSource, claudeMdTarget, { overwrite: true }); (0, logger_1.log)('Copied CLAUDE.md to root directory', 'success'); } // Copy .devcontainer to root directory const devcontainerSource = (0, node_path_1.join)(config_1.TEMPLATES_ROOT, 'devcontainers'); const devcontainerTarget = (0, node_path_1.join)(process.cwd(), '.aidev-containers'); if ((0, fs_extra_1.existsSync)(devcontainerTarget) && !force) { (0, logger_1.log)('.aidev-containers already exists in root directory. Not overwriting, run --force to overwrite', 'warn'); } else { (0, fs_extra_1.copySync)(devcontainerSource, devcontainerTarget, { overwrite: true }); (0, logger_1.log)('Copied .aidev-containers to root directory', 'success'); } (0, addCommands_1.addCommands)(); (0, logger_1.log)(`Copied Claude commands`); } catch (error) { (0, logger_1.log)(`Failed to initialize aidev: ${error instanceof Error ? error.message : String(error)}`, 'error'); throw error; } }); } //# sourceMappingURL=initCommand.js.map