UNPKG

create-gluestack

Version:

A CLI tool for easily initialising gluestack-ui and adding components to your projects.

127 lines 5.54 kB
"use strict"; 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; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.cloneProject = cloneProject; exports.installDependencies = installDependencies; exports.gitInit = gitInit; const data_js_1 = __importDefault(require("./data.js")); const fs_1 = require("fs"); const path_1 = __importDefault(require("path")); const child_process_1 = require("child_process"); const readline = __importStar(require("readline")); const { gitRepo, branch } = data_js_1.default; // Helper function to prompt user for input function promptUser(question) { const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); return new Promise((resolve) => { rl.question(question, (answer) => { rl.close(); resolve(answer.toLowerCase().trim()); }); }); } async function cloneProject(projectName, templateName) { const dirPath = path_1.default.join(process.cwd(), projectName); if ((0, fs_1.existsSync)(dirPath)) { console.log(`Folder already exists with name: ${projectName}`); const userChoice = await promptUser('Do you want to override the existing folder? (yes/no | y/n): '); if (userChoice === 'yes' || userChoice === 'y') { console.log('Overriding the existing folder...\n'); // Delete directory recursively (0, fs_1.rmSync)(projectName, { recursive: true, force: true }); } else { console.log('Operation cancelled. Please choose a different project name.'); process.exit(0); } } try { // Single command shallow clone with sparse checkout - much faster! (0, child_process_1.execSync)(`git clone --depth=1 --filter=blob:none --sparse ${gitRepo} ${projectName} --branch ${branch}`); // Initialize sparse checkout with no cone mode and explicit patterns (0, child_process_1.execSync)(`git sparse-checkout init --no-cone`, { cwd: dirPath }); (0, child_process_1.execSync)(`git sparse-checkout set "apps/${templateName}/*"`, { cwd: dirPath, }); // Move files moveAllFiles(dirPath, templateName); // Clean up try { // Remove the apps directory (0, fs_1.rmSync)(path_1.default.join(dirPath, 'apps'), { recursive: true, force: true }); // Remove the .git directory (0, fs_1.rmSync)(path_1.default.join(dirPath, '.git'), { recursive: true, force: true }); } catch (cleanupError) { console.warn('Warning: Some cleanup operations failed, but project should still be usable'); } } catch (error) { console.log('Git not installed or error occurred. Please install git and try again...'); process.exit(1); } } async function installDependencies(projectName, selectedPackageManager) { console.log('Installing Dependencies...'); (0, child_process_1.execSync)(`${selectedPackageManager} install`, { cwd: path_1.default.join(process.cwd(), projectName), }); console.log('Dependancies Installed!'); } async function gitInit(projectName) { const dirPath = path_1.default.join(process.cwd(), projectName); (0, child_process_1.execSync)('git init', { cwd: dirPath }); (0, child_process_1.execSync)('git branch -M main', { cwd: dirPath }); (0, child_process_1.execSync)(`git add --all`, { cwd: dirPath }); (0, child_process_1.execSync)(`git commit -m "Init"`, { cwd: dirPath }); } function moveAllFiles(dirPath, templateName) { const sourcePath = path_1.default.join(dirPath, 'apps', templateName); // Read all files/directories in the source directory const items = (0, fs_1.readdirSync)(sourcePath); // Move each item to the destination items.forEach((item) => { const sourceItem = path_1.default.join(sourcePath, item); const destItem = path_1.default.join(dirPath, item); (0, fs_1.renameSync)(sourceItem, destItem); }); } //# sourceMappingURL=utils.js.map