UNPKG

@deepbrainspace/nx-surrealdb

Version:

NX plugin for SurrealDB migrations with modular architecture

72 lines (70 loc) โ€ข 3.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = default_1; const devkit_1 = require("@nx/devkit"); async function default_1(tree, options) { const normalizedOptions = normalizeOptions(options); devkit_1.logger.info(`๐Ÿ—‘๏ธ Destroying database project: ${normalizedOptions.projectName}`); // Get all projects to find the target const projects = (0, devkit_1.getProjects)(tree); const project = projects.get(normalizedOptions.projectName); if (!project) { throw new Error(`Project '${normalizedOptions.projectName}' not found in workspace`); } devkit_1.logger.info(`๐Ÿ“ Found project at: ${project.root}`); // Check if user confirmed destruction (either via --force or interactive prompt) if (!normalizedOptions.force) { if (!normalizedOptions.confirmed) { devkit_1.logger.warn(`โš ๏ธ This will permanently delete the project '${normalizedOptions.projectName}' and all its files.`); devkit_1.logger.warn(`๐Ÿ“‚ Location: ${project.root}`); devkit_1.logger.warn(`๐Ÿ’ก Use --force to bypass this confirmation`); throw new Error(`Destruction cancelled. Use --force flag to proceed with deletion.`); } } // 1. Remove NX project configuration devkit_1.logger.info(`๐Ÿ“ Removing project configuration from workspace...`); (0, devkit_1.removeProjectConfiguration)(tree, normalizedOptions.projectName); // 2. Remove all project files and directories devkit_1.logger.info(`๐Ÿ—‚๏ธ Removing project files: ${project.root}`); if (tree.exists(project.root)) { tree.delete(project.root); } // 3. Clean up any potential dependencies in package.json // Note: Most NX projects don't add deps to root package.json, but we'll check if (tree.exists('package.json')) { const packageJson = JSON.parse(tree.read('package.json', 'utf-8')); let modified = false; // Remove any surrealdb-related dependencies that might have been added const depsToCheck = ['dependencies', 'devDependencies', 'peerDependencies']; for (const depType of depsToCheck) { if (packageJson[depType] && packageJson[depType]['surrealdb']) { delete packageJson[depType]['surrealdb']; modified = true; devkit_1.logger.info(`๐Ÿงน Removed surrealdb dependency from ${depType}`); } } if (modified) { tree.write('package.json', JSON.stringify(packageJson, null, 2)); } } devkit_1.logger.info(`โœ… Project '${normalizedOptions.projectName}' destroyed successfully!`); devkit_1.logger.info(`๐ŸŽฏ You can now safely run: nx g @deepbrainspace/nx-surrealdb:init ${normalizedOptions.projectName}`); return () => { devkit_1.logger.info(` ๐ŸŽ‰ Destruction completed! Project: ${normalizedOptions.projectName} Status: Completely removed from workspace Next steps: 1. Verify with: nx show projects 2. Re-create with: nx g @deepbrainspace/nx-surrealdb:init ${normalizedOptions.projectName} `); }; } function normalizeOptions(options) { return { ...options, force: options.force ?? false, confirmed: options.confirmed ?? false, }; } //# sourceMappingURL=generator.js.map