Files
start-sdk/lib/inits/setupInstall.ts
2023-05-05 10:45:21 -06:00

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)
}