create-gluecode
Version:
A CLI tool for easily initialising gluestack-ui and adding components to your projects.
84 lines • 4.25 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.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;
function cloneProject(projectName, templateName) {
return __awaiter(this, void 0, void 0, function* () {
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}`);
(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);
}
});
}
function installDependencies(projectName, selectedPackageManager) {
return __awaiter(this, void 0, void 0, function* () {
console.log('Installing Dependencies...');
(0, child_process_1.execSync)(`${selectedPackageManager} install`, {
cwd: path_1.default.join(process.cwd(), projectName),
});
console.log('Dependancies Installed!');
});
}
function gitInit(projectName) {
return __awaiter(this, void 0, void 0, function* () {
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