mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-26 10:21:55 +00:00
25 lines
596 B
TypeScript
25 lines
596 B
TypeScript
import { Effects, ExpectedExports } from "../types"
|
|
import { Utils, utils } from "../util"
|
|
|
|
export type InstallFn<WD> = (opts: {
|
|
effects: Effects
|
|
utils: Utils<WD>
|
|
}) => Promise<void>
|
|
export class Install<WD> {
|
|
private constructor(readonly fn: InstallFn<WD>) {}
|
|
static of<WD>(fn: InstallFn<WD>) {
|
|
return new Install(fn)
|
|
}
|
|
|
|
async init({
|
|
effects,
|
|
previousVersion,
|
|
}: Parameters<ExpectedExports.init<WD>>[0]) {
|
|
if (!previousVersion) await this.fn({ effects, utils: utils(effects) })
|
|
}
|
|
}
|
|
|
|
export function setupInstall<WD>(fn: InstallFn<WD>) {
|
|
return Install.of(fn)
|
|
}
|