UNPKG

react-inclusive-card

Version:

A simple, accessible, and flexible card component for React, inspired by the excellent book ["Inclusive Components"](https://inclusive-components.design/cards) by Heydon Pickering.

76 lines (75 loc) 3.41 kB
#!/usr/bin/env node "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var fs_1 = __importDefault(require("fs")); var path_1 = __importDefault(require("path")); var readline_1 = __importDefault(require("readline")); // Use yellow color for the path var yellow = "\x1b[33m"; var reset = "\x1b[0m"; var CMP_NAME = "InclusiveCard.tsx"; var STYLES_NAME = "InclusiveCard.css"; // Get CLI args var args = process.argv.slice(2); var pathArgIndex = args.findIndex(function (arg) { return arg === "--path"; }); if (pathArgIndex !== -1) { var pathArg = args[pathArgIndex + 1]; copyFile(pathArg); } if (pathArgIndex === -1) { var rl_1 = readline_1.default.createInterface({ input: process.stdin, output: process.stdout, }); // Listen for user input rl_1.question("\u2753 Do you want to copy the InclusiveCard component to the default path \n".concat(yellow, "src/components/").concat(CMP_NAME).concat(reset, "? (y/n)"), function (answer) { var normalized = answer.trim().toLowerCase(); // If the answer is not 'y', ask for a custom path if (normalized !== "y") { rl_1.question("\uD83D\uDCCD Please provide a path where you want to copy the component. \nExample: ".concat(yellow, "src/ui/components").concat(reset, "\n"), function (userPath) { // If the user doesn't provide a path, exit if (!userPath.trim()) { console.error("❌ No path provided. Exiting."); rl_1.close(); process.exit(1); } // Copy the file to the user-provided path copyFile(userPath.trim()); rl_1.close(); }); return; } // Answer is 'y', copy to default path copyFile("src/components"); rl_1.close(); }); } function copyFile(userPath) { var cleanedPath = userPath.replace(/\/$/, ""); // Remove trailing slash if present // Paths var packageRoot = path_1.default.dirname(require.resolve("react-inclusive-card/package.json")); var sourceFile = path_1.default.join(packageRoot, "src/Card.tsx"); var sourceStyles = path_1.default.join(packageRoot, "src/InclusiveCard.css"); var destinationFile = path_1.default.resolve(process.cwd(), "".concat(cleanedPath, "/").concat(CMP_NAME)); var destinationStyles = path_1.default.resolve(process.cwd(), "".concat(cleanedPath, "/").concat(STYLES_NAME)); try { if (!fs_1.default.existsSync(sourceFile) || !fs_1.default.existsSync(sourceStyles)) { console.error("❌ Source component or its styles not found."); process.exit(1); } var destinationDir = path_1.default.dirname(destinationFile); if (!fs_1.default.existsSync(destinationDir)) { fs_1.default.mkdirSync(destinationDir, { recursive: true }); } fs_1.default.copyFileSync(sourceFile, destinationFile); fs_1.default.copyFileSync(sourceStyles, destinationStyles); console.log("\u2705 The Inclusive Card component copied to ".concat(destinationFile)); } catch (error) { console.error("❌ Failed to copy component:", error); process.exit(1); } }