diff --git a/.prettierignore b/.prettierignore index 875cc2fc..0d107053 100644 --- a/.prettierignore +++ b/.prettierignore @@ -8,5 +8,4 @@ build *.njk _site forks -src/mothership-app/migrations -src/mothership-app/pb_hooks/src/versions.js \ No newline at end of file +src/mothership-app/migrations \ No newline at end of file diff --git a/src/cli/download.ts b/src/cli/download.ts index 6326bc4b..127b1aa3 100644 --- a/src/cli/download.ts +++ b/src/cli/download.ts @@ -1,9 +1,4 @@ -import { - DEBUG, - DefaultSettingsService, - PH_BIN_CACHE, - SETTINGS, -} from '$constants' +import { DEBUG, DefaultSettingsService, SETTINGS } from '$constants' import { PocketbaseReleaseDownloadService } from '$services' import { LogLevelName, LoggerService } from '$shared' @@ -18,9 +13,7 @@ const check = async () => { const { dbg, error, info, warn } = logger info(`Starting`) - const { check } = PocketbaseReleaseDownloadService({ - cachePath: PH_BIN_CACHE(), - }) + const { check } = PocketbaseReleaseDownloadService({}) await check() } diff --git a/src/cli/mothership.ts b/src/cli/mothership.ts index c37cea89..6f7e8f16 100644 --- a/src/cli/mothership.ts +++ b/src/cli/mothership.ts @@ -10,6 +10,7 @@ import { MOTHERSHIP_PORT, MOTHERSHIP_SEMVER, PH_BIN_CACHE, + PH_VERSIONS, SETTINGS, } from '$constants' import { @@ -66,6 +67,7 @@ global.EventSource = EventSource extraBinds: [ `${DATA_ROOT()}:${mkContainerHomePath(`data`)}`, `${MOTHERSHIP_HOOKS_DIR()}:${mkContainerHomePath(`pb_hooks`)}`, + `${PH_VERSIONS()}:${mkContainerHomePath(`pb_hooks`, `versions.js`)}`, `${MOTHERSHIP_MIGRATIONS_DIR()}:${mkContainerHomePath(`pb_migrations`)}`, `${MOTHERSHIP_APP_DIR()}:${mkContainerHomePath(`ph_app`)}`, ], diff --git a/src/constants.ts b/src/constants.ts index 30be5c1a..886be045 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -33,6 +33,7 @@ export const SETTINGS = { UPGRADE_MODE: mkBoolean(false), PH_HOME: mkPath(_PH_HOME), + PH_VERSIONS: mkPath(join(_PH_HOME, `versions.js`), { required: false }), PH_PROJECT_ROOT: mkPath(_PH_PROJECT_ROOT), DEBUG: mkBoolean(_IS_DEV), @@ -118,7 +119,7 @@ export const DefaultSettingsService = mkSingleton( ioc.register('settings', _settings) - logConstants() + logConstants() return _settings }, @@ -160,6 +161,7 @@ export const instanceLogger = () => ioc.service('instanceLogger') export const UPGRADE_MODE = () => settings().UPGRADE_MODE export const PH_HOME = () => settings().PH_HOME +export const PH_VERSIONS = () => settings().PH_VERSIONS export const PH_PROJECT_ROOT = () => settings().PH_PROJECT_ROOT export const DEBUG = () => settings().DEBUG diff --git a/src/services/PocketbaseReleaseDownloadService/index.ts b/src/services/PocketbaseReleaseDownloadService/index.ts index a3e4f3fc..019e8e4d 100644 --- a/src/services/PocketbaseReleaseDownloadService/index.ts +++ b/src/services/PocketbaseReleaseDownloadService/index.ts @@ -1,4 +1,4 @@ -import { MOTHERSHIP_HOOKS_DIR, PH_BIN_CACHE } from '$constants' +import { PH_BIN_CACHE, PH_VERSIONS } from '$constants' import { LoggerService, SingletonBaseConfig, mkSingleton } from '$shared' import { downloadAndExtract, mergeConfig, smartFetch } from '$util' import { keys } from '@s-libs/micro-dash' @@ -21,14 +21,16 @@ type Releases = Release[] export type PocketbaseReleaseDownloadServiceConfig = SingletonBaseConfig & { onlyOne: boolean - cachePath: string + binCachePath: string + versionsCachePath: string } export const PocketbaseReleaseDownloadService = mkSingleton( (config: Partial = {}) => { - const { cachePath, onlyOne } = mergeConfig( + const { binCachePath, versionsCachePath, onlyOne } = mergeConfig( { - cachePath: PH_BIN_CACHE(), + binCachePath: PH_BIN_CACHE(), + versionsCachePath: PH_VERSIONS(), onlyOne: false, }, config, @@ -52,7 +54,7 @@ export const PocketbaseReleaseDownloadService = mkSingleton( info(`Fetching info for PocketBase releases...`) let releases = await smartFetch( `https://api.github.com/repos/pocketbase/pocketbase/releases?per_page=100`, - join(cachePath, `releases.json`), + join(binCachePath, `releases.json`), ) // dbg({ releases }) @@ -67,7 +69,7 @@ export const PocketbaseReleaseDownloadService = mkSingleton( .map((release) => { const { tag_name, assets } = release const sanitizedTagName = tag_name.slice(1) - const path = join(cachePath, tag_name) + const path = join(binCachePath, tag_name) const url = assets.find((v) => { // dbg(v.name) return v.name.includes(osName) && v.name.includes(cpuArchitecture) @@ -105,10 +107,10 @@ export const PocketbaseReleaseDownloadService = mkSingleton( console.log(`***keys`, keys(binPaths)) const sortedSemVers = expandAndSortSemVers(keys(binPaths)) writeFileSync( - join(MOTHERSHIP_HOOKS_DIR(), `versions.js`), + versionsCachePath, `module.exports = ${JSON.stringify({ versions: sortedSemVers })}`, ) - console.log(JSON.stringify(sortedSemVers)) + info(`Saved to ${versionsCachePath}`, sortedSemVers) if (keys(binPaths).length === 0) { throw new Error(