UNPKG

@moontra/moonui-pro

Version:

Premium React components for MoonUI - Advanced UI library with 50+ pro components including performance, interactive, and gesture components

203 lines (199 loc) 6.92 kB
import * as fs from 'fs'; import * as path from 'path'; /** * @moontra/moonui-pro v2.0.9 * Premium UI components for MoonUI * (c) 2025 MoonUI. All rights reserved. * @license Commercial - https://moonui.dev/license */ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) { if (typeof require !== "undefined") return require.apply(this, arguments); throw new Error('Dynamic require of "' + x + '" is not supported'); }); function findExistingToken() { if (typeof window !== "undefined") { return null; } const possiblePaths = [ path.join(process.cwd(), ".moonui-license-token"), path.join(process.cwd(), "..", ".moonui-license-token"), path.join(process.cwd(), "..", "..", ".moonui-license-token") ]; if (process.env.VERCEL_ARTIFACTS_PATH) { possiblePaths.push(path.join(process.env.VERCEL_ARTIFACTS_PATH, ".moonui-license-token")); } if (process.env.NETLIFY_BUILD_BASE) { possiblePaths.push(path.join(process.env.NETLIFY_BUILD_BASE, ".moonui-license-token")); } possiblePaths.push("/tmp/.moonui-license-token"); for (const filePath of possiblePaths) { if (fs.existsSync(filePath)) { try { return fs.readFileSync(filePath, "utf8"); } catch (err) { console.error(`[MoonUI Token Generator] Failed to read token from ${filePath}:`, err); } } } return null; } async function generateTokenIfMissing(options = {}) { const { silent = false, forceRegenerate = false } = options; try { if (!forceRegenerate && process.env.MOONUI_PRO_TOKEN) { if (!silent) { console.log("[MoonUI Token Generator] Token found in environment variable"); } return { success: true, token: JSON.parse(Buffer.from(process.env.MOONUI_PRO_TOKEN, "base64").toString("utf8")), cached: true }; } if (!forceRegenerate) { const existingToken = findExistingToken(); if (existingToken) { if (!silent) { console.log("[MoonUI Token Generator] Token file already exists"); } return { success: true, token: JSON.parse(Buffer.from(existingToken, "base64").toString("utf8")), cached: true }; } } const licenseKey = process.env.MOONUI_LICENSE_KEY || process.env.NEXT_PUBLIC_MOONUI_LICENSE_KEY || process.env.VITE_MOONUI_LICENSE_KEY || process.env.REACT_APP_MOONUI_LICENSE_KEY; if (!licenseKey) { if (!silent) { console.log("[MoonUI Token Generator] No license key found in environment variables"); } return { success: false, error: "No license key found" }; } const postInstallPath = path.join(__dirname, "../../scripts/postinstall.cjs"); if (!fs.existsSync(postInstallPath)) { if (!silent) { console.error("[MoonUI Token Generator] PostInstall script not found at:", postInstallPath); } return { success: false, error: "PostInstall script not found" }; } const postInstall = __require(postInstallPath); if (!silent) { console.log("[MoonUI Token Generator] Validating license key and generating token..."); } const result = await postInstall.validateAndCreateToken(licenseKey, { silent }); if (result.success && result.token) { const saveSuccess = postInstall.saveLicenseToken(result.token); if (saveSuccess) { if (!silent) { console.log("[MoonUI Token Generator] \u2713 Token generated and saved successfully"); } return { success: true, token: result.token }; } else { if (!silent) { console.log("[MoonUI Token Generator] \u26A0 Token generated but failed to save"); } return { success: false, error: "Failed to save token" }; } } else { if (!silent) { console.log("[MoonUI Token Generator] \u2717 License validation failed:", result.error); } return { success: false, error: result.error || "License validation failed" }; } } catch (error) { if (!silent) { console.error("[MoonUI Token Generator] Error:", error.message); } return { success: false, error: error.message }; } } function resolveTokenSync() { try { if (process.env.MOONUI_PRO_TOKEN) { return process.env.MOONUI_PRO_TOKEN; } const existingToken = findExistingToken(); if (existingToken) { return existingToken; } return null; } catch (error) { console.error("[MoonUI Token Generator] Error resolving token:", error); return null; } } function getLicenseKeyFromEnv() { return process.env.MOONUI_LICENSE_KEY || process.env.NEXT_PUBLIC_MOONUI_LICENSE_KEY || process.env.VITE_MOONUI_LICENSE_KEY || process.env.REACT_APP_MOONUI_LICENSE_KEY || null; } // src/next-config-plugin.ts function withMoonUIProToken(nextConfig = {}) { console.log("[MoonUI Next.js Plugin] === INITIALIZING ==="); let token = resolveTokenSync(); if (token) { console.log("[MoonUI Next.js Plugin] \u2713 Existing token found"); } else { const licenseKey = getLicenseKeyFromEnv(); if (licenseKey) { console.log("[MoonUI Next.js Plugin] License key found, will attempt runtime generation..."); console.log("[MoonUI Next.js Plugin] \u2139 Token will be generated on first use (runtime fallback)"); } else { console.log("[MoonUI Next.js Plugin] No license key found in environment"); console.log("[MoonUI Next.js Plugin] Set MOONUI_LICENSE_KEY to enable Pro features"); } } const enhancedConfig = { ...nextConfig, env: { ...nextConfig.env, NEXT_PUBLIC_MOONUI_PRO_TOKEN: token || "" } }; if (token) { console.log("[MoonUI Next.js Plugin] \u2713 Token injected into NEXT_PUBLIC_MOONUI_PRO_TOKEN"); } else { console.log("[MoonUI Next.js Plugin] Running without Pro token (will use runtime fallback)"); } console.log("[MoonUI Next.js Plugin] === INITIALIZATION COMPLETE ==="); return enhancedConfig; } async function resolveTokenAsync() { const syncToken = resolveTokenSync(); if (syncToken) { return syncToken; } const licenseKey = getLicenseKeyFromEnv(); if (!licenseKey) { return null; } console.log("[MoonUI Next.js Plugin] Generating token asynchronously..."); const result = await generateTokenIfMissing({ silent: false }); if (result.success && result.token) { const tokenString = JSON.stringify(result.token); return Buffer.from(tokenString).toString("base64"); } return null; } var next_config_plugin_default = withMoonUIProToken; export { next_config_plugin_default as default, resolveTokenAsync, withMoonUIProToken };