UNPKG

lowdefy

Version:
102 lines (98 loc) 4.21 kB
/* Copyright 2020-2026 Lowdefy, Inc Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import fs from 'fs'; import path from 'path'; import axios from 'axios'; import semver from 'semver'; async function validateVersion({ cliVersion, lowdefyVersion, logger, requiresLowdefyYaml, configDirectory }) { const ui = logger?.ui ?? logger ?? { warn: (message)=>console.warn(message) }; if (!requiresLowdefyYaml) { return; } if (lowdefyVersion === 'local') { return; } if (!semver.valid(lowdefyVersion)) { throw new Error(` --------------------------------------------------- Version ${lowdefyVersion} is not a valid version. ---------------------------------------------------`); } if (semver.major(lowdefyVersion) === 3) { throw new Error(` --------------------------------------------------- You are attempting to run a version 3 app with the version 4 CLI. Please update your app to version 4 using the migration guide. View the migration guide here: https://docs.lowdefy.com/v3-to-v4 Alternatively, run the app with the version 3 CLI. To do this, run 'npx lowdefy@3'. ---------------------------------------------------`); } if (isExperimentalVersion(cliVersion) || isExperimentalVersion(lowdefyVersion)) { ui.warn(` --------------------------------------------------- You are using an experimental version of Lowdefy. Features may change at any time. ---------------------------------------------------`); return; } const registryUrl = 'https://registry.npmjs.org/lowdefy'; try { const packageInfo = await axios.get(registryUrl); const latestVersion = packageInfo.data['dist-tags'].latest; if (cliVersion !== latestVersion) { ui.warn(` ------------------------------------------------------------- You are not using the latest version of the Lowdefy CLI. Please update to version ${latestVersion}. To always use the latest version, run 'pnpx lowdefy@4'. -------------------------------------------------------------`); } if (lowdefyVersion && lowdefyVersion !== latestVersion) { ui.warn(` ------------------------------------------------------------- Your app is not using the latest Lowdefy version, ${lowdefyVersion}. Please update your app to version ${latestVersion}. View the changelog here: https://github.com/lowdefy/lowdefy/blob/main/CHANGELOG.md -------------------------------------------------------------`); } } catch (error) { ui.warn('Failed to check for latest Lowdefy version.'); } // Check for pending codemods from an interrupted upgrade if (configDirectory) { try { const upgradeStatePath = path.join(configDirectory, '.lowdefy', 'upgrade-state.json'); if (fs.existsSync(upgradeStatePath)) { const state = JSON.parse(fs.readFileSync(upgradeStatePath, 'utf8')); const skipped = state.phases.flatMap((p)=>p.codemods).filter((c)=>c.status === 'skipped'); if (skipped.length > 0) { ui.warn(` ------------------------------------------------------------- ${skipped.length} codemod(s) were skipped during upgrade. Run "npx lowdefy upgrade --resume" to complete them. -------------------------------------------------------------`); } } } catch { // Ignore errors reading upgrade state } } } function isExperimentalVersion(version) { return version.includes('alpha') || version.includes('beta') || version.includes('rc') || version.includes('experimental'); } export default validateVersion;