diff --git a/.changeset/green-foxes-jam.md b/.changeset/green-foxes-jam.md new file mode 100644 index 00000000..6e89999b --- /dev/null +++ b/.changeset/green-foxes-jam.md @@ -0,0 +1,5 @@ +--- +'pockethost': patch +--- + +Add mothership update-versions command diff --git a/ecosystem.config.cjs b/ecosystem.config.cjs index 9deaaa35..a25de44a 100644 --- a/ecosystem.config.cjs +++ b/ecosystem.config.cjs @@ -28,6 +28,11 @@ module.exports = { restart_delay: 60 * 60 * 1000, // 1 hour script: 'pnpm prod:cli pocketbase update', }, + { + name: `mothership-update-versions`, + restart_delay: 60 * 60 * 1000, // 1 hour + script: 'pnpm prod:cli mothership update-versions', + }, { name: `health-check`, restart_delay: 60 * 1000, // 1 minute diff --git a/packages/pockethost/src/cli/commands/MothershipCommand/UpdateVersionsCommand/index.ts b/packages/pockethost/src/cli/commands/MothershipCommand/UpdateVersionsCommand/index.ts new file mode 100644 index 00000000..dfd55a1e --- /dev/null +++ b/packages/pockethost/src/cli/commands/MothershipCommand/UpdateVersionsCommand/index.ts @@ -0,0 +1,49 @@ +import { + GobotService, + LoggerService, + MOTHERSHIP_HOOKS_DIR, + PH_ALLOWED_POCKETBASE_SEMVER, + stringify, +} from '@' +import { uniq } from '@s-libs/micro-dash' +import { Command } from 'commander' +import { writeFileSync } from 'fs' +import { compare, parse, prerelease, satisfies } from 'semver' + +export const UpdateVersionsCommand = () => { + const cmd = new Command(`update-versions`) + .description(`Update pocketbase versions`) + .action(async () => { + await freshenPocketbaseVersions() + }) + return cmd +} + +export async function freshenPocketbaseVersions() { + const { info } = LoggerService().create(`freshenPocketbaseVersions`) + + const { gobot } = await GobotService() + + info(`Updating pocketbase`) + const bot = await gobot(`pocketbase`) + const versions = uniq( + (await bot.versions()) + .map((v) => parse(v)) + .filter((v) => !!v) + .filter( + (v) => + satisfies(v, PH_ALLOWED_POCKETBASE_SEMVER()) && + prerelease(v) === null, + ) + .sort(compare) + .reverse() + .map((v) => `${v.major}.${v.minor}.*`), + ) + const cjs = `module.exports = ${stringify(versions, null, 2)}` + + const path = MOTHERSHIP_HOOKS_DIR(`versions.cjs`) + info(`Writing to ${path}`, { versions }) + writeFileSync(path, cjs) + + return cjs +} diff --git a/packages/pockethost/src/cli/commands/MothershipCommand/index.ts b/packages/pockethost/src/cli/commands/MothershipCommand/index.ts index 342707f8..d177ad5a 100644 --- a/packages/pockethost/src/cli/commands/MothershipCommand/index.ts +++ b/packages/pockethost/src/cli/commands/MothershipCommand/index.ts @@ -1,6 +1,7 @@ import { Command } from 'commander' import { SchemaCommand } from './SchemaCommand' import { ServeCommand } from './ServeCommand' +import { UpdateVersionsCommand } from './UpdateVersionsCommand' type Options = { debug: boolean @@ -11,6 +12,7 @@ export const MothershipCommand = () => { .description(`Mothership commands`) .addCommand(ServeCommand()) .addCommand(SchemaCommand()) + .addCommand(UpdateVersionsCommand()) .action(() => { cmd.help() }) diff --git a/packages/pockethost/src/mothership-app/pb_hooks/versions.cjs b/packages/pockethost/src/mothership-app/pb_hooks/versions.cjs index d06c7015..b8539868 100644 --- a/packages/pockethost/src/mothership-app/pb_hooks/versions.cjs +++ b/packages/pockethost/src/mothership-app/pb_hooks/versions.cjs @@ -1,167 +1,24 @@ module.exports = [ "0.22.*", - "0.22.27", - "0.22.26", - "0.22.25", - "0.22.24", - "0.22.23", - "0.22.22", - "0.22.21", - "0.22.20", - "0.22.19", - "0.22.18", - "0.22.17", - "0.22.16", - "0.22.15", - "0.22.14", - "0.22.13", - "0.22.12", - "0.22.11", - "0.22.10", - "0.22.9", - "0.22.8", - "0.22.7", - "0.22.6", - "0.22.5", - "0.22.4", - "0.22.3", - "0.22.2", - "0.22.1", - "0.22.0", "0.21.*", - "0.21.3", - "0.21.2", - "0.21.1", - "0.21.0", "0.20.*", - "0.20.7", - "0.20.6", - "0.20.5", - "0.20.4", - "0.20.3", - "0.20.2", - "0.20.1", - "0.20.0", "0.19.*", - "0.19.4", - "0.19.3", - "0.19.2", - "0.19.1", - "0.19.0", "0.18.*", - "0.18.10", - "0.18.9", - "0.18.8", - "0.18.7", - "0.18.6", - "0.18.5", - "0.18.4", - "0.18.3", - "0.18.2", - "0.18.1", - "0.18.0", "0.17.*", - "0.17.7", - "0.17.6", - "0.17.5", - "0.17.4", - "0.17.3", - "0.17.2", - "0.17.1", - "0.17.0", "0.16.*", - "0.16.10", - "0.16.9", - "0.16.8", - "0.16.7", - "0.16.6", - "0.16.5", - "0.16.4", - "0.16.3", - "0.16.2", - "0.16.1", - "0.16.0", "0.15.*", - "0.15.3", - "0.15.2", - "0.15.1", - "0.15.0", "0.14.*", - "0.14.5", - "0.14.4", - "0.14.3", - "0.14.2", - "0.14.1", - "0.14.0", "0.13.*", - "0.13.4", - "0.13.3", - "0.13.2", - "0.13.1", - "0.13.0", "0.12.*", - "0.12.3", - "0.12.2", - "0.12.1", - "0.12.0", "0.11.*", - "0.11.4", - "0.11.3", - "0.11.2", - "0.11.1", - "0.11.0", "0.10.*", - "0.10.4", - "0.10.3", - "0.10.2", - "0.10.1", - "0.10.0", "0.9.*", - "0.9.2", - "0.9.1", - "0.9.0", "0.8.*", - "0.8.0", "0.7.*", - "0.7.10", - "0.7.9", - "0.7.8", - "0.7.7", - "0.7.6", - "0.7.5", - "0.7.4", - "0.7.3", - "0.7.2", - "0.7.1", - "0.7.0", "0.6.*", - "0.6.0", "0.5.*", - "0.5.2", - "0.5.1", - "0.5.0", "0.4.*", - "0.4.2", - "0.4.1", - "0.4.0", "0.3.*", - "0.3.4", - "0.3.3", - "0.3.2", - "0.3.1", - "0.3.0", "0.2.*", - "0.2.8", - "0.2.7", - "0.2.6", - "0.2.5", - "0.2.4", - "0.2.3", - "0.2.2", - "0.2.1", - "0.2.0", - "0.1.*", - "0.1.2", - "0.1.1", - "0.1.0" + "0.1.*" ] \ No newline at end of file