mirror of
https://github.com/pockethost/pockethost.git
synced 2026-03-18 06:08:52 +00:00
Move versions.js to PH_HOME/versions.js
This commit is contained in:
@@ -8,5 +8,4 @@ build
|
||||
*.njk
|
||||
_site
|
||||
forks
|
||||
src/mothership-app/migrations
|
||||
src/mothership-app/pb_hooks/src/versions.js
|
||||
src/mothership-app/migrations
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
@@ -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`)}`,
|
||||
],
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<PocketbaseReleaseDownloadServiceConfig> = {}) => {
|
||||
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<Releases>(
|
||||
`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(
|
||||
|
||||
Reference in New Issue
Block a user