mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-30 04:11:57 +00:00
chore: Update the start-sdk to use dependencies
This commit is contained in:
15
lib/config/dependencies.ts
Normal file
15
lib/config/dependencies.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Dependency, PackageId } from "../types";
|
||||
|
||||
export function exists(id: PackageId) {
|
||||
return {
|
||||
id,
|
||||
kind: "exists",
|
||||
} as Dependency;
|
||||
}
|
||||
|
||||
export function running(id: PackageId) {
|
||||
return {
|
||||
id,
|
||||
kind: "running",
|
||||
} as Dependency;
|
||||
}
|
||||
@@ -2,3 +2,4 @@ export * as configBuilder from "./builder";
|
||||
|
||||
export { setupConfigExports } from "./setupConfigExports";
|
||||
export { specToBuilder, specToBuilderFile } from "./specToBuilder";
|
||||
export * as dependencies from './dependencies'
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Config } from "./builder";
|
||||
import { DeepPartial, DependsOn, Effects, ExpectedExports } from "../types";
|
||||
import { DeepPartial, Dependencies, DependsOn, Effects, ExpectedExports } from "../types";
|
||||
import { InputSpec } from "./configTypes";
|
||||
import { nullIfEmpty } from "../util";
|
||||
import { TypeFromProps } from "../util/propertiesMatcher";
|
||||
@@ -13,15 +13,8 @@ import { TypeFromProps } from "../util/propertiesMatcher";
|
||||
*/
|
||||
export function setupConfigExports<A extends InputSpec, ConfigType>(options: {
|
||||
spec: Config<A>;
|
||||
dependsOn: DependsOn;
|
||||
write(options: {
|
||||
effects: Effects;
|
||||
input: TypeFromProps<A>;
|
||||
}): Promise<ConfigType>;
|
||||
read(options: {
|
||||
effects: Effects;
|
||||
config: ConfigType;
|
||||
}): Promise<null | DeepPartial<TypeFromProps<A>>>;
|
||||
write(options: { effects: Effects; input: TypeFromProps<A> }): Promise<[ConfigType, Dependencies]>;
|
||||
read(options: { effects: Effects; config: ConfigType }): Promise<null | DeepPartial<TypeFromProps<A>>>;
|
||||
}) {
|
||||
const validator = options.spec.validator();
|
||||
return {
|
||||
@@ -30,17 +23,15 @@ export function setupConfigExports<A extends InputSpec, ConfigType>(options: {
|
||||
await effects.error(String(validator.errorMessage(input)));
|
||||
return { error: "Set config type error for config" };
|
||||
}
|
||||
const output = await options.write({ input, effects });
|
||||
if (output) {
|
||||
await effects.setWrapperData({ path: "config", value: output });
|
||||
}
|
||||
const [output, dependencies] = await options.write({ input, effects });
|
||||
|
||||
await effects.setDependencies(dependencies);
|
||||
await effects.setWrapperData({ path: "config", value: output });
|
||||
}) as ExpectedExports.setConfig,
|
||||
getConfig: (async ({ effects, config }) => {
|
||||
return {
|
||||
spec: options.spec.build(),
|
||||
config: nullIfEmpty(
|
||||
await options.read({ effects, config: config as ConfigType })
|
||||
),
|
||||
config: nullIfEmpty(await options.read({ effects, config: config as ConfigType })),
|
||||
};
|
||||
}) as ExpectedExports.getConfig,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user