diff --git a/packages/studiocms_core/src/schemas/config/dashboard.ts b/packages/studiocms_core/src/schemas/config/dashboard.ts index 81cc36b59..04be331b3 100644 --- a/packages/studiocms_core/src/schemas/config/dashboard.ts +++ b/packages/studiocms_core/src/schemas/config/dashboard.ts @@ -38,6 +38,15 @@ export const dashboardConfigSchema = z * Developer Options/Configuration */ developerConfig: developerConfigSchema, + /** + * OPTIONAL - This allows the user to enable or disable the version check for the dashboard + * + * This will check for the latest version of StudioCMS and notify the user + * if there is a new version available. + * + * @default true + */ + versionCheck: z.boolean().optional().default(true), }) .optional() .default({}); diff --git a/packages/studiocms_dashboard/package.json b/packages/studiocms_dashboard/package.json index cb80951fb..a2c8f8afd 100644 --- a/packages/studiocms_dashboard/package.json +++ b/packages/studiocms_dashboard/package.json @@ -44,7 +44,8 @@ "@inox-tools/runtime-logger": "catalog:studiocms-shared", "@matthiesenxyz/astrodtsbuilder": "catalog:studiocms-shared", "@matthiesenxyz/integration-utils": "catalog:studiocms-shared", - "@fontsource-variable/onest": "catalog:studiocms-shared" + "@fontsource-variable/onest": "catalog:studiocms-shared", + "semver": "catalog:studiocms" }, "peerDependencies": { "astro": "catalog:min", @@ -53,6 +54,7 @@ "vite": "catalog:min" }, "devDependencies": { - "typescript": "catalog:" + "typescript": "catalog:", + "@types/semver": "catalog:studiocms" } } diff --git a/packages/studiocms_dashboard/src/components/SingleSidebar.astro b/packages/studiocms_dashboard/src/components/SingleSidebar.astro index 0650cd83c..321136ece 100644 --- a/packages/studiocms_dashboard/src/components/SingleSidebar.astro +++ b/packages/studiocms_dashboard/src/components/SingleSidebar.astro @@ -1,12 +1,16 @@ --- +import { dashboardConfig } from 'studiocms:config'; import { useTranslations } from 'studiocms:i18n'; import { StudioCMSRoutes } from 'studiocms:lib'; import { Divider, Dropdown, Sidebar, User } from '@studiocms/ui/components'; import StudioCMSLogo from '../components/StudioCMSLogo.astro'; import SidebarLink from './SidebarLink.astro'; +import VersionCheck from './islands/VersionCheck.astro'; import Admin from './islands/sidebar/Admin.astro'; import UserAccount from './islands/sidebar/UserAccount.astro'; +const { versionCheck } = dashboardConfig; + const lang = 'en-us'; const t = useTranslations(lang, '@studiocms/dashboard:sidebar'); --- @@ -29,7 +33,7 @@ const t = useTranslations(lang, '@studiocms/dashboard:sidebar'); Loading - + + { versionCheck && ( + + + + )}
diff --git a/packages/studiocms_dashboard/src/components/islands/VersionCheck.astro b/packages/studiocms_dashboard/src/components/islands/VersionCheck.astro new file mode 100644 index 000000000..262e3ecf1 --- /dev/null +++ b/packages/studiocms_dashboard/src/components/islands/VersionCheck.astro @@ -0,0 +1,126 @@ +--- +import currentVersion from 'studiocms:version'; +import { Divider } from '@studiocms/ui/components'; +import { compare } from 'semver'; + +const jsonRes = await (await fetch('https://registry.npmjs.org/studiocms/latest')).json(); + +const latestVersion = jsonRes.version; + +const comparison = compare(currentVersion, latestVersion); + +const classList = comparison === -1 ? 'outdated' : comparison === 0 ? 'latest' : 'future'; + +const titleString = + comparison === -1 + ? 'There is a new version available' + : comparison === 0 + ? 'You are up to date' + : 'You are using a unreleased version'; +--- + + + Current Version + + +
+ + {currentVersion} + + + + { comparison === -1 && ( + + There is a new version of StudioCMS available, please consider updating. + + )} + + { comparison === 1 && ( + + You are currently using a pre-release version of StudioCMS. + + )} +
+ + diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 061a15474..3e9c69e50 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -680,10 +680,16 @@ importers: astro-integration-kit: specifier: 'catalog:' version: 0.17.0(astro@5.0.5(@types/node@22.10.2)(jiti@2.4.1)(rollup@4.28.1)(typescript@5.7.2)(yaml@2.6.1)) + semver: + specifier: catalog:studiocms + version: 7.6.3 vite: specifier: catalog:min version: 6.0.3(@types/node@22.10.2)(jiti@2.4.1)(yaml@2.6.1) devDependencies: + '@types/semver': + specifier: catalog:studiocms + version: 7.5.8 typescript: specifier: 'catalog:' version: 5.7.2