New version check system setup

This commit is contained in:
Adam Matthiesen 2024-03-03 08:16:17 -08:00
parent fd21ee8df5
commit 557120f6e6
6 changed files with 271 additions and 612 deletions

View File

@ -16,7 +16,7 @@
"test:integration": "pnpm --filter astro-ghostcms test",
"test:integration:watch": "pnpm --filter astro-ghostcms test:watch",
"test:integration:coverage": "pnpm --filter astro-ghostcms test:coverage",
"test:create": "pnpm --filter create-astro-ghostcms test",
"test:create-utility": "pnpm --filter create-astro-ghostcms test",
"test:starlight": "pnpm --filter starlight-ghostcms test",
"test:starlight:watch": "pnpm --filter starlight-ghostcms test:watch",
"test:starlight:coverage": "pnpm --filter starlight-ghostcms test:coverage"
@ -24,8 +24,8 @@
"devDependencies": {
"@biomejs/biome": "1.5.3",
"@changesets/cli": "^2.27.1",
"vitest": "^1.3.0",
"vitest-fetch-mock": "^0.2.2",
"@vitest/ui": "1.3.0"
"@vitest/ui": "^1.3.1",
"vitest": "^1.3.1",
"vitest-fetch-mock": "^0.2.2"
}
}

View File

@ -58,7 +58,9 @@
"astro": "^4.4.1"
},
"devDependencies": {
"vitest": "^1.3.0",
"@types/fs-extra": "11.0.4",
"@types/node": "20.11.24",
"vitest": "^1.3.1",
"vitest-fetch-mock": "^0.2.2"
},
"dependencies": {
@ -70,6 +72,8 @@
"@ts-ghost/content-api": "^4.0.12",
"astro-integration-kit": "^0.5.0",
"astro-robots-txt": "^1.0.0",
"fs-extra": "11.2.0",
"package-json": "10.0.0",
"picocolors": "1.0.0",
"satori": "^0.10.13",
"satori-html": "0.3.2",

View File

@ -4,6 +4,9 @@ import { GhostUserConfigSchema } from "./schemas/userconfig";
import { loadEnv } from "vite";
import { AstroError } from "astro/errors";
import c from "picocolors";
import path from "node:path";
import { fileURLToPath } from "node:url";
import fse from "fs-extra";
// Import External Integrations
import sitemap from "@astrojs/sitemap";
@ -13,6 +16,7 @@ import robotsTxt from "astro-robots-txt";
import ghostOGImages from "./integrations/satoriog"
import ghostRSS from "./integrations/rssfeed"
import ghostThemeProvider from "./integrations/themeprovider"
import latestVersion from "./utils/latestVersion";
// Load environment variables
const ENV = loadEnv("all", process.cwd(), "CONTENT_API");
@ -154,16 +158,32 @@ export default defineIntegration({
},
"astro:config:done": ({ logger }) => {
const GhostLogger = logger.fork(`${c.bold(c.blue('👻 Astro-GhostCMS'))}${c.gray("/")}${c.green('Config')}`);
const GhostLogger = logger.fork(`${c.bold(c.blue('👻 Astro-GhostCMS'))}${c.gray("/")}${c.green('CONFIG')}`);
GhostLogger.info(c.bold(c.green('Integration Setup & Configuration Complete')))
},
"astro:server:start": ({ logger }) => {
"astro:server:start": async ({ logger }) => {
const GhostLogger = logger.fork(`${c.bold(c.blue('👻 Astro-GhostCMS'))}${c.gray("/")}${c.bold(c.green('DEV'))}`);
GhostLogger.info(c.bold(c.magenta('Running Astro-GhostCMS in Deveopment mode')))
const GhostUpdateLogger = logger.fork(`${c.bold(c.blue('👻 Astro-GhostCMS'))}${c.gray("/")}${c.bold(c.green('VERSION CHECK'))}`);
const verbose = options.fullConsoleLogs;
// Start the DEV server
GhostLogger.info(c.bold(c.magenta('Running Astro-GhostCMS in Deveopment mode 🚀')))
// Check for updates
const currentNPMVersion = await latestVersion("@matthiesenxyz/astro-ghostcms");
const packageJson = await fse.readJson(path.resolve(fileURLToPath(import.meta.url), "../../package.json"));
const localVersion = packageJson.version;
if (currentNPMVersion !== localVersion) {
GhostUpdateLogger.warn(`\n${c.bgYellow(c.bold(c.black(" There is a new version of Astro-GhostCMS available! ")))}\n${c.bold(c.white(" Current Installed Version: ")) + c.bold(c.red(`${localVersion} `))} \n ${c.bold(c.white("New Available Version: "))} ${c.green(currentNPMVersion)} \n ${c.bold(c.white("Please consider updating to the latest version by running: "))} ${c.bold(c.green("npm i @matthiesenxyz/astro-ghostcms@latest"))} \n`)
} else {
GhostUpdateLogger.info(c.bold(c.green(`Astro-GhostCMS is up to date! v${localVersion}`)))
}
},
"astro:build:done": ({ logger }) => {
const GhostLogger = logger.fork(`${c.bold(c.blue('👻 Astro-GhostCMS'))}${c.gray("/")}${c.bold(c.green('BUILD'))}`);
GhostLogger.info(c.bold(c.magenta('Running Astro-GhostCMS in Production mode')))
GhostLogger.info(c.bold(c.magenta('Running Astro-GhostCMS in Production mode 🚀')))
}
}
}

View File

@ -0,0 +1,26 @@
import packageJson from "package-json";
export type Options = {
/**
A semver range or [dist-tag](https://docs.npmjs.com/cli/dist-tag).
*/
readonly version?: string;
};
/**
Get the latest version of an npm package.
@example
```
console.log(await latestVersion('ava'));
//=> '0.18.0'
```
*/
export default async function latestVersion(
packageName: string,
options?: Options,
) {
const { version } = await packageJson(packageName.toLowerCase(), options);
return version;
}

View File

@ -46,17 +46,7 @@
"@types/gunzip-maybe": "^1.4.0",
"@types/node": "^20.11.19",
"@types/tar-fs": "^2.0.1",
"@typescript-eslint/eslint-plugin": "^7.0.1",
"@typescript-eslint/parser": "^7.0.1",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-node": "^0.3.7",
"eslint-import-resolver-typescript": "^3.5.3",
"prettier": "^3.2.5",
"typescript": "^5.3.3",
"vitest": "^1.3.0",
"vite": "^5.1.3",
"vite-tsconfig-paths": "^4.2.2"
"typescript": "^5.3.3"
},
"publishConfig": {
"access": "public"

File diff suppressed because it is too large Load Diff