UNPKG

@agametis/create-app-for-fm

Version:

Tool for selecting a starter project for FileMaker applications

104 lines (92 loc) 3.4 kB
import {execSync} from "child_process"; import fs from "fs-extra"; import path from "path"; import {GITHUB_CONFIG} from "../config.js"; import {t} from "../i18n.js"; export function showTemplateInfo(templateName) { if (!templateName) { console.error(t("info.noTemplateName")); console.log( t("info.useInfoCommand"), ); return; } // Find the template in our config const template = GITHUB_CONFIG.repositories.find( (repo) => repo.name.toLowerCase() === templateName.toLowerCase(), ); if (!template) { console.error(t("info.templateNotFound")); console.log(t("info.availableTemplates")); GITHUB_CONFIG.repositories.forEach((repo) => { console.log(`- ${repo.name}`); }); return; } console.log(`${t("info.templateInfo")}${template.name}\n`); if (template.description) { console.log(`${t("info.description")}${template.description}`); } console.log(`${t("info.githubUrl")}${GITHUB_CONFIG.baseUrl}${template.path}`); // Try to get more information from the repository try { // Create a temporary directory const tempDir = path.join(process.cwd(), "temp-info"); if (fs.existsSync(tempDir)) { fs.removeSync(tempDir); } fs.mkdirSync(tempDir); // Clone the repository (shallow, quiet) console.log(t("info.loadingMoreInfo")); execSync(`git clone --depth 1 -q ${GITHUB_CONFIG.baseUrl}${template.path} ${tempDir}`, { stdio: "ignore", }); // Check for README const readmePath = path.join(tempDir, "README.md"); if (fs.existsSync(readmePath)) { console.log(t("info.readmeFound")); const readme = fs.readFileSync(readmePath, "utf8"); // Display first 10 lines or 500 characters, whichever is shorter const lines = readme.split("\n").slice(0, 10).join("\n"); console.log(lines.length > 500 ? lines.substring(0, 500) + "..." : lines); console.log(t("info.readmeTruncated")); } // Check for package.json const packageJsonPath = path.join(tempDir, "package.json"); if (fs.existsSync(packageJsonPath)) { try { const packageJson = JSON.parse( fs.readFileSync(packageJsonPath, "utf8"), ); console.log(t("info.packageJsonInfo")); if (packageJson.dependencies && Object.keys(packageJson.dependencies).length > 0) { console.log(t("info.dependencies")); Object.keys(packageJson.dependencies) .slice(0, 10) .forEach((dep) => { console.log(`- ${dep}: ${packageJson.dependencies[dep]}`); }); if (Object.keys(packageJson.dependencies).length > 10) { console.log(t("info.moreItems", {count: Object.keys(packageJson.dependencies).length - 10})); } } if (packageJson.scripts && Object.keys(packageJson.scripts).length > 0) { console.log(t("info.scripts")); Object.entries(packageJson.scripts).forEach(([name, script]) => { console.log(`- ${name}: ${script}`); }); } } catch (error) { console.error(t("info.packageJsonError")); } } // Clean up fs.removeSync(tempDir); console.log(t("info.visitGithub")); console.log(`${GITHUB_CONFIG.baseUrl}${template.path}`); } catch (error) { console.error( `${t("info.errorFetchingInfo")}${error.message}`, ); } }