mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-04 22:39:46 +00:00
@@ -3,6 +3,7 @@ import { ExtendedVersion } from "../../../base/lib/exver"
|
||||
import { UpdateServiceInterfaces } from "../../../base/lib/interfaces/setupInterfaces"
|
||||
import { ExposedStorePaths } from "../../../base/lib/types"
|
||||
import * as T from "../../../base/lib/types"
|
||||
import { StorePath } from "../util"
|
||||
import { VersionGraph } from "../version/VersionGraph"
|
||||
import { Install } from "./setupInstall"
|
||||
import { Uninstall } from "./setupUninstall"
|
||||
@@ -16,6 +17,7 @@ export function setupInit<Manifest extends T.SDKManifest, Store>(
|
||||
effects: T.Effects
|
||||
}) => Promise<null | void | undefined>,
|
||||
actions: Actions<Store, any>,
|
||||
initStore: Store,
|
||||
exposedStore: ExposedStorePaths,
|
||||
): {
|
||||
packageInit: T.ExpectedExports.packageInit
|
||||
@@ -53,6 +55,14 @@ export function setupInit<Manifest extends T.SDKManifest, Store>(
|
||||
}
|
||||
},
|
||||
containerInit: async (opts) => {
|
||||
const prev = await opts.effects.getDataVersion()
|
||||
if (!prev) {
|
||||
await opts.effects.store.set({
|
||||
path: "" as StorePath,
|
||||
value: initStore,
|
||||
})
|
||||
await install.preInstall(opts)
|
||||
}
|
||||
await setServiceInterfaces({
|
||||
...opts,
|
||||
})
|
||||
|
||||
@@ -4,11 +4,15 @@ export type InstallFn<Manifest extends T.SDKManifest, Store> = (opts: {
|
||||
effects: T.Effects
|
||||
}) => Promise<null | void | undefined>
|
||||
export class Install<Manifest extends T.SDKManifest, Store> {
|
||||
private constructor(readonly fn: InstallFn<Manifest, Store>) {}
|
||||
private constructor(
|
||||
readonly fn: InstallFn<Manifest, Store>,
|
||||
readonly preFn?: InstallFn<Manifest, Store>,
|
||||
) {}
|
||||
static of<Manifest extends T.SDKManifest, Store>(
|
||||
fn: InstallFn<Manifest, Store>,
|
||||
preFn?: InstallFn<Manifest, Store>,
|
||||
) {
|
||||
return new Install(fn)
|
||||
return new Install(fn, preFn)
|
||||
}
|
||||
|
||||
async install({ effects }: Parameters<T.ExpectedExports.packageInit>[0]) {
|
||||
@@ -16,10 +20,18 @@ export class Install<Manifest extends T.SDKManifest, Store> {
|
||||
effects,
|
||||
})
|
||||
}
|
||||
|
||||
async preInstall({ effects }: Parameters<T.ExpectedExports.packageInit>[0]) {
|
||||
this.preFn &&
|
||||
(await this.preFn({
|
||||
effects,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
export function setupInstall<Manifest extends T.SDKManifest, Store>(
|
||||
fn: InstallFn<Manifest, Store>,
|
||||
preFn?: InstallFn<Manifest, Store>,
|
||||
) {
|
||||
return Install.of(fn)
|
||||
return Install.of(fn, preFn)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user