skaya
Version:
CLI SDK for full-stack automation: scaffold frontend, backend & blockchain. Future-ready for Web3, integrations, server components & logging.
91 lines (90 loc) • 5.12 kB
JavaScript
;
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());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleComponentImport = handleComponentImport;
const inquirer_1 = __importDefault(require("inquirer"));
const ProjectScanner_1 = require("../../../bin/utils/ProjectScanner");
const componentConfig = (0, ProjectScanner_1.loadComponentConfig)();
function handleComponentImport(projectType, componentType) {
return __awaiter(this, void 0, void 0, function* () {
const configKey = `${projectType}.${componentType}`;
const config = componentConfig[configKey] || {
importQuestion: `Would you like to import existing ${componentType} components?`,
selectMessage: `Select ${componentType} components to import:`,
scanType: projectType,
requiredImports: [],
};
// Updated the type definition for the values in the dependencies record.
const dependencies = {};
let importExisting = false;
// This array will remain empty as per the new logic, but its type is updated for consistency.
const componentsToImport = [];
const requiredImports = config.requiredImports || [];
if (requiredImports.length > 0) {
const { selectedRequiredImports } = yield inquirer_1.default.prompt([
{
type: "checkbox",
name: "selectedRequiredImports",
message: `Select which required components you would like to import:`,
choices: requiredImports.map((comp) => ({ name: comp, value: comp })),
},
]);
for (const depType of selectedRequiredImports) {
// It's assumed that `scanExistingComponents` returns objects that include
// `name`, `data`, `fileLocation`, and `componentType`.
// The `component: any` type assertion is used here, but ideally,
// `scanExistingComponents` should return a well-defined type.
const existingComponentsForType = yield (0, ProjectScanner_1.scanExistingComponents)(config.scanType, depType); // Explicitly cast for clarity
if ((existingComponentsForType === null || existingComponentsForType === void 0 ? void 0 : existingComponentsForType.length) > 0) {
const { selectedDependencies } = yield inquirer_1.default.prompt([
{
type: "checkbox",
name: "selectedDependencies",
message: `Select ${depType} components to import:`,
choices: existingComponentsForType.map((component) => ({
name: component.name,
value: component, // The entire component object (including fileLocation and componentType) is passed here
})),
pageSize: 10,
},
]);
// Assign the selected dependencies, which now include fileLocation and componentType
dependencies[depType] = selectedDependencies;
if (selectedDependencies.length > 0) {
importExisting = true;
}
}
}
}
if (Object.keys(dependencies).some((key) => dependencies[key].length > 0)) {
console.log("\n--- Dependencies to be imported ---");
for (const [depType, selectedDeps] of Object.entries(dependencies)) {
if (selectedDeps.length > 0) {
console.log(`\nDependencies (${depType}):`);
selectedDeps.forEach((dep) => console.log(`- ${dep.name}`));
}
}
console.log("-------------------------------------------------");
}
else {
console.log("\nNo components were selected for import.");
}
return {
importExisting,
componentsToImport, // This will still be an empty array as per the existing logic.
dependencies, // This object now contains the selected components with fileLocation and componentType.
requiredImports,
};
});
}