UNPKG

create-gluestack-nightly

Version:

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

73 lines 3.44 kB
"use strict"; 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 { gitRepo, branch } = data_js_1.default; 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}`); console.log('Overwriding the existing folder...\n'); // Delete directory recursively (0, fs_1.rmSync)(projectName, { recursive: true, force: true }); } 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