UNPKG

@atomazing-org/vite-config

Version:

A library providing a vite configuration with including PWA and MF supports.

71 lines (68 loc) 2.27 kB
#!/usr/bin/env node // bin/create-manifest.mjs import fs from "fs"; import path from "path"; import { input, confirm } from "@inquirer/prompts"; import { fileURLToPath } from "url"; var __filename = fileURLToPath(import.meta.url); var __dirname = path.dirname(__filename); var manifestTemplate = `import type { ManifestOptions } from 'vite-plugin-pwa' const manifest: Partial<ManifestOptions> = { name: '{{name}}', short_name: '{{short_name}}', display: 'standalone', scope: '/', start_url: '/', theme_color: '#7764E8', background_color: '#171D34', description: '{{description}}', categories: ['utilities'], edge_side_panel: { preferred_width: 500 }, icons: [] }; export default manifest; `; async function createManifest() { console.log("\n\u{1F680} PWA Manifest Generator\n"); try { const name = await input({ message: "Enter app name:", validate: (value) => value.trim() ? true : "App name cannot be empty" }); const shortName = await input({ message: "Enter short name (max 12 characters):", validate: (value) => { if (!value.trim()) return "Short name cannot be empty"; if (value.length > 12) return "Must be 12 characters or less"; return true; } }); const description = await input({ message: "Enter app description:", default: "My Progressive Web App" }); const content = manifestTemplate.replace(/{{name}}/g, name).replace(/{{short_name}}/g, shortName).replace(/{{description}}/g, description); console.log("\n\u{1F4DD} Manifest preview:"); console.log(content); const proceed = await confirm({ message: "Create manifest.ts?", default: true }); if (!proceed) { console.log("\n\u274C Operation cancelled"); process.exit(0); } const filePath = path.join(process.cwd(), "manifest.ts"); fs.writeFileSync(filePath, content); console.log("\n\u2705 manifest.ts successfully created!"); console.log(`\u{1F4CD} Location: ${filePath}`); } catch (error) { if (error.message === "User force closed the prompt") { console.log("\n\u274C Operation cancelled"); } else { console.error("\n\u274C Error:", error.message); } process.exit(1); } } createManifest();