@webiny/pulumi-sdk 5.26.0 → 5.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,6 +11,7 @@ export interface ApplicationStackArgs {
11
11
  pulumi: Pulumi;
12
12
  debug?: boolean;
13
13
  env: string;
14
+ variant?: string;
14
15
  }
15
16
  export interface ApplicationBuilderConfig extends Partial<ApplicationHooks> {
16
17
  id: string;
@@ -1 +1 @@
1
- {"version":3,"sources":["ApplicationBuilder.ts"],"names":["ApplicationBuilder","constructor","config","id","name","description","cli","onBeforeBuild","onAfterBuild","onBeforeDeploy","onAfterDeploy"],"mappings":";;;;;;;;;;;AA8BO,MAAeA,kBAAf,CAGP;AACI;AACA;AAUAC,EAAAA,WAAW,CAAiBC,MAAjB,EAAkC;AAAA,SAAjBA,MAAiB,GAAjBA,MAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACzC,SAAKC,EAAL,GAAUD,MAAM,CAACC,EAAjB;AACA,SAAKC,IAAL,GAAYF,MAAM,CAACE,IAAnB;AACA,SAAKC,WAAL,GAAmBH,MAAM,CAACG,WAA1B;AACA,SAAKC,GAAL,GAAWJ,MAAM,CAACI,GAAlB;AACA,SAAKC,aAAL,GAAqBL,MAAM,CAACK,aAA5B;AACA,SAAKC,YAAL,GAAoBN,MAAM,CAACM,YAA3B;AACA,SAAKC,cAAL,GAAsBP,MAAM,CAACO,cAA7B;AACA,SAAKC,aAAL,GAAqBR,MAAM,CAACQ,aAA5B;AACH;;AArBL","sourcesContent":["import { PreviewResult, RefreshResult, UpResult } from \"@pulumi/pulumi/automation\";\nimport { ApplicationHooks } from \"./ApplicationConfig\";\nimport { ApplicationHook } from \"./ApplicationHook\";\nimport { Pulumi } from \"./Pulumi\";\nimport { PulumiApp } from \"./PulumiApp\";\n\nexport interface ApplicationStackArgs {\n /** Root path of the application */\n appDir: string;\n /** Root dir of the project */\n projectDir: string;\n pulumi: Pulumi;\n debug?: boolean;\n env: string;\n}\n\nexport interface ApplicationBuilderConfig extends Partial<ApplicationHooks> {\n id: string;\n name: string;\n description?: string;\n cli?: Record<string, any>;\n}\n\nexport interface ApplicationStack {\n app?: PulumiApp;\n refresh(): Promise<RefreshResult | undefined>;\n preview(): Promise<PreviewResult | undefined>;\n up(): Promise<UpResult | undefined>;\n}\n\nexport abstract class ApplicationBuilder<\n TConfig extends ApplicationBuilderConfig = ApplicationBuilderConfig\n> implements ApplicationBuilderConfig\n{\n // It needs to duplicate configuration props for backwards compatibility.\n // There is a lot of CLI code, that depends on it.\n public readonly id: string;\n public readonly name: string;\n public readonly description?: string;\n public readonly cli?: Record<string, any>;\n public readonly onBeforeBuild?: ApplicationHook;\n public readonly onAfterBuild?: ApplicationHook;\n public readonly onBeforeDeploy?: ApplicationHook;\n public readonly onAfterDeploy?: ApplicationHook;\n\n constructor(public readonly config: TConfig) {\n this.id = config.id;\n this.name = config.name;\n this.description = config.description;\n this.cli = config.cli;\n this.onBeforeBuild = config.onBeforeBuild;\n this.onAfterBuild = config.onAfterBuild;\n this.onBeforeDeploy = config.onBeforeDeploy;\n this.onAfterDeploy = config.onAfterDeploy;\n }\n\n public abstract createOrSelectStack(args: ApplicationStackArgs): Promise<ApplicationStack>;\n}\n"]}
1
+ {"version":3,"sources":["ApplicationBuilder.ts"],"names":["ApplicationBuilder","constructor","config","id","name","description","cli","onBeforeBuild","onAfterBuild","onBeforeDeploy","onAfterDeploy"],"mappings":";;;;;;;;;;;AA+BO,MAAeA,kBAAf,CAGP;AACI;AACA;AAUAC,EAAAA,WAAW,CAAiBC,MAAjB,EAAkC;AAAA,SAAjBA,MAAiB,GAAjBA,MAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACzC,SAAKC,EAAL,GAAUD,MAAM,CAACC,EAAjB;AACA,SAAKC,IAAL,GAAYF,MAAM,CAACE,IAAnB;AACA,SAAKC,WAAL,GAAmBH,MAAM,CAACG,WAA1B;AACA,SAAKC,GAAL,GAAWJ,MAAM,CAACI,GAAlB;AACA,SAAKC,aAAL,GAAqBL,MAAM,CAACK,aAA5B;AACA,SAAKC,YAAL,GAAoBN,MAAM,CAACM,YAA3B;AACA,SAAKC,cAAL,GAAsBP,MAAM,CAACO,cAA7B;AACA,SAAKC,aAAL,GAAqBR,MAAM,CAACQ,aAA5B;AACH;;AArBL","sourcesContent":["import { PreviewResult, RefreshResult, UpResult } from \"@pulumi/pulumi/automation\";\nimport { ApplicationHooks } from \"./ApplicationConfig\";\nimport { ApplicationHook } from \"./ApplicationHook\";\nimport { Pulumi } from \"./Pulumi\";\nimport { PulumiApp } from \"./PulumiApp\";\n\nexport interface ApplicationStackArgs {\n /** Root path of the application */\n appDir: string;\n /** Root dir of the project */\n projectDir: string;\n pulumi: Pulumi;\n debug?: boolean;\n env: string;\n variant?: string;\n}\n\nexport interface ApplicationBuilderConfig extends Partial<ApplicationHooks> {\n id: string;\n name: string;\n description?: string;\n cli?: Record<string, any>;\n}\n\nexport interface ApplicationStack {\n app?: PulumiApp;\n refresh(): Promise<RefreshResult | undefined>;\n preview(): Promise<PreviewResult | undefined>;\n up(): Promise<UpResult | undefined>;\n}\n\nexport abstract class ApplicationBuilder<\n TConfig extends ApplicationBuilderConfig = ApplicationBuilderConfig\n> implements ApplicationBuilderConfig\n{\n // It needs to duplicate configuration props for backwards compatibility.\n // There is a lot of CLI code, that depends on it.\n public readonly id: string;\n public readonly name: string;\n public readonly description?: string;\n public readonly cli?: Record<string, any>;\n public readonly onBeforeBuild?: ApplicationHook;\n public readonly onAfterBuild?: ApplicationHook;\n public readonly onBeforeDeploy?: ApplicationHook;\n public readonly onAfterDeploy?: ApplicationHook;\n\n constructor(public readonly config: TConfig) {\n this.id = config.id;\n this.name = config.name;\n this.description = config.description;\n this.cli = config.cli;\n this.onBeforeBuild = config.onBeforeBuild;\n this.onAfterBuild = config.onAfterBuild;\n this.onBeforeDeploy = config.onBeforeDeploy;\n this.onAfterDeploy = config.onAfterDeploy;\n }\n\n public abstract createOrSelectStack(args: ApplicationStackArgs): Promise<ApplicationStack>;\n}\n"]}
@@ -18,7 +18,7 @@ var _trimNewlines = _interopRequireDefault(require("trim-newlines"));
18
18
 
19
19
  var _automation = require("@pulumi/pulumi/automation");
20
20
 
21
- var _getPulumiWorkDir = require("./utils/getPulumiWorkDir");
21
+ var _utils = require("./utils");
22
22
 
23
23
  var _ApplicationBuilder = require("./ApplicationBuilder");
24
24
 
@@ -30,7 +30,7 @@ class ApplicationBuilderGeneric extends _ApplicationBuilder.ApplicationBuilder {
30
30
 
31
31
  const relativePath = _path.default.relative(args.projectDir, args.appDir);
32
32
 
33
- const pulumiWorkDir = (0, _getPulumiWorkDir.getPulumiWorkDir)(args.projectDir, relativePath);
33
+ const pulumiWorkDir = (0, _utils.getPulumiWorkDir)(args.projectDir, relativePath);
34
34
 
35
35
  if (!_fs.default.existsSync(pulumiWorkDir)) {
36
36
  _fs.default.mkdirSync(pulumiWorkDir, {
@@ -40,6 +40,7 @@ class ApplicationBuilderGeneric extends _ApplicationBuilder.ApplicationBuilder {
40
40
 
41
41
  const app = await this.config.app({
42
42
  env: args.env,
43
+ variant: args.variant,
43
44
  appDir: args.appDir,
44
45
  projectDir: args.projectDir
45
46
  });
@@ -61,7 +62,10 @@ class ApplicationBuilderGeneric extends _ApplicationBuilder.ApplicationBuilder {
61
62
  PATH: args.pulumi.pulumiFolder + PATH_SEPARATOR + (process.env.PATH ?? "")
62
63
  }
63
64
  });
64
- const stackName = args.env;
65
+ const stackName = (0, _utils.getStackName)({
66
+ env: args.env,
67
+ variant: args.variant
68
+ });
65
69
  const stack = await _automation.Stack.createOrSelect(stackName, workspace);
66
70
  const options = {
67
71
  onOutput: line => console.log((0, _trimNewlines.default)(line)),
@@ -1 +1 @@
1
- {"version":3,"sources":["ApplicationBuilderGeneric.ts"],"names":["ApplicationBuilderGeneric","ApplicationBuilder","createOrSelectStack","args","PULUMI_SECRETS_PROVIDER","process","env","PATH_SEPARATOR","os","platform","relativePath","path","relative","projectDir","appDir","pulumiWorkDir","fs","existsSync","mkdirSync","recursive","app","config","appController","createController","workspace","LocalWorkspace","create","program","run","workDir","projectSettings","name","runtime","description","secretsProvider","pulumiHome","pulumi","pulumiFolder","envVars","WEBINY_ENV","WEBINY_PROJECT_NAME","PATH","stackName","stack","Stack","createOrSelect","options","onOutput","line","console","log","color","refresh","preview","up","result","outputs","key","Object","keys","value","deployFinished","createGenericApplication"],"mappings":";;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAGA;;AACA;;AAYO,MAAMA,yBAAN,SAAwCC,sCAAxC,CAAqF;AACxD,QAAnBC,mBAAmB,CAACC,IAAD,EAAwD;AACpF,UAAMC,uBAAuB,GAAGC,OAAO,CAACC,GAAR,CAAY,yBAAZ,CAAhC,CADoF,CAGpF;;AACA,UAAMC,cAAc,GAAGC,YAAGC,QAAH,OAAkB,OAAlB,GAA4B,GAA5B,GAAkC,GAAzD;;AAEA,UAAMC,YAAY,GAAGC,cAAKC,QAAL,CAAcT,IAAI,CAACU,UAAnB,EAA+BV,IAAI,CAACW,MAApC,CAArB;;AACA,UAAMC,aAAa,GAAG,wCAAiBZ,IAAI,CAACU,UAAtB,EAAkCH,YAAlC,CAAtB;;AAEA,QAAI,CAACM,YAAGC,UAAH,CAAcF,aAAd,CAAL,EAAmC;AAC/BC,kBAAGE,SAAH,CAAaH,aAAb,EAA4B;AAAEI,QAAAA,SAAS,EAAE;AAAb,OAA5B;AACH;;AAED,UAAMC,GAAG,GAAG,MAAM,KAAKC,MAAL,CAAYD,GAAZ,CAAgB;AAC9Bd,MAAAA,GAAG,EAAEH,IAAI,CAACG,GADoB;AAE9BQ,MAAAA,MAAM,EAAEX,IAAI,CAACW,MAFiB;AAG9BD,MAAAA,UAAU,EAAEV,IAAI,CAACU;AAHa,KAAhB,CAAlB;AAMA,UAAMS,aAAa,GAAGF,GAAG,CAACG,gBAAJ,EAAtB;AAEA,UAAMC,SAAS,GAA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Q,EAAN,GAAW;AACP,cAAMC,MAAM,GAAG,MAAMZ,KAAK,CAACW,EAAN,CAASR,OAAT,CAArB;AAEA,cAAMU,OAA4B,GAAG,EAArC;;AACA,aAAK,MAAMC,GAAX,IAAkBC,MAAM,CAACC,IAAP,CAAYJ,MAAM,CAACC,OAAnB,CAAlB,EAA+C;AAC3CA,UAAAA,OAAO,CAACC,GAAD,CAAP,GAAeF,MAAM,CAACC,OAAP,CAAeC,GAAf,EAAoBG,KAAnC;AACH;;AAED,cAAMtC,aAAa,CAACuC,cAAd,CAA6B;AAAEL,UAAAA;AAAF,SAA7B,CAAN;AACA,eAAOD,MAAP;AACH;;AAlBE,KAAP;AAoBH;;AAtEuF;;;;AAyErF,SAASO,wBAAT,CAAkCzC,MAAlC,EAAoE;AACvE,SAAO,IAAIrB,yBAAJ,CAA8BqB,MAA9B,CAAP;AACH","sourcesContent":["import os from \"os\";\nimport path from \"path\";\nimport fs from \"fs\";\nimport trimNewlines from \"trim-newlines\";\nimport { LocalWorkspace, Stack, UpOptions } from \"@pulumi/pulumi/automation\";\n\nimport { PulumiApp } from \"./PulumiApp\";\nimport { getPulumiWorkDir } from \"./utils/getPulumiWorkDir\";\nimport {\n ApplicationBuilder,\n ApplicationBuilderConfig,\n ApplicationStack,\n ApplicationStackArgs\n} from \"./ApplicationBuilder\";\nimport { ApplicationContext } from \"./ApplicationConfig\";\n\nexport interface ApplicationGenericConfig extends ApplicationBuilderConfig {\n app(ctx: ApplicationContext): Promise<PulumiApp> | PulumiApp;\n}\n\nexport class ApplicationBuilderGeneric extends ApplicationBuilder<ApplicationGenericConfig> {\n public async createOrSelectStack(args: ApplicationStackArgs): Promise<ApplicationStack> {\n const PULUMI_SECRETS_PROVIDER = process.env[\"PULUMI_SECRETS_PROVIDER\"];\n\n // Use \";\" when on Windows. For Mac and Linux, use \":\".\n const PATH_SEPARATOR = os.platform() === \"win32\" ? \";\" : \":\";\n\n const relativePath = path.relative(args.projectDir, args.appDir);\n const pulumiWorkDir = getPulumiWorkDir(args.projectDir, relativePath);\n\n if (!fs.existsSync(pulumiWorkDir)) {\n fs.mkdirSync(pulumiWorkDir, { recursive: true });\n }\n\n const app = await this.config.app({\n env: args.env,\n appDir: args.appDir,\n projectDir: args.projectDir\n });\n\n const appController = app.createController();\n\n const workspace = await LocalWorkspace.create({\n program: () => appController.run(),\n workDir: pulumiWorkDir,\n projectSettings: {\n name: this.config.name,\n runtime: \"nodejs\",\n description: this.config.description\n },\n secretsProvider: PULUMI_SECRETS_PROVIDER,\n pulumiHome: args.pulumi.pulumiFolder,\n envVars: {\n WEBINY_ENV: args.env,\n WEBINY_PROJECT_NAME: this.config.name,\n // Add Pulumi CLI path to env variable, so the CLI would be properly resolved.\n PATH: args.pulumi.pulumiFolder + PATH_SEPARATOR + (process.env.PATH ?? \"\")\n }\n });\n\n const stackName = args.env;\n\n const stack = await Stack.createOrSelect(stackName, workspace);\n\n type SharedOptions = Pick<UpOptions, \"onOutput\" | \"color\" | \"onEvent\">;\n const options: SharedOptions = {\n onOutput: line => console.log(trimNewlines(line)),\n color: \"always\"\n };\n\n return {\n app,\n async refresh() {\n return await stack.refresh(options);\n },\n async preview() {\n return await stack.preview(options);\n },\n async up() {\n const result = await stack.up(options);\n\n const outputs: Record<string, any> = {};\n for (const key of Object.keys(result.outputs)) {\n outputs[key] = result.outputs[key].value;\n }\n\n await appController.deployFinished({ outputs });\n return result;\n }\n };\n }\n}\n\nexport function createGenericApplication(config: ApplicationGenericConfig) {\n return new ApplicationBuilderGeneric(config);\n}\n"]}
1
+ {"version":3,"sources":["ApplicationBuilderGeneric.ts"],"names":["ApplicationBuilderGeneric","ApplicationBuilder","createOrSelectStack","args","PULUMI_SECRETS_PROVIDER","process","env","PATH_SEPARATOR","os","platform","relativePath","path","relative","projectDir","appDir","pulumiWorkDir","fs","existsSync","mkdirSync","recursive","app","config","variant","appController","createController","workspace","LocalWorkspace","create","program","run","workDir","projectSettings","name","runtime","description","secretsProvider","pulumiHome","pulumi","pulumiFolder","envVars","WEBINY_ENV","WEBINY_PROJECT_NAME","PATH","stackName","stack","Stack","createOrSelect","options","onOutput","line","console","log","color","refresh","preview","up","result","outputs","key","Object","keys","value","deployFinished","createGenericApplication"],"mappings":";;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAGA;;AACA;;AAYO,MAAMA,yBAAN,SAAwCC,sCAAxC,CAAqF;AACxD,QAAnBC,mBAAmB,CAACC,IAAD,EAAwD;AACpF,UAAMC,uBAAuB,GAAGC,OAAO,CAACC,GAAR,CAAY,yBAAZ,CAAhC,CADoF,CAGpF;;AACA,UAAMC,cAAc,GAAGC,YAAGC,QAAH,OAAkB,OAAlB,GAA4B,GAA5B,GAAkC,GAAzD;;AAEA,UAAMC,YAAY,GAAGC,cAAKC,QAAL,CAAcT,IAAI,CAACU,UAAnB,EAA+BV,IAAI,CAACW,MAApC,CAArB;;AACA,UAAMC,aAAa,GAAG,6BAAiBZ,IAAI,CAACU,UAAtB,EAAkCH,YAAlC,CAAtB;;AAEA,QAAI,CAACM,YAAGC,UAAH,CAAcF,aAAd,CAAL,EAAmC;AAC/BC,kBAAGE,SAAH,CAAaH,aAAb,EAA4B;AAAEI,QAAAA,SAAS,EAAE;AAAb,OAA5B;AACH;;AAED,UAAMC,GAAG,GAAG,MAAM,KAAKC,MAAL,CAAYD,GAAZ,CAAgB;AAC9Bd,MAAAA,GAAG,EAAEH,IAAI,CAACG,GADoB;AAE9BgB,MAAAA,OAAO,EAAEnB,IAAI,CAACmB,OAFgB;AAG9BR,MAAAA,MAAM,EAAEX,IAAI,CAACW,MAHiB;AAI9BD,MAAAA,UAAU,EAAEV,IAAI,CAACU;AAJa,KAAhB,CAAlB;AAOA,UAAMU,aAAa,GAAGH,GAAG,CAACI,gBAAJ,EAAtB;AAEA,UAAMC,SAAS,GAAG,MAAMC,2BAAeC,MAAf,CAAsB;AAC1CC,MAAAA,OAAO,EAAE,MAAML,aAAa,CAACM,GAAd,EAD2B;AAE1CC,MA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AN,GAAW;AACP,cAAMC,MAAM,GAAG,MAAMZ,KAAK,CAACW,EAAN,CAASR,OAAT,CAArB;AAEA,cAAMU,OAA4B,GAAG,EAArC;;AACA,aAAK,MAAMC,GAAX,IAAkBC,MAAM,CAACC,IAAP,CAAYJ,MAAM,CAACC,OAAnB,CAAlB,EAA+C;AAC3CA,UAAAA,OAAO,CAACC,GAAD,CAAP,GAAeF,MAAM,CAACC,OAAP,CAAeC,GAAf,EAAoBG,KAAnC;AACH;;AAED,cAAMtC,aAAa,CAACuC,cAAd,CAA6B;AAAEL,UAAAA;AAAF,SAA7B,CAAN;AACA,eAAOD,MAAP;AACH;;AAlBE,KAAP;AAoBH;;AA1EuF;;;;AA6ErF,SAASO,wBAAT,CAAkC1C,MAAlC,EAAoE;AACvE,SAAO,IAAIrB,yBAAJ,CAA8BqB,MAA9B,CAAP;AACH","sourcesContent":["import os from \"os\";\nimport path from \"path\";\nimport fs from \"fs\";\nimport trimNewlines from \"trim-newlines\";\nimport { LocalWorkspace, Stack, UpOptions } from \"@pulumi/pulumi/automation\";\n\nimport { PulumiApp } from \"./PulumiApp\";\nimport { getPulumiWorkDir, getStackName } from \"./utils\";\nimport {\n ApplicationBuilder,\n ApplicationBuilderConfig,\n ApplicationStack,\n ApplicationStackArgs\n} from \"./ApplicationBuilder\";\nimport { ApplicationContext } from \"./ApplicationConfig\";\n\nexport interface ApplicationGenericConfig extends ApplicationBuilderConfig {\n app(ctx: ApplicationContext): Promise<PulumiApp> | PulumiApp;\n}\n\nexport class ApplicationBuilderGeneric extends ApplicationBuilder<ApplicationGenericConfig> {\n public async createOrSelectStack(args: ApplicationStackArgs): Promise<ApplicationStack> {\n const PULUMI_SECRETS_PROVIDER = process.env[\"PULUMI_SECRETS_PROVIDER\"];\n\n // Use \";\" when on Windows. For Mac and Linux, use \":\".\n const PATH_SEPARATOR = os.platform() === \"win32\" ? \";\" : \":\";\n\n const relativePath = path.relative(args.projectDir, args.appDir);\n const pulumiWorkDir = getPulumiWorkDir(args.projectDir, relativePath);\n\n if (!fs.existsSync(pulumiWorkDir)) {\n fs.mkdirSync(pulumiWorkDir, { recursive: true });\n }\n\n const app = await this.config.app({\n env: args.env,\n variant: args.variant,\n appDir: args.appDir,\n projectDir: args.projectDir\n });\n\n const appController = app.createController();\n\n const workspace = await LocalWorkspace.create({\n program: () => appController.run(),\n workDir: pulumiWorkDir,\n projectSettings: {\n name: this.config.name,\n runtime: \"nodejs\",\n description: this.config.description\n },\n secretsProvider: PULUMI_SECRETS_PROVIDER,\n pulumiHome: args.pulumi.pulumiFolder,\n envVars: {\n WEBINY_ENV: args.env,\n WEBINY_PROJECT_NAME: this.config.name,\n // Add Pulumi CLI path to env variable, so the CLI would be properly resolved.\n PATH: args.pulumi.pulumiFolder + PATH_SEPARATOR + (process.env.PATH ?? \"\")\n }\n });\n\n const stackName = getStackName({\n env: args.env,\n variant: args.variant\n });\n\n const stack = await Stack.createOrSelect(stackName, workspace);\n\n type SharedOptions = Pick<UpOptions, \"onOutput\" | \"color\" | \"onEvent\">;\n const options: SharedOptions = {\n onOutput: line => console.log(trimNewlines(line)),\n color: \"always\"\n };\n\n return {\n app,\n async refresh() {\n return await stack.refresh(options);\n },\n async preview() {\n return await stack.preview(options);\n },\n async up() {\n const result = await stack.up(options);\n\n const outputs: Record<string, any> = {};\n for (const key of Object.keys(result.outputs)) {\n outputs[key] = result.outputs[key].value;\n }\n\n await appController.deployFinished({ outputs });\n return result;\n }\n };\n }\n}\n\nexport function createGenericApplication(config: ApplicationGenericConfig) {\n return new ApplicationBuilderGeneric(config);\n}\n"]}
@@ -2,6 +2,7 @@ import { ApplicationHook } from "./ApplicationHook";
2
2
  import { PulumiApp } from "./PulumiApp";
3
3
  export interface ApplicationContext {
4
4
  env: string;
5
+ variant?: string | null;
5
6
  appDir: string;
6
7
  projectDir: string;
7
8
  }
package/PulumiApp.d.ts CHANGED
@@ -48,12 +48,53 @@ export declare abstract class PulumiApp<TConfig = unknown> {
48
48
  abstract setup(config: TConfig): Promise<void> | void;
49
49
  onResource(handler: ResourceHandler): void;
50
50
  onAfterDeploy(handler: DeployEventHandler): void;
51
+ /**
52
+ * Adds a resource to pulumi app.
53
+ * It's not running the script immadietely, but enqueues the call.
54
+ * This way we are still able to modify the config of the resource.
55
+ * @param ctor Resource to be added, ie aws.s3.Bucket
56
+ * @param params Parameters to configure the resource
57
+ * @returns Object giving access to both resource outputs and its config.
58
+ */
51
59
  addResource<T extends ResourceConstructor>(ctor: T, params: CreateResourceParams<T>): PulumiAppResource<T>;
60
+ /**
61
+ * Registers output value within pulumi app.
62
+ * @param name Name of the output value
63
+ * @param output Value of the output
64
+ */
52
65
  addOutput<T>(name: string, output: T): void;
66
+ /**
67
+ * Registers one or more output values.
68
+ * @param outputs Dictionary containg output values.
69
+ */
53
70
  addOutputs(outputs: Record<string, unknown>): void;
71
+ /**
72
+ * Registers an app module witin app.
73
+ * Allows to decompose application into smaller pieces.
74
+ * Added module can be then retrieved with `getModule`.
75
+ * @param def Module definition
76
+ */
54
77
  addModule<TModule>(def: PulumiAppModuleDefinition<TModule, void>): TModule;
78
+ /**
79
+ * Registers an app module witin app.
80
+ * Allows to decompose application into smaller pieces.
81
+ * Added module can be then retrieved with `getModule`.
82
+ * @param def Module definition
83
+ * @param config Module config
84
+ */
55
85
  addModule<TModule, TConfig>(def: PulumiAppModuleDefinition<TModule, TConfig>, config: TConfig): TModule;
86
+ /**
87
+ * Schedules a handler to be executed when running pulumi script.
88
+ * Anything, that is returned from handler will be wrapped in pulumi.Output
89
+ * so it can be used in other places.
90
+ * @param handler Handler to be executed.
91
+ * @returns Result of the handler wrapped with pulumi.Output
92
+ */
56
93
  addHandler<T>(handler: () => Promise<T> | T): pulumi.Output<pulumi.Unwrap<T>>;
94
+ /**
95
+ * Returns a module by its definition
96
+ * @param def Module definition
97
+ */
57
98
  getModule<TConfig, TModule>(def: PulumiAppModuleDefinition<TModule, TConfig>): TModule;
58
99
  getModule<TConfig, TModule>(def: PulumiAppModuleDefinition<TModule, TConfig>, opts: {
59
100
  optional: false;
@@ -61,6 +102,7 @@ export declare abstract class PulumiApp<TConfig = unknown> {
61
102
  getModule<TConfig, TModule>(def: PulumiAppModuleDefinition<TModule, TConfig>, opts: {
62
103
  optional: true;
63
104
  }): TModule | null;
105
+ /** Internal usage only. */
64
106
  createController(): {
65
107
  run: () => Promise<Record<string, any>>;
66
108
  deployFinished: (params: DeployEventParams) => Promise<void>;
package/PulumiApp.js CHANGED
@@ -12,7 +12,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
12
12
 
13
13
  var pulumi = _interopRequireWildcard(require("@pulumi/pulumi"));
14
14
 
15
- var _tagResources = require("./utils/tagResources");
15
+ var _utils = require("./utils");
16
16
 
17
17
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
18
18
 
@@ -38,6 +38,15 @@ class PulumiApp {
38
38
  onAfterDeploy(handler) {
39
39
  this.afterDeployHandlers.push(handler);
40
40
  }
41
+ /**
42
+ * Adds a resource to pulumi app.
43
+ * It's not running the script immadietely, but enqueues the call.
44
+ * This way we are still able to modify the config of the resource.
45
+ * @param ctor Resource to be added, ie aws.s3.Bucket
46
+ * @param params Parameters to configure the resource
47
+ * @returns Object giving access to both resource outputs and its config.
48
+ */
49
+
41
50
 
42
51
  addResource(ctor, params) {
43
52
  const config = params.config ?? {};
@@ -57,14 +66,32 @@ class PulumiApp {
57
66
  };
58
67
  return resource;
59
68
  }
69
+ /**
70
+ * Registers output value within pulumi app.
71
+ * @param name Name of the output value
72
+ * @param output Value of the output
73
+ */
74
+
60
75
 
61
76
  addOutput(name, output) {
62
77
  this.outputs[name] = output;
63
78
  }
79
+ /**
80
+ * Registers one or more output values.
81
+ * @param outputs Dictionary containg output values.
82
+ */
83
+
64
84
 
65
85
  addOutputs(outputs) {
66
86
  Object.assign(this.outputs, outputs);
67
87
  }
88
+ /**
89
+ * Registers an app module witin app.
90
+ * Allows to decompose application into smaller pieces.
91
+ * Added module can be then retrieved with `getModule`.
92
+ * @param def Module definition
93
+ */
94
+
68
95
 
69
96
  addModule(def, config) {
70
97
  if (this.modules.has(def.symbol)) {
@@ -75,6 +102,14 @@ class PulumiApp {
75
102
  this.modules.set(def.symbol, module);
76
103
  return module;
77
104
  }
105
+ /**
106
+ * Schedules a handler to be executed when running pulumi script.
107
+ * Anything, that is returned from handler will be wrapped in pulumi.Output
108
+ * so it can be used in other places.
109
+ * @param handler Handler to be executed.
110
+ * @returns Result of the handler wrapped with pulumi.Output
111
+ */
112
+
78
113
 
79
114
  addHandler(handler) {
80
115
  const promise = new Promise(resolve => {
@@ -84,6 +119,11 @@ class PulumiApp {
84
119
  });
85
120
  return pulumi.output(promise);
86
121
  }
122
+ /**
123
+ * Returns a module by its definition
124
+ * @param def Module definition
125
+ */
126
+
87
127
 
88
128
  getModule(def, opts) {
89
129
  const module = this.modules.get(def.symbol);
@@ -98,6 +138,8 @@ class PulumiApp {
98
138
 
99
139
  return module;
100
140
  }
141
+ /** Internal usage only. */
142
+
101
143
 
102
144
  createController() {
103
145
  return {
@@ -107,7 +149,7 @@ class PulumiApp {
107
149
  }
108
150
 
109
151
  async runProgram() {
110
- (0, _tagResources.tagResources)({
152
+ (0, _utils.tagResources)({
111
153
  WbyProjectName: String(process.env["WEBINY_PROJECT_NAME"]),
112
154
  WbyEnvironment: String(process.env["WEBINY_ENV"])
113
155
  });
package/PulumiApp.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["PulumiApp.ts"],"names":["PulumiApp","constructor","params","Map","name","ctx","onResource","handler","resourceHandlers","push","onAfterDeploy","afterDeployHandlers","addResource","ctor","config","opts","promise","Promise","resolve","handlers","forEach","resourceInstance","resource","createConfigProxy","output","pulumi","addOutput","outputs","addOutputs","Object","assign","addModule","def","modules","has","symbol","Error","module","run","set","addHandler","getModule","get","optional","createController","runProgram","bind","deployFinished","WbyProjectName","String","process","env","WbyEnvironment","defineApp","appDef","App","setup","obj","Proxy","target","p","key","setter","value","modifier","currentValue","newValue","apply","v"],"mappings":";;;;;;;;;;;;AAAA;;AAKA;;;;;;AA6CO,MAAeA,SAAf,CAA4C;AAS/CC,EAAAA,WAAW,CAACC,MAAD,EAA0B;AAAA;AAAA;AAAA,4DANkB,EAMlB;AAAA,+DALwB,EAKxB;AAAA,oDAJuB,EAIvB;AAAA,mDAHW,EAGX;AAAA,mDAFV,IAAIC,GAAJ,EAEU;AACjC,SAAKC,IAAL,GAAYF,MAAM,CAACE,IAAnB;AACA,SAAKC,GAAL,GAAWH,MAAM,CAACG,GAAlB;AACH;;AAIMC,EAAAA,UAAU,CAACC,OAAD,EAAiC;AAC9C,SAAKC,gBAAL,CAAsBC,IAAtB,CAA2BF,OAA3B;AACH;;AAEMG,EAAAA,aAAa,CAACH,OAAD,EAA8B;AAC9C,SAAKI,mBAAL,CAAyBF,IAAzB,CAA8BF,OAA9B;AACH;;AAEMK,EAAAA,WAAW,CAAgCC,IAAhC,EAAyCX,MAAzC,EAA0E;AACxF,UAAMY,MAAM,GAAGZ,MAAM,CAACY,MAAP,IAAkB,EAAjC;AACA,UAAMC,IAAI,GAAGb,MAAM,CAACa,IAAP,IAAe,EAA5B;AAEA,UAAMC,OAAO,GAAG,IAAIC,OAAJ,CAA6BC,OAAO,IAAI;AACpD,WAAKC,QAAL,CAAcV,IAAd,CAAmB,MAAM;AACrB,aAAKD,gBAAL,CAAsBY,OAAtB,CAA8Bb,OAAO,IAAIA,OAAO,CAACc,gBAAD,CAAhD;AACA,cAAMA,gBAAgB,GAAG,IAAIR,IAAJ,CAASS,QAAQ,CAAClB,IAAlB,EAAwBU,MAAxB,EAAgCC,IAAhC,CAAzB;AACAG,QAAAA,OAAO,CAACG,gBAAD,CAAP;AACH,OAJD;AAKH,KANe,CAAhB;AAQA,UAAMC,Q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AAAqBC,QAAAA,GAAG,EAAEA;AAA1B,OAAN;AACH;;AAEiB,UAALmD,KAAK,CAAC1C,MAAD,EAAkB;AAChC,YAAMU,MAAM,GAAG,MAAMtB,MAAM,CAACY,MAAP,CAAc,IAAd,EAAoBA,MAApB,CAArB;AACAe,MAAAA,MAAM,CAACC,MAAP,CAAc,IAAd,EAAoBN,MAApB;AACH;;AAR+C,GAApD;AAWA,SAAO8B,MAAP;AACH;;AAED,SAAS/B,iBAAT,CAA6CkC,GAA7C,EAAqD;AACjD,SAAO,IAAIC,KAAJ,CAAUD,GAAV,EAAe;AAClBf,IAAAA,GAAG,CAACiB,MAAD,EAASC,CAAT,EAAoB;AAEnB,YAAMC,GAAG,GAAGD,CAAZ;;AACA,YAAME,MAA+B,GAAIC,KAAD,IAA0C;AAC9E,YAAI,OAAOA,KAAP,KAAiB,UAArB,EAAiC;AAC7B,gBAAMC,QAAQ,GAAGD,KAAjB;AACA,gBAAME,YAAY,GAAGN,MAAM,CAACE,GAAD,CAA3B,CAF6B,CAG7B;;AACA,gBAAMK,QAAQ,GAAGzC,MAAM,CAACD,MAAP,CAAcyC,YAAd,EAA4BE,KAA5B,CAAkCC,CAAC,IAAI;AACpD,kBAAMF,QAAQ,GAAGF,QAAQ,CAACI,CAAD,CAAzB;AACA,mBAAO3C,MAAM,CAACD,MAAP,CAAc0C,QAAd,CAAP;AACH,WAHgB,CAAjB;AAKAP,UAAAA,MAAM,CAACE,GAAD,CAAN,GAAcK,QAAd;AACH,SAVD,MAUO;AACHP,UAAAA,MAAM,CAACE,GAAD,CAAN,GAAcE,KAAd;AACH;AACJ,OAdD;;AAgBA,aAAOD,MAAP;AACH;;AArBiB,GAAf,CAAP;AAuBH","sourcesContent":["import * as pulumi from \"@pulumi/pulumi\";\n\nimport { ApplicationContext } from \"./ApplicationConfig\";\nimport { PulumiAppModuleDefinition } from \"./PulumiAppModule\";\nimport { ResourceArgs, ResourceConstructor, ResourceType } from \"./PulumiResource\";\nimport { tagResources } from \"./utils/tagResources\";\n\nexport interface CreateResourceParams<TCtor extends ResourceConstructor> {\n name: string;\n config: ResourceArgs<TCtor>;\n opts?: pulumi.CustomResourceOptions;\n}\n\nexport interface PulumiAppResource<T extends ResourceConstructor> {\n name: string;\n readonly config: ResourceConfigProxy<ResourceArgs<T>>;\n readonly opts: pulumi.CustomResourceOptions;\n readonly output: pulumi.Output<pulumi.Unwrap<ResourceType<T>>>;\n}\n\nexport interface PulumiAppParams {\n name: string;\n ctx: ApplicationContext;\n}\n\nexport interface ResourceHandler {\n (resource: PulumiAppResource<ResourceConstructor>): void;\n}\n\nexport type ResourceConfigProxy<T extends object> = {\n readonly [K in keyof T]-?: ResourceConfigSetter<T[K]>;\n};\n\nexport interface ResourceConfigSetter<T> {\n (value: T): void;\n (fcn: ResourceConfigModifier<T>): void;\n}\n\nexport interface ResourceConfigModifier<T> {\n (value: pulumi.Unwrap<T>): T | void;\n}\n\ninterface DeployEventParams {\n outputs: Record<string, any>;\n}\n\ninterface DeployEventHandler {\n (params: DeployEventParams): Promise<void> | void;\n}\n\nexport abstract class PulumiApp<TConfig = unknown> {\n public readonly name: string;\n public readonly ctx: ApplicationContext;\n private readonly resourceHandlers: ResourceHandler[] = [];\n private readonly afterDeployHandlers: DeployEventHandler[] = [];\n private readonly handlers: (() => void | Promise<void>)[] = [];\n private readonly outputs: Record<string, any> = {};\n private readonly modules = new Map<symbol, unknown>();\n\n constructor(params: PulumiAppParams) {\n this.name = params.name;\n this.ctx = params.ctx;\n }\n\n public abstract setup(config: TConfig): Promise<void> | void;\n\n public onResource(handler: ResourceHandler): void {\n this.resourceHandlers.push(handler);\n }\n\n public onAfterDeploy(handler: DeployEventHandler) {\n this.afterDeployHandlers.push(handler);\n }\n\n public addResource<T extends ResourceConstructor>(ctor: T, params: CreateResourceParams<T>) {\n const config = params.config ?? ({} as ResourceArgs<T>);\n const opts = params.opts ?? {};\n\n const promise = new Promise<ResourceType<T>>(resolve => {\n this.handlers.push(() => {\n this.resourceHandlers.forEach(handler => handler(resourceInstance));\n const resourceInstance = new ctor(resource.name, config, opts);\n resolve(resourceInstance);\n });\n });\n\n const resource: PulumiAppResource<T> = {\n name: params.name,\n config: createConfigProxy(config),\n opts,\n output: pulumi.output(promise)\n };\n\n return resource;\n }\n\n public addOutput<T>(name: string, output: T) {\n this.outputs[name] = output;\n }\n\n public addOutputs(outputs: Record<string, unknown>) {\n Object.assign(this.outputs, outputs);\n }\n\n public addModule<TModule>(def: PulumiAppModuleDefinition<TModule, void>): TModule;\n public addModule<TModule, TConfig>(\n def: PulumiAppModuleDefinition<TModule, TConfig>,\n config: TConfig\n ): TModule;\n public addModule<TModule, TConfig>(\n def: PulumiAppModuleDefinition<TModule, TConfig>,\n config?: TConfig\n ) {\n if (this.modules.has(def.symbol)) {\n throw new Error(\n `Module \"${def.name}\" is already present in the \"${this.name}\" application.`\n );\n }\n\n const module = def.run(this, config as TConfig);\n this.modules.set(def.symbol, module);\n\n return module;\n }\n\n public addHandler<T>(handler: () => Promise<T> | T) {\n const promise = new Promise<T>(resolve => {\n this.handlers.push(async () => {\n resolve(await handler());\n });\n });\n\n return pulumi.output(promise);\n }\n\n public getModule<TConfig, TModule>(def: PulumiAppModuleDefinition<TModule, TConfig>): TModule;\n public getModule<TConfig, TModule>(\n def: PulumiAppModuleDefinition<TModule, TConfig>,\n opts: { optional: false }\n ): TModule;\n public getModule<TConfig, TModule>(\n def: PulumiAppModuleDefinition<TModule, TConfig>,\n opts: { optional: true }\n ): TModule | null;\n public getModule<TConfig, TModule>(\n def: PulumiAppModuleDefinition<TModule, TConfig>,\n opts?: { optional: boolean }\n ) {\n const module = this.modules.get(def.symbol);\n\n if (!module) {\n if (opts?.optional) {\n return null;\n } else {\n throw new Error(`Module \"${def.name}\" not found in \"${this.name}\" app`);\n }\n }\n\n return module;\n }\n\n public createController() {\n return {\n run: this.runProgram.bind(this),\n deployFinished: this.deployFinished.bind(this)\n };\n }\n\n private async runProgram() {\n tagResources({\n WbyProjectName: String(process.env[\"WEBINY_PROJECT_NAME\"]),\n WbyEnvironment: String(process.env[\"WEBINY_ENV\"])\n });\n\n for (const handler of this.handlers) {\n await handler();\n }\n\n return this.outputs;\n }\n\n private async deployFinished(params: DeployEventParams) {\n for (const handler of this.afterDeployHandlers) {\n await handler(params);\n }\n }\n}\n\nexport interface CreateAppParams<TOutput extends Record<string, unknown>, TConfig = void> {\n name: string;\n config(app: PulumiApp, config: TConfig): TOutput | Promise<TOutput>;\n}\n\nexport function defineApp<TOutput extends Record<string, unknown>, TConfig = void>(\n params: CreateAppParams<TOutput, TConfig>\n) {\n const appDef = class App extends PulumiApp<TConfig> {\n constructor(ctx: ApplicationContext) {\n super({ name: params.name, ctx: ctx });\n }\n\n public async setup(config: TConfig) {\n const output = await params.config(this, config);\n Object.assign(this, output);\n }\n };\n\n return appDef as new (ctx: ApplicationContext) => PulumiApp<TConfig> & TOutput;\n}\n\nfunction createConfigProxy<T extends object>(obj: T) {\n return new Proxy(obj, {\n get(target, p: string) {\n type V = T[keyof T];\n const key = p as keyof T;\n const setter: ResourceConfigSetter<V> = (value: V | ResourceConfigModifier<V>) => {\n if (typeof value === \"function\") {\n const modifier = value as ResourceConfigModifier<V>;\n const currentValue = target[key];\n // Wrap a current config with a function.\n const newValue = pulumi.output(currentValue).apply(v => {\n const newValue = modifier(v);\n return pulumi.output(newValue);\n });\n\n target[key] = newValue as unknown as V;\n } else {\n target[key] = value;\n }\n };\n\n return setter;\n }\n }) as ResourceConfigProxy<T>;\n}\n"]}
1
+ {"version":3,"sources":["PulumiApp.ts"],"names":["PulumiApp","constructor","params","Map","name","ctx","onResource","handler","resourceHandlers","push","onAfterDeploy","afterDeployHandlers","addResource","ctor","config","opts","promise","Promise","resolve","handlers","forEach","resourceInstance","resource","createConfigProxy","output","pulumi","addOutput","outputs","addOutputs","Object","assign","addModule","def","modules","has","symbol","Error","module","run","set","addHandler","getModule","get","optional","createController","runProgram","bind","deployFinished","WbyProjectName","String","process","env","WbyEnvironment","defineApp","appDef","App","setup","obj","Proxy","target","p","key","setter","value","modifier","currentValue","newValue","apply","v"],"mappings":";;;;;;;;;;;;AAAA;;AAKA;;;;;;AA6CO,MAAeA,SAAf,CAA4C;AAS/CC,EAAAA,WAAW,CAACC,MAAD,EAA0B;AAAA;AAAA;AAAA,4DANkB,EAMlB;AAAA,+DALwB,EAKxB;AAAA,oDAJuB,EAIvB;AAAA,mDAHW,EAGX;AAAA,mDAFV,IAAIC,GAAJ,EAEU;AACjC,SAAKC,IAAL,GAAYF,MAAM,CAACE,IAAnB;AACA,SAAKC,GAAL,GAAWH,MAAM,CAACG,GAAlB;AACH;;AAIMC,EAAAA,UAAU,CAACC,OAAD,EAAiC;AAC9C,SAAKC,gBAAL,CAAsBC,IAAtB,CAA2BF,OAA3B;AACH;;AAEMG,EAAAA,aAAa,CAACH,OAAD,EAA8B;AAC9C,SAAKI,mBAAL,CAAyBF,IAAzB,CAA8BF,OAA9B;AACH;AAED;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;;;AACWK,EAAAA,WAAW,CAAgCC,IAAhC,EAAyCX,MAAzC,EAA0E;AACxF,UAAMY,MAAM,GAAGZ,MAAM,CAACY,MAAP,IAAkB,EAAjC;AACA,UAAMC,IAAI,GAAGb,MAAM,CAACa,IAAP,IAAe,EAA5B;AAEA,UAAMC,OAAO,GAAG,IAAIC,OAAJ,CAA6BC,OAAO,IAAI;AACpD,WAAKC,QAAL,CAAcV,IAAd,CAAmB,MAAM;AACrB,aAAKD,gBAAL,CAAsBY,OAAtB,CAA8Bb,OAAO,IAAIA,OAAO,CAACc,gBAAD,CAAhD;AACA,cAAMA,gBAAgB,GAAG,IAAIR,IAAJ,CAASS,QAAQ,CAAClB,IAAlB,EAAwBU,MAAxB,EAAgCC,IAAhC,CAAzB;AACAG,QAAAA,OAAO,CAACG,gBAAD,CAAP;AACH,OAJD;AAKH,KANe,CAAhB;AAQA,UAAMC,QAA8B,GAAG;AACnClB,MAAAA,IAAI,EAAEF,MAAM,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DC,IAAAA,WAAW,CAACI,GAAD,EAA0B;AACjC,YAAM;AAAED,QAAAA,IAAI,EAAEF,MAAM,CAACE,IAAf;AAAqBC,QAAAA,GAAG,EAAEA;AAA1B,OAAN;AACH;;AAEiB,UAALmD,KAAK,CAAC1C,MAAD,EAAkB;AAChC,YAAMU,MAAM,GAAG,MAAMtB,MAAM,CAACY,MAAP,CAAc,IAAd,EAAoBA,MAApB,CAArB;AACAe,MAAAA,MAAM,CAACC,MAAP,CAAc,IAAd,EAAoBN,MAApB;AACH;;AAR+C,GAApD;AAWA,SAAO8B,MAAP;AACH;;AAED,SAAS/B,iBAAT,CAA6CkC,GAA7C,EAAqD;AACjD,SAAO,IAAIC,KAAJ,CAAUD,GAAV,EAAe;AAClBf,IAAAA,GAAG,CAACiB,MAAD,EAASC,CAAT,EAAoB;AAEnB,YAAMC,GAAG,GAAGD,CAAZ;;AACA,YAAME,MAA+B,GAAIC,KAAD,IAA0C;AAC9E,YAAI,OAAOA,KAAP,KAAiB,UAArB,EAAiC;AAC7B,gBAAMC,QAAQ,GAAGD,KAAjB;AACA,gBAAME,YAAY,GAAGN,MAAM,CAACE,GAAD,CAA3B,CAF6B,CAG7B;;AACA,gBAAMK,QAAQ,GAAGzC,MAAM,CAACD,MAAP,CAAcyC,YAAd,EAA4BE,KAA5B,CAAkCC,CAAC,IAAI;AACpD,kBAAMF,QAAQ,GAAGF,QAAQ,CAACI,CAAD,CAAzB;AACA,mBAAO3C,MAAM,CAACD,MAAP,CAAc0C,QAAd,CAAP;AACH,WAHgB,CAAjB;AAKAP,UAAAA,MAAM,CAACE,GAAD,CAAN,GAAcK,QAAd;AACH,SAVD,MAUO;AACHP,UAAAA,MAAM,CAACE,GAAD,CAAN,GAAcE,KAAd;AACH;AACJ,OAdD;;AAgBA,aAAOD,MAAP;AACH;;AArBiB,GAAf,CAAP;AAuBH","sourcesContent":["import * as pulumi from \"@pulumi/pulumi\";\n\nimport { ApplicationContext } from \"./ApplicationConfig\";\nimport { PulumiAppModuleDefinition } from \"./PulumiAppModule\";\nimport { ResourceArgs, ResourceConstructor, ResourceType } from \"./PulumiResource\";\nimport { tagResources } from \"./utils\";\n\nexport interface CreateResourceParams<TCtor extends ResourceConstructor> {\n name: string;\n config: ResourceArgs<TCtor>;\n opts?: pulumi.CustomResourceOptions;\n}\n\nexport interface PulumiAppResource<T extends ResourceConstructor> {\n name: string;\n readonly config: ResourceConfigProxy<ResourceArgs<T>>;\n readonly opts: pulumi.CustomResourceOptions;\n readonly output: pulumi.Output<pulumi.Unwrap<ResourceType<T>>>;\n}\n\nexport interface PulumiAppParams {\n name: string;\n ctx: ApplicationContext;\n}\n\nexport interface ResourceHandler {\n (resource: PulumiAppResource<ResourceConstructor>): void;\n}\n\nexport type ResourceConfigProxy<T extends object> = {\n readonly [K in keyof T]-?: ResourceConfigSetter<T[K]>;\n};\n\nexport interface ResourceConfigSetter<T> {\n (value: T): void;\n (fcn: ResourceConfigModifier<T>): void;\n}\n\nexport interface ResourceConfigModifier<T> {\n (value: pulumi.Unwrap<T>): T | void;\n}\n\ninterface DeployEventParams {\n outputs: Record<string, any>;\n}\n\ninterface DeployEventHandler {\n (params: DeployEventParams): Promise<void> | void;\n}\n\nexport abstract class PulumiApp<TConfig = unknown> {\n public readonly name: string;\n public readonly ctx: ApplicationContext;\n private readonly resourceHandlers: ResourceHandler[] = [];\n private readonly afterDeployHandlers: DeployEventHandler[] = [];\n private readonly handlers: (() => void | Promise<void>)[] = [];\n private readonly outputs: Record<string, any> = {};\n private readonly modules = new Map<symbol, unknown>();\n\n constructor(params: PulumiAppParams) {\n this.name = params.name;\n this.ctx = params.ctx;\n }\n\n public abstract setup(config: TConfig): Promise<void> | void;\n\n public onResource(handler: ResourceHandler): void {\n this.resourceHandlers.push(handler);\n }\n\n public onAfterDeploy(handler: DeployEventHandler) {\n this.afterDeployHandlers.push(handler);\n }\n\n /**\n * Adds a resource to pulumi app.\n * It's not running the script immadietely, but enqueues the call.\n * This way we are still able to modify the config of the resource.\n * @param ctor Resource to be added, ie aws.s3.Bucket\n * @param params Parameters to configure the resource\n * @returns Object giving access to both resource outputs and its config.\n */\n public addResource<T extends ResourceConstructor>(ctor: T, params: CreateResourceParams<T>) {\n const config = params.config ?? ({} as ResourceArgs<T>);\n const opts = params.opts ?? {};\n\n const promise = new Promise<ResourceType<T>>(resolve => {\n this.handlers.push(() => {\n this.resourceHandlers.forEach(handler => handler(resourceInstance));\n const resourceInstance = new ctor(resource.name, config, opts);\n resolve(resourceInstance);\n });\n });\n\n const resource: PulumiAppResource<T> = {\n name: params.name,\n config: createConfigProxy(config),\n opts,\n output: pulumi.output(promise)\n };\n\n return resource;\n }\n\n /**\n * Registers output value within pulumi app.\n * @param name Name of the output value\n * @param output Value of the output\n */\n public addOutput<T>(name: string, output: T) {\n this.outputs[name] = output;\n }\n\n /**\n * Registers one or more output values.\n * @param outputs Dictionary containg output values.\n */\n public addOutputs(outputs: Record<string, unknown>) {\n Object.assign(this.outputs, outputs);\n }\n\n /**\n * Registers an app module witin app.\n * Allows to decompose application into smaller pieces.\n * Added module can be then retrieved with `getModule`.\n * @param def Module definition\n */\n public addModule<TModule>(def: PulumiAppModuleDefinition<TModule, void>): TModule;\n\n /**\n * Registers an app module witin app.\n * Allows to decompose application into smaller pieces.\n * Added module can be then retrieved with `getModule`.\n * @param def Module definition\n * @param config Module config\n */\n public addModule<TModule, TConfig>(\n def: PulumiAppModuleDefinition<TModule, TConfig>,\n config: TConfig\n ): TModule;\n public addModule<TModule, TConfig>(\n def: PulumiAppModuleDefinition<TModule, TConfig>,\n config?: TConfig\n ) {\n if (this.modules.has(def.symbol)) {\n throw new Error(\n `Module \"${def.name}\" is already present in the \"${this.name}\" application.`\n );\n }\n\n const module = def.run(this, config as TConfig);\n this.modules.set(def.symbol, module);\n\n return module;\n }\n\n /**\n * Schedules a handler to be executed when running pulumi script.\n * Anything, that is returned from handler will be wrapped in pulumi.Output\n * so it can be used in other places.\n * @param handler Handler to be executed.\n * @returns Result of the handler wrapped with pulumi.Output\n */\n public addHandler<T>(handler: () => Promise<T> | T) {\n const promise = new Promise<T>(resolve => {\n this.handlers.push(async () => {\n resolve(await handler());\n });\n });\n\n return pulumi.output(promise);\n }\n\n /**\n * Returns a module by its definition\n * @param def Module definition\n */\n public getModule<TConfig, TModule>(def: PulumiAppModuleDefinition<TModule, TConfig>): TModule;\n public getModule<TConfig, TModule>(\n def: PulumiAppModuleDefinition<TModule, TConfig>,\n opts: { optional: false }\n ): TModule;\n public getModule<TConfig, TModule>(\n def: PulumiAppModuleDefinition<TModule, TConfig>,\n opts: { optional: true }\n ): TModule | null;\n public getModule<TConfig, TModule>(\n def: PulumiAppModuleDefinition<TModule, TConfig>,\n opts?: { optional: boolean }\n ) {\n const module = this.modules.get(def.symbol);\n\n if (!module) {\n if (opts?.optional) {\n return null;\n } else {\n throw new Error(`Module \"${def.name}\" not found in \"${this.name}\" app`);\n }\n }\n\n return module;\n }\n\n /** Internal usage only. */\n public createController() {\n return {\n run: this.runProgram.bind(this),\n deployFinished: this.deployFinished.bind(this)\n };\n }\n\n private async runProgram() {\n tagResources({\n WbyProjectName: String(process.env[\"WEBINY_PROJECT_NAME\"]),\n WbyEnvironment: String(process.env[\"WEBINY_ENV\"])\n });\n\n for (const handler of this.handlers) {\n await handler();\n }\n\n return this.outputs;\n }\n\n private async deployFinished(params: DeployEventParams) {\n for (const handler of this.afterDeployHandlers) {\n await handler(params);\n }\n }\n}\n\nexport interface CreateAppParams<TOutput extends Record<string, unknown>, TConfig = void> {\n name: string;\n config(app: PulumiApp, config: TConfig): TOutput | Promise<TOutput>;\n}\n\nexport function defineApp<TOutput extends Record<string, unknown>, TConfig = void>(\n params: CreateAppParams<TOutput, TConfig>\n) {\n const appDef = class App extends PulumiApp<TConfig> {\n constructor(ctx: ApplicationContext) {\n super({ name: params.name, ctx: ctx });\n }\n\n public async setup(config: TConfig) {\n const output = await params.config(this, config);\n Object.assign(this, output);\n }\n };\n\n return appDef as new (ctx: ApplicationContext) => PulumiApp<TConfig> & TOutput;\n}\n\nfunction createConfigProxy<T extends object>(obj: T) {\n return new Proxy(obj, {\n get(target, p: string) {\n type V = T[keyof T];\n const key = p as keyof T;\n const setter: ResourceConfigSetter<V> = (value: V | ResourceConfigModifier<V>) => {\n if (typeof value === \"function\") {\n const modifier = value as ResourceConfigModifier<V>;\n const currentValue = target[key];\n // Wrap a current config with a function.\n const newValue = pulumi.output(currentValue).apply(v => {\n const newValue = modifier(v);\n return pulumi.output(newValue);\n });\n\n target[key] = newValue as unknown as V;\n } else {\n target[key] = value;\n }\n };\n\n return setter;\n }\n }) as ResourceConfigProxy<T>;\n}\n"]}
package/index.d.ts CHANGED
@@ -7,6 +7,4 @@ export * from "./ApplicationHook";
7
7
  export * from "./ApplicationBuilder";
8
8
  export * from "./ApplicationBuilderGeneric";
9
9
  export * from "./ApplicationBuilderLegacy";
10
- export * from "./utils/getPulumiWorkDir";
11
- export * from "./utils/mergeAppHooks";
12
- export * from "./utils/tagResources";
10
+ export * from "./utils";
package/index.js CHANGED
@@ -121,41 +121,15 @@ Object.keys(_ApplicationBuilderLegacy).forEach(function (key) {
121
121
  });
122
122
  });
123
123
 
124
- var _getPulumiWorkDir = require("./utils/getPulumiWorkDir");
124
+ var _utils = require("./utils");
125
125
 
126
- Object.keys(_getPulumiWorkDir).forEach(function (key) {
126
+ Object.keys(_utils).forEach(function (key) {
127
127
  if (key === "default" || key === "__esModule") return;
128
- if (key in exports && exports[key] === _getPulumiWorkDir[key]) return;
128
+ if (key in exports && exports[key] === _utils[key]) return;
129
129
  Object.defineProperty(exports, key, {
130
130
  enumerable: true,
131
131
  get: function () {
132
- return _getPulumiWorkDir[key];
133
- }
134
- });
135
- });
136
-
137
- var _mergeAppHooks = require("./utils/mergeAppHooks");
138
-
139
- Object.keys(_mergeAppHooks).forEach(function (key) {
140
- if (key === "default" || key === "__esModule") return;
141
- if (key in exports && exports[key] === _mergeAppHooks[key]) return;
142
- Object.defineProperty(exports, key, {
143
- enumerable: true,
144
- get: function () {
145
- return _mergeAppHooks[key];
146
- }
147
- });
148
- });
149
-
150
- var _tagResources = require("./utils/tagResources");
151
-
152
- Object.keys(_tagResources).forEach(function (key) {
153
- if (key === "default" || key === "__esModule") return;
154
- if (key in exports && exports[key] === _tagResources[key]) return;
155
- Object.defineProperty(exports, key, {
156
- enumerable: true,
157
- get: function () {
158
- return _tagResources[key];
132
+ return _utils[key];
159
133
  }
160
134
  });
161
135
  });
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAEA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from \"./Pulumi\";\nexport * from \"./PulumiApp\";\nexport * from \"./PulumiAppModule\";\nexport * from \"./PulumiResource\";\nexport * from \"./ApplicationConfig\";\nexport * from \"./ApplicationHook\";\nexport * from \"./ApplicationBuilder\";\nexport * from \"./ApplicationBuilderGeneric\";\nexport * from \"./ApplicationBuilderLegacy\";\n\nexport * from \"./utils/getPulumiWorkDir\";\nexport * from \"./utils/mergeAppHooks\";\nexport * from \"./utils/tagResources\";\n"]}
1
+ {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAEA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from \"./Pulumi\";\nexport * from \"./PulumiApp\";\nexport * from \"./PulumiAppModule\";\nexport * from \"./PulumiResource\";\nexport * from \"./ApplicationConfig\";\nexport * from \"./ApplicationHook\";\nexport * from \"./ApplicationBuilder\";\nexport * from \"./ApplicationBuilderGeneric\";\nexport * from \"./ApplicationBuilderLegacy\";\n\nexport * from \"./utils\";\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/pulumi-sdk",
3
- "version": "5.26.0",
3
+ "version": "5.27.0",
4
4
  "main": "index.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -29,8 +29,8 @@
29
29
  "@babel/core": "^7.16.0",
30
30
  "@types/lodash": "^4.14.178",
31
31
  "@types/node": "^10.0.0",
32
- "@webiny/cli": "^5.26.0",
33
- "@webiny/project-utils": "^5.26.0",
32
+ "@webiny/cli": "^5.27.0",
33
+ "@webiny/project-utils": "^5.27.0",
34
34
  "rimraf": "^3.0.2",
35
35
  "typescript": "4.5.5"
36
36
  },
@@ -46,5 +46,5 @@
46
46
  "build": "yarn webiny run build",
47
47
  "watch": "yarn webiny run watch"
48
48
  },
49
- "gitHead": "4d66d3dbd7e6da045d23be4f2e247d1269aa2004"
49
+ "gitHead": "0f2b0b65639d2e1a79cf9189c8fe5cea2c32d302"
50
50
  }
@@ -0,0 +1,5 @@
1
+ /** Return a full stack name for a given environment and app variant. */
2
+ export declare function getStackName(args: {
3
+ env: string;
4
+ variant?: string;
5
+ }): string;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getStackName = getStackName;
7
+
8
+ /** Return a full stack name for a given environment and app variant. */
9
+ function getStackName(args) {
10
+ return args.variant ? `${args.env}.${args.variant}` : args.env;
11
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["getStackName.ts"],"names":["getStackName","args","variant","env"],"mappings":";;;;;;;AAAA;AACO,SAASA,YAAT,CAAsBC,IAAtB,EAA+D;AAClE,SAAOA,IAAI,CAACC,OAAL,GAAgB,GAAED,IAAI,CAACE,GAAI,IAAGF,IAAI,CAACC,OAAQ,EAA3C,GAA+CD,IAAI,CAACE,GAA3D;AACH","sourcesContent":["/** Return a full stack name for a given environment and app variant. */\nexport function getStackName(args: { env: string; variant?: string }) {\n return args.variant ? `${args.env}.${args.variant}` : args.env;\n}\n"]}
@@ -0,0 +1,5 @@
1
+ export * from "./getPulumiWorkDir";
2
+ export * from "./getStackName";
3
+ export * from "./mergeAppHooks";
4
+ export * from "./tagResources";
5
+ export * from "./stagedRollouts";
package/utils/index.js ADDED
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var _getPulumiWorkDir = require("./getPulumiWorkDir");
8
+
9
+ Object.keys(_getPulumiWorkDir).forEach(function (key) {
10
+ if (key === "default" || key === "__esModule") return;
11
+ if (key in exports && exports[key] === _getPulumiWorkDir[key]) return;
12
+ Object.defineProperty(exports, key, {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _getPulumiWorkDir[key];
16
+ }
17
+ });
18
+ });
19
+
20
+ var _getStackName = require("./getStackName");
21
+
22
+ Object.keys(_getStackName).forEach(function (key) {
23
+ if (key === "default" || key === "__esModule") return;
24
+ if (key in exports && exports[key] === _getStackName[key]) return;
25
+ Object.defineProperty(exports, key, {
26
+ enumerable: true,
27
+ get: function () {
28
+ return _getStackName[key];
29
+ }
30
+ });
31
+ });
32
+
33
+ var _mergeAppHooks = require("./mergeAppHooks");
34
+
35
+ Object.keys(_mergeAppHooks).forEach(function (key) {
36
+ if (key === "default" || key === "__esModule") return;
37
+ if (key in exports && exports[key] === _mergeAppHooks[key]) return;
38
+ Object.defineProperty(exports, key, {
39
+ enumerable: true,
40
+ get: function () {
41
+ return _mergeAppHooks[key];
42
+ }
43
+ });
44
+ });
45
+
46
+ var _tagResources = require("./tagResources");
47
+
48
+ Object.keys(_tagResources).forEach(function (key) {
49
+ if (key === "default" || key === "__esModule") return;
50
+ if (key in exports && exports[key] === _tagResources[key]) return;
51
+ Object.defineProperty(exports, key, {
52
+ enumerable: true,
53
+ get: function () {
54
+ return _tagResources[key];
55
+ }
56
+ });
57
+ });
58
+
59
+ var _stagedRollouts = require("./stagedRollouts");
60
+
61
+ Object.keys(_stagedRollouts).forEach(function (key) {
62
+ if (key === "default" || key === "__esModule") return;
63
+ if (key in exports && exports[key] === _stagedRollouts[key]) return;
64
+ Object.defineProperty(exports, key, {
65
+ enumerable: true,
66
+ get: function () {
67
+ return _stagedRollouts[key];
68
+ }
69
+ });
70
+ });
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from \"./getPulumiWorkDir\";\nexport * from \"./getStackName\";\nexport * from \"./mergeAppHooks\";\nexport * from \"./tagResources\";\nexport * from \"./stagedRollouts\";\n"]}
@@ -0,0 +1,15 @@
1
+ export declare type GatewayConfig = Record<string, {
2
+ domain: string;
3
+ weight: number;
4
+ }>;
5
+ export interface GatewayConfigParams {
6
+ cwd: string;
7
+ app: string;
8
+ env: string;
9
+ }
10
+ export interface GatewayConfigUpdateParams extends GatewayConfigParams {
11
+ variant: string;
12
+ domain: string;
13
+ }
14
+ export declare function updateGatewayConfig(params: GatewayConfigUpdateParams): Promise<void>;
15
+ export declare function loadGatewayConfig(params: GatewayConfigParams): Promise<GatewayConfig>;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.loadGatewayConfig = loadGatewayConfig;
9
+ exports.updateGatewayConfig = updateGatewayConfig;
10
+
11
+ var _path = _interopRequireDefault(require("path"));
12
+
13
+ var _fs = _interopRequireDefault(require("fs"));
14
+
15
+ async function updateGatewayConfig(params) {
16
+ const configPath = getGatewayConfigFilePath(params);
17
+ const config = await readGatewayConfigFile(configPath);
18
+
19
+ if (config[params.variant]) {
20
+ // Update existing config.
21
+ config[params.variant].domain = params.domain;
22
+ } else {
23
+ config[params.variant] = {
24
+ domain: params.domain,
25
+ // Every newly deployed variant has 0% of traffic.
26
+ weight: 0
27
+ };
28
+ }
29
+
30
+ await writeGatewayConfigFile(configPath, config);
31
+ }
32
+
33
+ async function loadGatewayConfig(params) {
34
+ const configPath = getGatewayConfigFilePath(params);
35
+ return readGatewayConfigFile(configPath);
36
+ }
37
+
38
+ function getGatewayConfigFilePath(params) {
39
+ return _path.default.join(params.cwd, `gateway.${params.app}.${params.env}.json`);
40
+ }
41
+
42
+ async function readGatewayConfigFile(filePath) {
43
+ if (!_fs.default.existsSync(filePath)) {
44
+ return {};
45
+ }
46
+
47
+ const configJson = await _fs.default.promises.readFile(filePath, {
48
+ encoding: "utf-8"
49
+ });
50
+ return JSON.parse(configJson) || {};
51
+ }
52
+
53
+ async function writeGatewayConfigFile(filePath, config) {
54
+ const configJson = JSON.stringify(config, null, 4);
55
+ await _fs.default.promises.writeFile(filePath, configJson, {
56
+ encoding: "utf-8"
57
+ });
58
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["stagedRollouts.ts"],"names":["updateGatewayConfig","params","configPath","getGatewayConfigFilePath","config","readGatewayConfigFile","variant","domain","weight","writeGatewayConfigFile","loadGatewayConfig","path","join","cwd","app","env","filePath","fs","existsSync","configJson","promises","readFile","encoding","JSON","parse","stringify","writeFile"],"mappings":";;;;;;;;;;AAAA;;AACA;;AAqBO,eAAeA,mBAAf,CAAmCC,MAAnC,EAAsE;AACzE,QAAMC,UAAU,GAAGC,wBAAwB,CAACF,MAAD,CAA3C;AACA,QAAMG,MAAM,GAAG,MAAMC,qBAAqB,CAACH,UAAD,CAA1C;;AAEA,MAAIE,MAAM,CAACH,MAAM,CAACK,OA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,EAAE;AAAZ,GAA5C,CAAN;AACH","sourcesContent":["import path from \"path\";\nimport fs from \"fs\";\n\nexport type GatewayConfig = Record<\n string,\n {\n domain: string;\n weight: number;\n }\n>;\n\nexport interface GatewayConfigParams {\n cwd: string;\n app: string;\n env: string;\n}\n\nexport interface GatewayConfigUpdateParams extends GatewayConfigParams {\n variant: string;\n domain: string;\n}\n\nexport async function updateGatewayConfig(params: GatewayConfigUpdateParams) {\n const configPath = getGatewayConfigFilePath(params);\n const config = await readGatewayConfigFile(configPath);\n\n if (config[params.variant]) {\n // Update existing config.\n config[params.variant].domain = params.domain;\n } else {\n config[params.variant] = {\n domain: params.domain,\n // Every newly deployed variant has 0% of traffic.\n weight: 0\n };\n }\n\n await writeGatewayConfigFile(configPath, config);\n}\n\nexport async function loadGatewayConfig(params: GatewayConfigParams) {\n const configPath = getGatewayConfigFilePath(params);\n return readGatewayConfigFile(configPath);\n}\n\nfunction getGatewayConfigFilePath(params: GatewayConfigParams) {\n return path.join(params.cwd, `gateway.${params.app}.${params.env}.json`);\n}\n\nasync function readGatewayConfigFile(filePath: string): Promise<GatewayConfig> {\n if (!fs.existsSync(filePath)) {\n return {};\n }\n\n const configJson = await fs.promises.readFile(filePath, { encoding: \"utf-8\" });\n return JSON.parse(configJson) || {};\n}\n\nasync function writeGatewayConfigFile(filePath: string, config: GatewayConfig) {\n const configJson = JSON.stringify(config, null, 4);\n await fs.promises.writeFile(filePath, configJson, { encoding: \"utf-8\" });\n}\n"]}