mirror of
https://github.com/pockethost/pockethost.git
synced 2025-07-06 04:42:29 +00:00
feat(pockethost): gobot command updater/downloader
This commit is contained in:
parent
d6e700bdd1
commit
ad839eadf1
@ -22,14 +22,9 @@ module.exports = {
|
|||||||
script: 'pnpm prod:cli mothership serve',
|
script: 'pnpm prod:cli mothership serve',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: `updater`,
|
name: `gobot`,
|
||||||
restart_delay: 60 * 60 * 1000, // 1 hour
|
restart_delay: 60 * 60 * 1000, // 1 hour
|
||||||
script: 'pnpm prod:cli mothership update',
|
script: 'pnpm prod:cli gobot update',
|
||||||
},
|
|
||||||
{
|
|
||||||
name: `downloader`,
|
|
||||||
restart_delay: 60 * 60 * 1000, // 1 hour
|
|
||||||
script: 'pnpm gobot:download',
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: `health`,
|
name: `health`,
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import { writeFileSync } from 'fs'
|
import { writeFileSync } from 'fs'
|
||||||
import { gobot } from 'gobot'
|
|
||||||
import {
|
import {
|
||||||
|
LoggerService,
|
||||||
MOTHERSHIP_DATA_ROOT,
|
MOTHERSHIP_DATA_ROOT,
|
||||||
MOTHERSHIP_HOOKS_DIR,
|
|
||||||
stringify,
|
stringify,
|
||||||
} from '../../../../core'
|
} from '../../../../../core'
|
||||||
|
import { GobotService } from '../../../../services/GobotService'
|
||||||
|
|
||||||
function compareSemVer(a: string, b: string): number {
|
function compareSemVer(a: string, b: string): number {
|
||||||
// Consider wildcards as higher than any version number, hence represented by a large number for comparison
|
// Consider wildcards as higher than any version number, hence represented by a large number for comparison
|
||||||
@ -54,12 +54,27 @@ function expandAndSortSemVers(semvers: string[]): string[] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function freshenPocketbaseVersions() {
|
export async function freshenPocketbaseVersions() {
|
||||||
|
const { info } = LoggerService().create(`freshenPocketbaseVersions`)
|
||||||
|
|
||||||
|
const { gobot } = await GobotService()
|
||||||
|
|
||||||
|
info(`Updating pocketbase`)
|
||||||
const bot = await gobot(`pocketbase`)
|
const bot = await gobot(`pocketbase`)
|
||||||
await bot.update()
|
await bot.update()
|
||||||
|
await bot.download()
|
||||||
const rawVersions = await bot.versions()
|
const rawVersions = await bot.versions()
|
||||||
const versions = expandAndSortSemVers(rawVersions)
|
const versions = expandAndSortSemVers(rawVersions)
|
||||||
const cjs = `module.exports = ${stringify(versions, null, 2)}`
|
const cjs = `module.exports = ${stringify(versions, null, 2)}`
|
||||||
writeFileSync(MOTHERSHIP_DATA_ROOT(`pb_hooks`, `versions.cjs`), cjs)
|
|
||||||
writeFileSync(MOTHERSHIP_HOOKS_DIR(`versions.cjs`), cjs)
|
{
|
||||||
|
const path = MOTHERSHIP_DATA_ROOT(`pb_hooks`, `versions.cjs`)
|
||||||
|
info(`Writing to ${path}`)
|
||||||
|
writeFileSync(path, cjs)
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const path = bot.cachePath(`versions.cjs`)
|
||||||
|
info(`Writing to ${path}`)
|
||||||
|
writeFileSync(path, cjs)
|
||||||
|
}
|
||||||
return cjs
|
return cjs
|
||||||
}
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
import { Command } from 'commander'
|
||||||
|
import { freshenPocketbaseVersions } from './freshenPocketbaseVersions'
|
||||||
|
|
||||||
|
export const UpdateCommand = () => {
|
||||||
|
const cmd = new Command(`update`)
|
||||||
|
.description(`Update all Gobot dependencies`)
|
||||||
|
.action(async (options) => {
|
||||||
|
await freshenPocketbaseVersions()
|
||||||
|
})
|
||||||
|
return cmd
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
import { Command } from 'commander'
|
||||||
|
import { UpdateCommand } from './UpdateCommand'
|
||||||
|
|
||||||
|
export const GobotCommand = () => {
|
||||||
|
const cmd = new Command(`gobot`).description(`Gobot commands`)
|
||||||
|
|
||||||
|
cmd.addCommand(UpdateCommand())
|
||||||
|
return cmd
|
||||||
|
}
|
@ -56,8 +56,18 @@ export async function mothership(cfg: MothershipConfig) {
|
|||||||
LS_WEBHOOK_SECRET: LS_WEBHOOK_SECRET(),
|
LS_WEBHOOK_SECRET: LS_WEBHOOK_SECRET(),
|
||||||
}
|
}
|
||||||
dbg(env)
|
dbg(env)
|
||||||
|
|
||||||
|
const options: Partial<GobotOptions> = {
|
||||||
|
version: MOTHERSHIP_SEMVER(),
|
||||||
|
env,
|
||||||
|
}
|
||||||
|
dbg(`options`, options)
|
||||||
|
const { gobot } = GobotService()
|
||||||
|
const bot = await gobot(`pocketbase`, options)
|
||||||
|
|
||||||
await rimraf(MOTHERSHIP_DATA_ROOT(`pb_hooks`))
|
await rimraf(MOTHERSHIP_DATA_ROOT(`pb_hooks`))
|
||||||
await _copy(MOTHERSHIP_HOOKS_DIR(`**/*`), MOTHERSHIP_DATA_ROOT(`pb_hooks`))
|
await _copy(MOTHERSHIP_HOOKS_DIR(`**/*`), MOTHERSHIP_DATA_ROOT(`pb_hooks`))
|
||||||
|
await _copy(bot.cachePath(`versions.cjs`), MOTHERSHIP_DATA_ROOT(`pb_hooks`))
|
||||||
await rimraf(MOTHERSHIP_DATA_ROOT(`pb_migrations`))
|
await rimraf(MOTHERSHIP_DATA_ROOT(`pb_migrations`))
|
||||||
await _copy(
|
await _copy(
|
||||||
MOTHERSHIP_MIGRATIONS_DIR(`**/*`),
|
MOTHERSHIP_MIGRATIONS_DIR(`**/*`),
|
||||||
@ -80,13 +90,6 @@ export async function mothership(cfg: MothershipConfig) {
|
|||||||
if (IS_DEV()) {
|
if (IS_DEV()) {
|
||||||
args.push(`--dev`)
|
args.push(`--dev`)
|
||||||
}
|
}
|
||||||
const options: Partial<GobotOptions> = {
|
|
||||||
version: MOTHERSHIP_SEMVER(),
|
|
||||||
env,
|
|
||||||
}
|
|
||||||
dbg(`args`, args)
|
dbg(`args`, args)
|
||||||
dbg(`options`, options)
|
|
||||||
const { gobot } = GobotService()
|
|
||||||
const bot = await gobot(`pocketbase`, options)
|
|
||||||
bot.run(args, { env })
|
bot.run(args, { env })
|
||||||
}
|
}
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
import { Command } from 'commander'
|
|
||||||
import { freshenPocketbaseVersions } from '../freshenPocketbaseVersions'
|
|
||||||
|
|
||||||
type Options = {}
|
|
||||||
|
|
||||||
export const UpdateCommand = () => {
|
|
||||||
const cmd = new Command(`update`)
|
|
||||||
.description(`Update known PocketBase versions`)
|
|
||||||
.action(async (options: Options) => {
|
|
||||||
const cjs = await freshenPocketbaseVersions()
|
|
||||||
console.log(cjs)
|
|
||||||
})
|
|
||||||
return cmd
|
|
||||||
}
|
|
@ -14,6 +14,7 @@ import {
|
|||||||
import { GobotService } from '../services/GobotService'
|
import { GobotService } from '../services/GobotService'
|
||||||
import { EdgeCommand } from './commands/EdgeCommand'
|
import { EdgeCommand } from './commands/EdgeCommand'
|
||||||
import { FirewallCommand } from './commands/FirewallCommand'
|
import { FirewallCommand } from './commands/FirewallCommand'
|
||||||
|
import { GobotCommand } from './commands/GobotCommand'
|
||||||
import { HealthCommand } from './commands/HealthCommand'
|
import { HealthCommand } from './commands/HealthCommand'
|
||||||
import { MothershipCommand } from './commands/MothershipCommand'
|
import { MothershipCommand } from './commands/MothershipCommand'
|
||||||
import { SendMailCommand } from './commands/SendMailCommand'
|
import { SendMailCommand } from './commands/SendMailCommand'
|
||||||
@ -43,6 +44,7 @@ export const main = async () => {
|
|||||||
.addCommand(FirewallCommand())
|
.addCommand(FirewallCommand())
|
||||||
.addCommand(SendMailCommand())
|
.addCommand(SendMailCommand())
|
||||||
.addCommand(ServeCommand())
|
.addCommand(ServeCommand())
|
||||||
|
.addCommand(GobotCommand())
|
||||||
|
|
||||||
await program.parseAsync()
|
await program.parseAsync()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user