@webiny/project 6.0.0-rc.0 → 6.0.0-rc.2
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.
- package/abstractions/services/WatchedLambdaFunctionsService.d.ts +12 -7
- package/abstractions/services/WatchedLambdaFunctionsService.js.map +1 -1
- package/decorators/DeployAppClearWatchedLambdaFunctions.d.ts +3 -2
- package/decorators/DeployAppClearWatchedLambdaFunctions.js +11 -5
- package/decorators/DeployAppClearWatchedLambdaFunctions.js.map +1 -1
- package/decorators/DeployAppWithWatchedLambdaReplacement.d.ts +3 -2
- package/decorators/DeployAppWithWatchedLambdaReplacement.js +16 -7
- package/decorators/DeployAppWithWatchedLambdaReplacement.js.map +1 -1
- package/defineExtension/createExtensionReactComponent.js +2 -6
- package/defineExtension/createExtensionReactComponent.js.map +1 -1
- package/defineExtension/index.d.ts +0 -1
- package/defineExtension/index.js +0 -1
- package/defineExtension/index.js.map +1 -1
- package/exports/extensions.d.ts +1 -0
- package/exports/extensions.js +1 -0
- package/exports/extensions.js.map +1 -1
- package/extensions/AdminBuildParam.d.ts +11 -0
- package/extensions/AdminBuildParam.js +184 -0
- package/extensions/AdminBuildParam.js.map +1 -0
- package/extensions/AdminExtension.d.ts +11 -0
- package/extensions/AdminExtension.js +99 -0
- package/extensions/AdminExtension.js.map +1 -0
- package/extensions/ApiBuildParam.d.ts +11 -0
- package/extensions/ApiBuildParam.js +119 -0
- package/extensions/ApiBuildParam.js.map +1 -0
- package/extensions/ApiExtension.d.ts +11 -0
- package/{defineExtension/defineApiExtension.js → extensions/ApiExtension.js} +13 -15
- package/extensions/ApiExtension.js.map +1 -0
- package/extensions/FeatureFlags.d.ts +85 -0
- package/extensions/FeatureFlags.js +42 -0
- package/extensions/FeatureFlags.js.map +1 -0
- package/extensions/index.d.ts +102 -0
- package/extensions/index.js +12 -2
- package/extensions/index.js.map +1 -1
- package/features/Watch/Watch.js +1 -0
- package/features/Watch/Watch.js.map +1 -1
- package/features/Watch/replaceLambdaFunctions.d.ts +2 -1
- package/features/Watch/replaceLambdaFunctions.js +5 -1
- package/features/Watch/replaceLambdaFunctions.js.map +1 -1
- package/package.json +13 -13
- package/services/SetProjectIdService/SetProjectIdService.js +28 -18
- package/services/SetProjectIdService/SetProjectIdService.js.map +1 -1
- package/services/WatchedLambdaFunctionsService/WatchedLambdaFunctionsService.d.ts +4 -4
- package/services/WatchedLambdaFunctionsService/WatchedLambdaFunctionsService.js +26 -20
- package/services/WatchedLambdaFunctionsService/WatchedLambdaFunctionsService.js.map +1 -1
- package/defineExtension/defineApiExtension.d.ts +0 -17
- package/defineExtension/defineApiExtension.js.map +0 -1
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
import { type AppName } from "../../abstractions/types.js";
|
|
2
|
+
export interface IWatchedLambdaFunctionsServiceParams {
|
|
3
|
+
name: AppName;
|
|
4
|
+
deploymentId?: string;
|
|
5
|
+
}
|
|
2
6
|
export interface IWatchedLambdaFunctionsService {
|
|
3
7
|
/**
|
|
4
|
-
* Mark Lambda functions as needing replacement on next deployment
|
|
8
|
+
* Mark Lambda functions as needing replacement on next deployment.
|
|
5
9
|
*/
|
|
6
|
-
markDirty(
|
|
10
|
+
markDirty(params: IWatchedLambdaFunctionsServiceParams, functionUrns: string[]): void;
|
|
7
11
|
/**
|
|
8
|
-
* Get list of Lambda function URNs that need replacement for an app
|
|
12
|
+
* Get list of Lambda function URNs that need replacement for an app.
|
|
9
13
|
*/
|
|
10
|
-
getDirty(
|
|
14
|
+
getDirty(params: IWatchedLambdaFunctionsServiceParams): string[];
|
|
11
15
|
/**
|
|
12
|
-
* Clear Lambda functions that need replacement for an app
|
|
16
|
+
* Clear Lambda functions that need replacement for an app.
|
|
13
17
|
*/
|
|
14
|
-
clearDirty(
|
|
18
|
+
clearDirty(params: IWatchedLambdaFunctionsServiceParams): void;
|
|
15
19
|
/**
|
|
16
|
-
* Clear all Lambda functions that need replacement across all apps
|
|
20
|
+
* Clear all Lambda functions that need replacement across all apps.
|
|
17
21
|
*/
|
|
18
22
|
clearAll(): void;
|
|
19
23
|
}
|
|
20
24
|
export declare const WatchedLambdaFunctionsService: import("@webiny/di").Abstraction<IWatchedLambdaFunctionsService>;
|
|
21
25
|
export declare namespace WatchedLambdaFunctionsService {
|
|
22
26
|
type Interface = IWatchedLambdaFunctionsService;
|
|
27
|
+
type Params = IWatchedLambdaFunctionsServiceParams;
|
|
23
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createAbstraction","WatchedLambdaFunctionsService"],"sources":["WatchedLambdaFunctionsService.ts"],"sourcesContent":["import { createAbstraction } from \"~/abstractions/createAbstraction.js\";\nimport { type AppName } from \"~/abstractions/types.js\";\n\nexport interface IWatchedLambdaFunctionsService {\n /**\n * Mark Lambda functions as needing replacement on next deployment
|
|
1
|
+
{"version":3,"names":["createAbstraction","WatchedLambdaFunctionsService"],"sources":["WatchedLambdaFunctionsService.ts"],"sourcesContent":["import { createAbstraction } from \"~/abstractions/createAbstraction.js\";\nimport { type AppName } from \"~/abstractions/types.js\";\n\nexport interface IWatchedLambdaFunctionsServiceParams {\n name: AppName;\n deploymentId?: string;\n}\n\nexport interface IWatchedLambdaFunctionsService {\n /**\n * Mark Lambda functions as needing replacement on next deployment.\n */\n markDirty(params: IWatchedLambdaFunctionsServiceParams, functionUrns: string[]): void;\n\n /**\n * Get list of Lambda function URNs that need replacement for an app.\n */\n getDirty(params: IWatchedLambdaFunctionsServiceParams): string[];\n\n /**\n * Clear Lambda functions that need replacement for an app.\n */\n clearDirty(params: IWatchedLambdaFunctionsServiceParams): void;\n\n /**\n * Clear all Lambda functions that need replacement across all apps.\n */\n clearAll(): void;\n}\n\nexport const WatchedLambdaFunctionsService = createAbstraction<IWatchedLambdaFunctionsService>(\n \"WatchedLambdaFunctionsService\"\n);\n\nexport namespace WatchedLambdaFunctionsService {\n export type Interface = IWatchedLambdaFunctionsService;\n export type Params = IWatchedLambdaFunctionsServiceParams;\n}\n"],"mappings":"AAAA,SAASA,iBAAiB;AA8B1B,OAAO,MAAMC,6BAA6B,GAAGD,iBAAiB,CAC1D,+BACJ,CAAC","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DeployApp, GetApp, WatchedLambdaFunctionsService } from "../abstractions/index.js";
|
|
1
|
+
import { DeployApp, GetApp, PulumiGetStackOutputService, WatchedLambdaFunctionsService } from "../abstractions/index.js";
|
|
2
2
|
/**
|
|
3
3
|
* Decorator that clears watched Lambda functions after successful deployment.
|
|
4
4
|
* This ensures Lambda functions that were updated during watch sessions are replaced
|
|
@@ -6,9 +6,10 @@ import { DeployApp, GetApp, WatchedLambdaFunctionsService } from "../abstraction
|
|
|
6
6
|
*/
|
|
7
7
|
export declare class DeployAppClearWatchedLambdaFunctions implements DeployApp.Interface {
|
|
8
8
|
private getApp;
|
|
9
|
+
private pulumiGetStackOutputService;
|
|
9
10
|
private watchedLambdaFunctionsService;
|
|
10
11
|
private decoratee;
|
|
11
|
-
constructor(getApp: GetApp.Interface, watchedLambdaFunctionsService: WatchedLambdaFunctionsService.Interface, decoratee: DeployApp.Interface);
|
|
12
|
+
constructor(getApp: GetApp.Interface, pulumiGetStackOutputService: PulumiGetStackOutputService.Interface, watchedLambdaFunctionsService: WatchedLambdaFunctionsService.Interface, decoratee: DeployApp.Interface);
|
|
12
13
|
execute(params: DeployApp.Params): Promise<void>;
|
|
13
14
|
}
|
|
14
15
|
export declare const deployAppClearWatchedLambdaFunctions: typeof DeployAppClearWatchedLambdaFunctions & {
|
|
@@ -1,28 +1,34 @@
|
|
|
1
|
-
import { DeployApp, GetApp, WatchedLambdaFunctionsService } from "../abstractions/index.js";
|
|
2
|
-
|
|
1
|
+
import { DeployApp, GetApp, PulumiGetStackOutputService, WatchedLambdaFunctionsService } from "../abstractions/index.js";
|
|
3
2
|
/**
|
|
4
3
|
* Decorator that clears watched Lambda functions after successful deployment.
|
|
5
4
|
* This ensures Lambda functions that were updated during watch sessions are replaced
|
|
6
5
|
* only once, and not on subsequent deployments.
|
|
7
6
|
*/
|
|
8
7
|
export class DeployAppClearWatchedLambdaFunctions {
|
|
9
|
-
constructor(getApp, watchedLambdaFunctionsService, decoratee) {
|
|
8
|
+
constructor(getApp, pulumiGetStackOutputService, watchedLambdaFunctionsService, decoratee) {
|
|
10
9
|
this.getApp = getApp;
|
|
10
|
+
this.pulumiGetStackOutputService = pulumiGetStackOutputService;
|
|
11
11
|
this.watchedLambdaFunctionsService = watchedLambdaFunctionsService;
|
|
12
12
|
this.decoratee = decoratee;
|
|
13
13
|
}
|
|
14
14
|
async execute(params) {
|
|
15
|
+
const coreApp = this.getApp.execute("core");
|
|
16
|
+
const coreStackOutput = await this.pulumiGetStackOutputService.execute(coreApp);
|
|
17
|
+
const deploymentId = coreStackOutput?.deploymentId;
|
|
15
18
|
const result = await this.decoratee.execute(params);
|
|
16
19
|
|
|
17
20
|
// Clear Lambda URNs that needed replacement after successful deployment
|
|
18
21
|
const app = this.getApp.execute(params.app);
|
|
19
|
-
this.watchedLambdaFunctionsService.clearDirty(
|
|
22
|
+
this.watchedLambdaFunctionsService.clearDirty({
|
|
23
|
+
name: app.name,
|
|
24
|
+
deploymentId
|
|
25
|
+
});
|
|
20
26
|
return result;
|
|
21
27
|
}
|
|
22
28
|
}
|
|
23
29
|
export const deployAppClearWatchedLambdaFunctions = DeployApp.createDecorator({
|
|
24
30
|
decorator: DeployAppClearWatchedLambdaFunctions,
|
|
25
|
-
dependencies: [GetApp, WatchedLambdaFunctionsService]
|
|
31
|
+
dependencies: [GetApp, PulumiGetStackOutputService, WatchedLambdaFunctionsService]
|
|
26
32
|
});
|
|
27
33
|
|
|
28
34
|
//# sourceMappingURL=DeployAppClearWatchedLambdaFunctions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DeployApp","GetApp","WatchedLambdaFunctionsService","DeployAppClearWatchedLambdaFunctions","constructor","getApp","watchedLambdaFunctionsService","decoratee","execute","params","result","app","clearDirty","name","deployAppClearWatchedLambdaFunctions","createDecorator","decorator","dependencies"],"sources":["DeployAppClearWatchedLambdaFunctions.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"names":["DeployApp","GetApp","PulumiGetStackOutputService","WatchedLambdaFunctionsService","DeployAppClearWatchedLambdaFunctions","constructor","getApp","pulumiGetStackOutputService","watchedLambdaFunctionsService","decoratee","execute","params","coreApp","coreStackOutput","deploymentId","result","app","clearDirty","name","deployAppClearWatchedLambdaFunctions","createDecorator","decorator","dependencies"],"sources":["DeployAppClearWatchedLambdaFunctions.ts"],"sourcesContent":["import {\n DeployApp,\n GetApp,\n PulumiGetStackOutputService,\n WatchedLambdaFunctionsService\n} from \"~/abstractions/index.js\";\nimport { type ICoreStackOutput } from \"~/abstractions/features/GetAppStackOutput.js\";\n\n/**\n * Decorator that clears watched Lambda functions after successful deployment.\n * This ensures Lambda functions that were updated during watch sessions are replaced\n * only once, and not on subsequent deployments.\n */\nexport class DeployAppClearWatchedLambdaFunctions implements DeployApp.Interface {\n constructor(\n private getApp: GetApp.Interface,\n private pulumiGetStackOutputService: PulumiGetStackOutputService.Interface,\n private watchedLambdaFunctionsService: WatchedLambdaFunctionsService.Interface,\n private decoratee: DeployApp.Interface\n ) {}\n\n async execute(params: DeployApp.Params) {\n const coreApp = this.getApp.execute(\"core\");\n const coreStackOutput =\n await this.pulumiGetStackOutputService.execute<ICoreStackOutput>(coreApp);\n const deploymentId = coreStackOutput?.deploymentId;\n\n const result = await this.decoratee.execute(params);\n\n // Clear Lambda URNs that needed replacement after successful deployment\n const app = this.getApp.execute(params.app);\n this.watchedLambdaFunctionsService.clearDirty({ name: app.name, deploymentId });\n\n return result;\n }\n}\n\nexport const deployAppClearWatchedLambdaFunctions = DeployApp.createDecorator({\n decorator: DeployAppClearWatchedLambdaFunctions,\n dependencies: [GetApp, PulumiGetStackOutputService, WatchedLambdaFunctionsService]\n});\n"],"mappings":"AAAA,SACIA,SAAS,EACTC,MAAM,EACNC,2BAA2B,EAC3BC,6BAA6B;AAIjC;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,oCAAoC,CAAgC;EAC7EC,WAAWA,CACCC,MAAwB,EACxBC,2BAAkE,EAClEC,6BAAsE,EACtEC,SAA8B,EACxC;IAAA,KAJUH,MAAwB,GAAxBA,MAAwB;IAAA,KACxBC,2BAAkE,GAAlEA,2BAAkE;IAAA,KAClEC,6BAAsE,GAAtEA,6BAAsE;IAAA,KACtEC,SAA8B,GAA9BA,SAA8B;EACvC;EAEH,MAAMC,OAAOA,CAACC,MAAwB,EAAE;IACpC,MAAMC,OAAO,GAAG,IAAI,CAACN,MAAM,CAACI,OAAO,CAAC,MAAM,CAAC;IAC3C,MAAMG,eAAe,GACjB,MAAM,IAAI,CAACN,2BAA2B,CAACG,OAAO,CAAmBE,OAAO,CAAC;IAC7E,MAAME,YAAY,GAAGD,eAAe,EAAEC,YAAY;IAElD,MAAMC,MAAM,GAAG,MAAM,IAAI,CAACN,SAAS,CAACC,OAAO,CAACC,MAAM,CAAC;;IAEnD;IACA,MAAMK,GAAG,GAAG,IAAI,CAACV,MAAM,CAACI,OAAO,CAACC,MAAM,CAACK,GAAG,CAAC;IAC3C,IAAI,CAACR,6BAA6B,CAACS,UAAU,CAAC;MAAEC,IAAI,EAAEF,GAAG,CAACE,IAAI;MAAEJ;IAAa,CAAC,CAAC;IAE/E,OAAOC,MAAM;EACjB;AACJ;AAEA,OAAO,MAAMI,oCAAoC,GAAGnB,SAAS,CAACoB,eAAe,CAAC;EAC1EC,SAAS,EAAEjB,oCAAoC;EAC/CkB,YAAY,EAAE,CAACrB,MAAM,EAAEC,2BAA2B,EAAEC,6BAA6B;AACrF,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DeployApp, GetApp, WatchedLambdaFunctionsService } from "../abstractions/index.js";
|
|
1
|
+
import { DeployApp, GetApp, PulumiGetStackOutputService, WatchedLambdaFunctionsService } from "../abstractions/index.js";
|
|
2
2
|
/**
|
|
3
3
|
* Decorator that injects watched Lambda function URNs into Pulumi replace args.
|
|
4
4
|
* This ensures Lambda functions that were updated during watch sessions are
|
|
@@ -6,9 +6,10 @@ import { DeployApp, GetApp, WatchedLambdaFunctionsService } from "../abstraction
|
|
|
6
6
|
*/
|
|
7
7
|
export declare class DeployAppWithWatchedLambdaReplacement implements DeployApp.Interface {
|
|
8
8
|
private getApp;
|
|
9
|
+
private pulumiGetStackOutputService;
|
|
9
10
|
private watchedLambdaFunctionsService;
|
|
10
11
|
private decoratee;
|
|
11
|
-
constructor(getApp: GetApp.Interface, watchedLambdaFunctionsService: WatchedLambdaFunctionsService.Interface, decoratee: DeployApp.Interface);
|
|
12
|
+
constructor(getApp: GetApp.Interface, pulumiGetStackOutputService: PulumiGetStackOutputService.Interface, watchedLambdaFunctionsService: WatchedLambdaFunctionsService.Interface, decoratee: DeployApp.Interface);
|
|
12
13
|
execute(params: DeployApp.Params): Promise<void>;
|
|
13
14
|
}
|
|
14
15
|
export declare const deployAppWithWatchedLambdaReplacement: typeof DeployAppWithWatchedLambdaReplacement & {
|
|
@@ -1,26 +1,35 @@
|
|
|
1
|
-
import { DeployApp, GetApp, WatchedLambdaFunctionsService } from "../abstractions/index.js";
|
|
2
|
-
|
|
1
|
+
import { DeployApp, GetApp, PulumiGetStackOutputService, WatchedLambdaFunctionsService } from "../abstractions/index.js";
|
|
3
2
|
/**
|
|
4
3
|
* Decorator that injects watched Lambda function URNs into Pulumi replace args.
|
|
5
4
|
* This ensures Lambda functions that were updated during watch sessions are
|
|
6
5
|
* replaced during deployment.
|
|
7
6
|
*/
|
|
8
7
|
export class DeployAppWithWatchedLambdaReplacement {
|
|
9
|
-
constructor(getApp, watchedLambdaFunctionsService, decoratee) {
|
|
8
|
+
constructor(getApp, pulumiGetStackOutputService, watchedLambdaFunctionsService, decoratee) {
|
|
10
9
|
this.getApp = getApp;
|
|
10
|
+
this.pulumiGetStackOutputService = pulumiGetStackOutputService;
|
|
11
11
|
this.watchedLambdaFunctionsService = watchedLambdaFunctionsService;
|
|
12
12
|
this.decoratee = decoratee;
|
|
13
13
|
}
|
|
14
14
|
async execute(params) {
|
|
15
|
+
const coreApp = this.getApp.execute("core");
|
|
16
|
+
const coreStackOutput = await this.pulumiGetStackOutputService.execute(coreApp);
|
|
17
|
+
const deploymentId = coreStackOutput?.deploymentId;
|
|
15
18
|
const app = this.getApp.execute(params.app);
|
|
16
|
-
const lambdaUrnsToReplace = this.watchedLambdaFunctionsService.getDirty(
|
|
19
|
+
const lambdaUrnsToReplace = this.watchedLambdaFunctionsService.getDirty({
|
|
20
|
+
name: app.name,
|
|
21
|
+
deploymentId
|
|
22
|
+
});
|
|
23
|
+
if (lambdaUrnsToReplace.length === 0) {
|
|
24
|
+
return this.decoratee.execute(params);
|
|
25
|
+
}
|
|
17
26
|
|
|
18
|
-
// Inject replace URNs into pulumiArgs
|
|
27
|
+
// Inject replace URNs into pulumiArgs.
|
|
19
28
|
const enhancedParams = {
|
|
20
29
|
...params,
|
|
21
30
|
pulumiArgs: {
|
|
22
31
|
...params.pulumiArgs,
|
|
23
|
-
replace: lambdaUrnsToReplace
|
|
32
|
+
replace: lambdaUrnsToReplace
|
|
24
33
|
}
|
|
25
34
|
};
|
|
26
35
|
return this.decoratee.execute(enhancedParams);
|
|
@@ -28,7 +37,7 @@ export class DeployAppWithWatchedLambdaReplacement {
|
|
|
28
37
|
}
|
|
29
38
|
export const deployAppWithWatchedLambdaReplacement = DeployApp.createDecorator({
|
|
30
39
|
decorator: DeployAppWithWatchedLambdaReplacement,
|
|
31
|
-
dependencies: [GetApp, WatchedLambdaFunctionsService]
|
|
40
|
+
dependencies: [GetApp, PulumiGetStackOutputService, WatchedLambdaFunctionsService]
|
|
32
41
|
});
|
|
33
42
|
|
|
34
43
|
//# sourceMappingURL=DeployAppWithWatchedLambdaReplacement.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DeployApp","GetApp","WatchedLambdaFunctionsService","DeployAppWithWatchedLambdaReplacement","constructor","getApp","watchedLambdaFunctionsService","decoratee","execute","params","app","lambdaUrnsToReplace","getDirty","name","enhancedParams","pulumiArgs","replace","
|
|
1
|
+
{"version":3,"names":["DeployApp","GetApp","PulumiGetStackOutputService","WatchedLambdaFunctionsService","DeployAppWithWatchedLambdaReplacement","constructor","getApp","pulumiGetStackOutputService","watchedLambdaFunctionsService","decoratee","execute","params","coreApp","coreStackOutput","deploymentId","app","lambdaUrnsToReplace","getDirty","name","length","enhancedParams","pulumiArgs","replace","deployAppWithWatchedLambdaReplacement","createDecorator","decorator","dependencies"],"sources":["DeployAppWithWatchedLambdaReplacement.ts"],"sourcesContent":["import {\n DeployApp,\n GetApp,\n PulumiGetStackOutputService,\n WatchedLambdaFunctionsService\n} from \"~/abstractions/index.js\";\nimport { type ICoreStackOutput } from \"~/abstractions/features/GetAppStackOutput.js\";\n\n/**\n * Decorator that injects watched Lambda function URNs into Pulumi replace args.\n * This ensures Lambda functions that were updated during watch sessions are\n * replaced during deployment.\n */\nexport class DeployAppWithWatchedLambdaReplacement implements DeployApp.Interface {\n constructor(\n private getApp: GetApp.Interface,\n private pulumiGetStackOutputService: PulumiGetStackOutputService.Interface,\n private watchedLambdaFunctionsService: WatchedLambdaFunctionsService.Interface,\n private decoratee: DeployApp.Interface\n ) {}\n\n async execute(params: DeployApp.Params) {\n const coreApp = this.getApp.execute(\"core\");\n const coreStackOutput =\n await this.pulumiGetStackOutputService.execute<ICoreStackOutput>(coreApp);\n const deploymentId = coreStackOutput?.deploymentId;\n\n const app = this.getApp.execute(params.app);\n const lambdaUrnsToReplace = this.watchedLambdaFunctionsService.getDirty({\n name: app.name,\n deploymentId\n });\n\n if (lambdaUrnsToReplace.length === 0) {\n return this.decoratee.execute(params);\n }\n\n // Inject replace URNs into pulumiArgs.\n const enhancedParams = {\n ...params,\n pulumiArgs: {\n ...params.pulumiArgs,\n replace: lambdaUrnsToReplace\n }\n };\n\n return this.decoratee.execute(enhancedParams);\n }\n}\n\nexport const deployAppWithWatchedLambdaReplacement = DeployApp.createDecorator({\n decorator: DeployAppWithWatchedLambdaReplacement,\n dependencies: [GetApp, PulumiGetStackOutputService, WatchedLambdaFunctionsService]\n});\n"],"mappings":"AAAA,SACIA,SAAS,EACTC,MAAM,EACNC,2BAA2B,EAC3BC,6BAA6B;AAIjC;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,qCAAqC,CAAgC;EAC9EC,WAAWA,CACCC,MAAwB,EACxBC,2BAAkE,EAClEC,6BAAsE,EACtEC,SAA8B,EACxC;IAAA,KAJUH,MAAwB,GAAxBA,MAAwB;IAAA,KACxBC,2BAAkE,GAAlEA,2BAAkE;IAAA,KAClEC,6BAAsE,GAAtEA,6BAAsE;IAAA,KACtEC,SAA8B,GAA9BA,SAA8B;EACvC;EAEH,MAAMC,OAAOA,CAACC,MAAwB,EAAE;IACpC,MAAMC,OAAO,GAAG,IAAI,CAACN,MAAM,CAACI,OAAO,CAAC,MAAM,CAAC;IAC3C,MAAMG,eAAe,GACjB,MAAM,IAAI,CAACN,2BAA2B,CAACG,OAAO,CAAmBE,OAAO,CAAC;IAC7E,MAAME,YAAY,GAAGD,eAAe,EAAEC,YAAY;IAElD,MAAMC,GAAG,GAAG,IAAI,CAACT,MAAM,CAACI,OAAO,CAACC,MAAM,CAACI,GAAG,CAAC;IAC3C,MAAMC,mBAAmB,GAAG,IAAI,CAACR,6BAA6B,CAACS,QAAQ,CAAC;MACpEC,IAAI,EAAEH,GAAG,CAACG,IAAI;MACdJ;IACJ,CAAC,CAAC;IAEF,IAAIE,mBAAmB,CAACG,MAAM,KAAK,CAAC,EAAE;MAClC,OAAO,IAAI,CAACV,SAAS,CAACC,OAAO,CAACC,MAAM,CAAC;IACzC;;IAEA;IACA,MAAMS,cAAc,GAAG;MACnB,GAAGT,MAAM;MACTU,UAAU,EAAE;QACR,GAAGV,MAAM,CAACU,UAAU;QACpBC,OAAO,EAAEN;MACb;IACJ,CAAC;IAED,OAAO,IAAI,CAACP,SAAS,CAACC,OAAO,CAACU,cAAc,CAAC;EACjD;AACJ;AAEA,OAAO,MAAMG,qCAAqC,GAAGvB,SAAS,CAACwB,eAAe,CAAC;EAC3EC,SAAS,EAAErB,qCAAqC;EAChDsB,YAAY,EAAE,CAACzB,MAAM,EAAEC,2BAA2B,EAAEC,6BAA6B;AACrF,CAAC,CAAC","ignoreList":[]}
|
|
@@ -13,10 +13,6 @@ const KeyValues = props => {
|
|
|
13
13
|
};
|
|
14
14
|
export function createExtensionReactComponent(extensionParams) {
|
|
15
15
|
const ExtensionReactComponent = props => {
|
|
16
|
-
// If custom render function is provided, use it.
|
|
17
|
-
if (extensionParams.render) {
|
|
18
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, extensionParams.render(props));
|
|
19
|
-
}
|
|
20
16
|
const {
|
|
21
17
|
name,
|
|
22
18
|
remove,
|
|
@@ -39,14 +35,14 @@ export function createExtensionReactComponent(extensionParams) {
|
|
|
39
35
|
|
|
40
36
|
// @ts-expect-error move KeyValues back inside the Property component to avoid this error
|
|
41
37
|
const KeyValuesComponent = parentProps => /*#__PURE__*/React.createElement(KeyValues, Object.assign({}, parentProps, keyValues));
|
|
42
|
-
return /*#__PURE__*/React.createElement(Property, {
|
|
38
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Property, {
|
|
43
39
|
id: propertyId,
|
|
44
40
|
name: propertyName,
|
|
45
41
|
array: extensionParams.multiple,
|
|
46
42
|
remove: remove,
|
|
47
43
|
before: placeBefore,
|
|
48
44
|
after: placeAfter
|
|
49
|
-
}, /*#__PURE__*/React.createElement(KeyValuesComponent, null));
|
|
45
|
+
}, /*#__PURE__*/React.createElement(KeyValuesComponent, null)), extensionParams.render && extensionParams.render(props));
|
|
50
46
|
};
|
|
51
47
|
ExtensionReactComponent.displayName = `ExtensionReactComponent(${extensionParams.type})`;
|
|
52
48
|
return ExtensionReactComponent;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useMemo","Property","useIdGenerator","KeyValues","props","getId","Object","entries","map","key","value","createElement","name","id","createExtensionReactComponent","extensionParams","ExtensionReactComponent","
|
|
1
|
+
{"version":3,"names":["React","useMemo","Property","useIdGenerator","KeyValues","props","getId","Object","entries","map","key","value","createElement","name","id","createExtensionReactComponent","extensionParams","ExtensionReactComponent","remove","before","after","keyValues","type","propertyId","multiple","undefined","propertyName","placeAfter","placeBefore","KeyValuesComponent","parentProps","assign","Fragment","array","render","displayName"],"sources":["createExtensionReactComponent.tsx"],"sourcesContent":["import React, { useMemo } from \"react\";\nimport { Property, useIdGenerator } from \"@webiny/react-properties\";\nimport { type DefineExtensionParams } from \"./types.js\";\nimport { type z } from \"zod\";\n\nconst KeyValues = (props: Record<string, any>) => {\n const getId = useIdGenerator(\"\");\n return Object.entries(props).map(([key, value]) => {\n return <Property key={key} name={key} id={getId(key)} value={value} />;\n });\n};\n\ntype ExtensionReactComponentProps<TParamsSchema extends z.ZodTypeAny> = z.infer<TParamsSchema> & {\n remove?: boolean;\n before?: string;\n after?: string;\n name?: string;\n};\n\nexport function createExtensionReactComponent<TParamsSchema extends z.ZodTypeAny>(\n extensionParams: DefineExtensionParams<TParamsSchema>\n) {\n const ExtensionReactComponent: React.FC<\n ExtensionReactComponentProps<TParamsSchema>\n > = props => {\n const { name, remove, before, after, ...keyValues } = props;\n\n const getId = useIdGenerator(extensionParams.type);\n\n // By passing undefined, we're letting RP generate a unique ID for us.\n const propertyId = useMemo(() => {\n if (extensionParams.multiple) {\n return name ? getId(name) : undefined;\n }\n\n return getId(extensionParams.type);\n }, [name, extensionParams.multiple, getId]);\n\n const propertyName = name || extensionParams.type;\n\n const placeAfter = after !== undefined ? getId(after) : undefined;\n const placeBefore = before !== undefined ? getId(before) : undefined;\n\n // @ts-expect-error move KeyValues back inside the Property component to avoid this error\n const KeyValuesComponent = parentProps => <KeyValues {...parentProps} {...keyValues} />;\n\n return (\n <>\n <Property\n id={propertyId}\n name={propertyName}\n array={extensionParams.multiple}\n remove={remove}\n before={placeBefore}\n after={placeAfter}\n >\n <KeyValuesComponent />\n </Property>\n {extensionParams.render && extensionParams.render(props)}\n </>\n );\n };\n\n ExtensionReactComponent.displayName = `ExtensionReactComponent(${extensionParams.type})`;\n return ExtensionReactComponent;\n}\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,OAAO,QAAQ,OAAO;AACtC,SAASC,QAAQ,EAAEC,cAAc,QAAQ,0BAA0B;AAInE,MAAMC,SAAS,GAAIC,KAA0B,IAAK;EAC9C,MAAMC,KAAK,GAAGH,cAAc,CAAC,EAAE,CAAC;EAChC,OAAOI,MAAM,CAACC,OAAO,CAACH,KAAK,CAAC,CAACI,GAAG,CAAC,CAAC,CAACC,GAAG,EAAEC,KAAK,CAAC,KAAK;IAC/C,oBAAOX,KAAA,CAAAY,aAAA,CAACV,QAAQ;MAACQ,GAAG,EAAEA,GAAI;MAACG,IAAI,EAAEH,GAAI;MAACI,EAAE,EAAER,KAAK,CAACI,GAAG,CAAE;MAACC,KAAK,EAAEA;IAAM,CAAE,CAAC;EAC1E,CAAC,CAAC;AACN,CAAC;AASD,OAAO,SAASI,6BAA6BA,CACzCC,eAAqD,EACvD;EACE,MAAMC,uBAEL,GAAGZ,KAAK,IAAI;IACT,MAAM;MAAEQ,IAAI;MAAEK,MAAM;MAAEC,MAAM;MAAEC,KAAK;MAAE,GAAGC;IAAU,CAAC,GAAGhB,KAAK;IAE3D,MAAMC,KAAK,GAAGH,cAAc,CAACa,eAAe,CAACM,IAAI,CAAC;;IAElD;IACA,MAAMC,UAAU,GAAGtB,OAAO,CAAC,MAAM;MAC7B,IAAIe,eAAe,CAACQ,QAAQ,EAAE;QAC1B,OAAOX,IAAI,GAAGP,KAAK,CAACO,IAAI,CAAC,GAAGY,SAAS;MACzC;MAEA,OAAOnB,KAAK,CAACU,eAAe,CAACM,IAAI,CAAC;IACtC,CAAC,EAAE,CAACT,IAAI,EAAEG,eAAe,CAACQ,QAAQ,EAAElB,KAAK,CAAC,CAAC;IAE3C,MAAMoB,YAAY,GAAGb,IAAI,IAAIG,eAAe,CAACM,IAAI;IAEjD,MAAMK,UAAU,GAAGP,KAAK,KAAKK,SAAS,GAAGnB,KAAK,CAACc,KAAK,CAAC,GAAGK,SAAS;IACjE,MAAMG,WAAW,GAAGT,MAAM,KAAKM,SAAS,GAAGnB,KAAK,CAACa,MAAM,CAAC,GAAGM,SAAS;;IAEpE;IACA,MAAMI,kBAAkB,GAAGC,WAAW,iBAAI9B,KAAA,CAAAY,aAAA,CAACR,SAAS,EAAAG,MAAA,CAAAwB,MAAA,KAAKD,WAAW,EAAMT,SAAS,CAAG,CAAC;IAEvF,oBACIrB,KAAA,CAAAY,aAAA,CAAAZ,KAAA,CAAAgC,QAAA,qBACIhC,KAAA,CAAAY,aAAA,CAACV,QAAQ;MACLY,EAAE,EAAES,UAAW;MACfV,IAAI,EAAEa,YAAa;MACnBO,KAAK,EAAEjB,eAAe,CAACQ,QAAS;MAChCN,MAAM,EAAEA,MAAO;MACfC,MAAM,EAAES,WAAY;MACpBR,KAAK,EAAEO;IAAW,gBAElB3B,KAAA,CAAAY,aAAA,CAACiB,kBAAkB,MAAE,CACf,CAAC,EACVb,eAAe,CAACkB,MAAM,IAAIlB,eAAe,CAACkB,MAAM,CAAC7B,KAAK,CACzD,CAAC;EAEX,CAAC;EAEDY,uBAAuB,CAACkB,WAAW,GAAG,2BAA2BnB,eAAe,CAACM,IAAI,GAAG;EACxF,OAAOL,uBAAuB;AAClC","ignoreList":[]}
|
package/defineExtension/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./defineExtension.js\";\nexport * from \"./
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./defineExtension.js\";\nexport * from \"./models/index.js\";\nexport * from \"./zodTypes/zodSrcPath.js\";\n"],"mappings":"AAAA;AACA;AACA","ignoreList":[]}
|
package/exports/extensions.d.ts
CHANGED
package/exports/extensions.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["EnvVar"],"sources":["extensions.ts"],"sourcesContent":["export { EnvVar } from \"~/extensions/EnvVar.js\";\n"],"mappings":"AAAA,SAASA,MAAM","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["EnvVar","FeatureFlags"],"sources":["extensions.ts"],"sourcesContent":["export { EnvVar } from \"~/extensions/EnvVar.js\";\nexport { FeatureFlags } from \"~/extensions/FeatureFlags.js\";\n"],"mappings":"AAAA,SAASA,MAAM;AACf,SAASC,YAAY","ignoreList":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const AdminBuildParam: import("~/defineExtension/index.js").ExtensionComponent<z.ZodObject<{
|
|
3
|
+
paramName: z.ZodString;
|
|
4
|
+
value: z.ZodUnion<[z.ZodString, z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodArray<z.ZodAny, "many">, z.ZodNumber, z.ZodBoolean]>;
|
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
value: string | number | boolean | any[] | Record<string, any>;
|
|
7
|
+
paramName: string;
|
|
8
|
+
}, {
|
|
9
|
+
value: string | number | boolean | any[] | Record<string, any>;
|
|
10
|
+
paramName: string;
|
|
11
|
+
}>>;
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { defineExtension } from "../defineExtension/index.js";
|
|
3
|
+
import crypto from "crypto";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import fs from "fs";
|
|
6
|
+
import { Node, Project } from "ts-morph";
|
|
7
|
+
async function generateBuildParamsFeature(buildParamsDir, ctx) {
|
|
8
|
+
const featureFilePath = path.join(buildParamsDir, "feature.ts");
|
|
9
|
+
|
|
10
|
+
// Get all BuildParam_*.ts files.
|
|
11
|
+
const files = fs.readdirSync(buildParamsDir).filter(f => f.startsWith("BuildParam_") && f.endsWith(".ts") && f !== "feature.ts");
|
|
12
|
+
|
|
13
|
+
// Generate imports and registrations.
|
|
14
|
+
const imports = files.map(file => {
|
|
15
|
+
const className = path.parse(file).name;
|
|
16
|
+
return `import ${className} from "./${className}.js";`;
|
|
17
|
+
}).join("\n");
|
|
18
|
+
const registrations = files.map(file => {
|
|
19
|
+
const className = path.parse(file).name;
|
|
20
|
+
return ` container.register(${className});`;
|
|
21
|
+
}).join("\n");
|
|
22
|
+
const featureContent = `import { createFeature } from "@webiny/feature/admin";
|
|
23
|
+
import { Container } from "@webiny/di";
|
|
24
|
+
${imports}
|
|
25
|
+
|
|
26
|
+
export const BuildParamsInternalFeature = createFeature({
|
|
27
|
+
name: "BuildParamsInternal",
|
|
28
|
+
register(container: Container) {
|
|
29
|
+
${registrations}
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
`;
|
|
33
|
+
fs.writeFileSync(featureFilePath, featureContent, "utf8");
|
|
34
|
+
|
|
35
|
+
// Now we need to update Extensions.tsx to use RegisterFeature with this feature.
|
|
36
|
+
await updateExtensionsTsx(ctx);
|
|
37
|
+
}
|
|
38
|
+
async function updateExtensionsTsx(ctx) {
|
|
39
|
+
const extensionsTsxFilePath = ctx.project.paths.workspaceFolder.join("apps", "admin", "src", "Extensions.tsx").toString();
|
|
40
|
+
const project = new Project();
|
|
41
|
+
project.addSourceFileAtPath(extensionsTsxFilePath);
|
|
42
|
+
const source = project.getSourceFileOrThrow(extensionsTsxFilePath);
|
|
43
|
+
|
|
44
|
+
// Check if we already have the imports.
|
|
45
|
+
const buildParamsFeatureImport = "./buildParams/feature.js";
|
|
46
|
+
const existingFeatureImport = source.getImportDeclaration(buildParamsFeatureImport);
|
|
47
|
+
if (!existingFeatureImport) {
|
|
48
|
+
let index = 1;
|
|
49
|
+
const importDeclarations = source.getImportDeclarations();
|
|
50
|
+
if (importDeclarations.length) {
|
|
51
|
+
const last = importDeclarations[importDeclarations.length - 1];
|
|
52
|
+
index = last.getChildIndex() + 1;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Add import for BuildParamsInternalFeature.
|
|
56
|
+
source.insertImportDeclaration(index, {
|
|
57
|
+
namedImports: ["BuildParamsInternalFeature"],
|
|
58
|
+
moduleSpecifier: buildParamsFeatureImport
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// Add import for BuildParamsFeature.
|
|
62
|
+
const buildParamsFeatureImportPath = "@webiny/app-admin";
|
|
63
|
+
const existingBuildParamsImport = source.getImportDeclaration(buildParamsFeatureImportPath);
|
|
64
|
+
if (!existingBuildParamsImport) {
|
|
65
|
+
source.insertImportDeclaration(index, {
|
|
66
|
+
namedImports: ["BuildParamsFeature"],
|
|
67
|
+
moduleSpecifier: buildParamsFeatureImportPath
|
|
68
|
+
});
|
|
69
|
+
} else {
|
|
70
|
+
// Add to existing import if BuildParamsFeature not already there.
|
|
71
|
+
const namedImports = existingBuildParamsImport.getNamedImports();
|
|
72
|
+
const hasBuildParamsFeature = namedImports.some(ni => ni.getName() === "BuildParamsFeature");
|
|
73
|
+
if (!hasBuildParamsFeature) {
|
|
74
|
+
existingBuildParamsImport.addNamedImport("BuildParamsFeature");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Add import for RegisterFeature if not present.
|
|
79
|
+
const registerFeatureImportPath = "@webiny/app-admin";
|
|
80
|
+
const existingRegisterFeatureImport = source.getImportDeclaration(registerFeatureImportPath);
|
|
81
|
+
if (existingRegisterFeatureImport) {
|
|
82
|
+
const namedImports = existingRegisterFeatureImport.getNamedImports();
|
|
83
|
+
const hasRegisterFeature = namedImports.some(ni => ni.getName() === "RegisterFeature");
|
|
84
|
+
if (!hasRegisterFeature) {
|
|
85
|
+
existingRegisterFeatureImport.addNamedImport("RegisterFeature");
|
|
86
|
+
}
|
|
87
|
+
} else {
|
|
88
|
+
source.insertImportDeclaration(index, {
|
|
89
|
+
namedImports: ["RegisterFeature"],
|
|
90
|
+
moduleSpecifier: registerFeatureImportPath
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Now add <RegisterFeature> components to the Extensions component.
|
|
96
|
+
const extensionsIdentifier = source.getFirstDescendant(node => {
|
|
97
|
+
if (!Node.isIdentifier(node)) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
return node.getText() === "Extensions";
|
|
101
|
+
});
|
|
102
|
+
if (!extensionsIdentifier) {
|
|
103
|
+
throw new Error(`Could not find the "Extensions" React component in "${extensionsTsxFilePath}".`);
|
|
104
|
+
}
|
|
105
|
+
const extensionsArrowFn = extensionsIdentifier.getNextSibling(node => Node.isArrowFunction(node));
|
|
106
|
+
if (!extensionsArrowFn) {
|
|
107
|
+
throw new Error(`Could not find the "Extensions" React component arrow function.`);
|
|
108
|
+
}
|
|
109
|
+
const extensionsArrowFnFragment = extensionsArrowFn.getFirstDescendant(node => {
|
|
110
|
+
return Node.isJsxFragment(node);
|
|
111
|
+
});
|
|
112
|
+
if (!extensionsArrowFnFragment) {
|
|
113
|
+
throw new Error(`Could not find JSX fragment in Extensions component.`);
|
|
114
|
+
}
|
|
115
|
+
const currentContent = extensionsArrowFnFragment.getFullText().replace("<>", "").replace("</>", "").trim();
|
|
116
|
+
|
|
117
|
+
// Check if we already have the RegisterFeature components.
|
|
118
|
+
if (!currentContent.includes("BuildParamsFeature")) {
|
|
119
|
+
const newContent = `<><RegisterFeature feature={BuildParamsFeature} /><RegisterFeature feature={BuildParamsInternalFeature} />${currentContent}</>`;
|
|
120
|
+
extensionsArrowFnFragment.replaceWithText(newContent);
|
|
121
|
+
}
|
|
122
|
+
await source.save();
|
|
123
|
+
}
|
|
124
|
+
export const AdminBuildParam = defineExtension({
|
|
125
|
+
type: "Admin/BuildParam",
|
|
126
|
+
tags: {
|
|
127
|
+
runtimeContext: "app-build",
|
|
128
|
+
appName: "admin"
|
|
129
|
+
},
|
|
130
|
+
description: "Add build-time parameter to Admin app.",
|
|
131
|
+
multiple: true,
|
|
132
|
+
paramsSchema: () => {
|
|
133
|
+
return z.object({
|
|
134
|
+
paramName: z.string(),
|
|
135
|
+
value: z.union([z.string(), z.record(z.any()), z.array(z.any()), z.number(), z.boolean()])
|
|
136
|
+
});
|
|
137
|
+
},
|
|
138
|
+
async build(params, ctx) {
|
|
139
|
+
const buildParamsDir = ctx.project.paths.workspaceFolder.join("apps", "admin", "src", "buildParams").toString();
|
|
140
|
+
const {
|
|
141
|
+
paramName,
|
|
142
|
+
value
|
|
143
|
+
} = params;
|
|
144
|
+
|
|
145
|
+
// Serialize value to a TypeScript literal.
|
|
146
|
+
const valueStr = JSON.stringify(value, null, 4);
|
|
147
|
+
|
|
148
|
+
// Generate a unique class name based on the paramName.
|
|
149
|
+
const hash = crypto.createHash("sha256").update(paramName).digest("hex");
|
|
150
|
+
const className = `BuildParam_${hash.slice(-10)}`;
|
|
151
|
+
const fileName = `${className}.ts`;
|
|
152
|
+
const filePath = path.join(buildParamsDir, fileName);
|
|
153
|
+
|
|
154
|
+
// Ensure buildParams directory exists.
|
|
155
|
+
if (!fs.existsSync(buildParamsDir)) {
|
|
156
|
+
fs.mkdirSync(buildParamsDir, {
|
|
157
|
+
recursive: true
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Check if file already exists.
|
|
162
|
+
if (!fs.existsSync(filePath)) {
|
|
163
|
+
// Create the BuildParam implementation file.
|
|
164
|
+
const fileContent = `import { BuildParam } from "webiny/admin/buildParams";
|
|
165
|
+
|
|
166
|
+
class ${className} implements BuildParam.Interface {
|
|
167
|
+
key = "${paramName}";
|
|
168
|
+
value = ${valueStr};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export default BuildParam.createImplementation({
|
|
172
|
+
implementation: ${className},
|
|
173
|
+
dependencies: []
|
|
174
|
+
});
|
|
175
|
+
`;
|
|
176
|
+
fs.writeFileSync(filePath, fileContent, "utf8");
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Now we need to generate/update the feature file that imports all BuildParams.
|
|
180
|
+
await generateBuildParamsFeature(buildParamsDir, ctx);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
//# sourceMappingURL=AdminBuildParam.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["z","defineExtension","crypto","path","fs","Node","Project","generateBuildParamsFeature","buildParamsDir","ctx","featureFilePath","join","files","readdirSync","filter","f","startsWith","endsWith","imports","map","file","className","parse","name","registrations","featureContent","writeFileSync","updateExtensionsTsx","extensionsTsxFilePath","project","paths","workspaceFolder","toString","addSourceFileAtPath","source","getSourceFileOrThrow","buildParamsFeatureImport","existingFeatureImport","getImportDeclaration","index","importDeclarations","getImportDeclarations","length","last","getChildIndex","insertImportDeclaration","namedImports","moduleSpecifier","buildParamsFeatureImportPath","existingBuildParamsImport","getNamedImports","hasBuildParamsFeature","some","ni","getName","addNamedImport","registerFeatureImportPath","existingRegisterFeatureImport","hasRegisterFeature","extensionsIdentifier","getFirstDescendant","node","isIdentifier","getText","Error","extensionsArrowFn","getNextSibling","isArrowFunction","extensionsArrowFnFragment","isJsxFragment","currentContent","getFullText","replace","trim","includes","newContent","replaceWithText","save","AdminBuildParam","type","tags","runtimeContext","appName","description","multiple","paramsSchema","object","paramName","string","value","union","record","any","array","number","boolean","build","params","valueStr","JSON","stringify","hash","createHash","update","digest","slice","fileName","filePath","existsSync","mkdirSync","recursive","fileContent"],"sources":["AdminBuildParam.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { defineExtension } from \"~/defineExtension/index.js\";\nimport crypto from \"crypto\";\nimport path from \"path\";\nimport fs from \"fs\";\nimport { Node, Project } from \"ts-morph\";\n\nasync function generateBuildParamsFeature(buildParamsDir: string, ctx: any) {\n const featureFilePath = path.join(buildParamsDir, \"feature.ts\");\n\n // Get all BuildParam_*.ts files.\n const files = fs\n .readdirSync(buildParamsDir)\n .filter(f => f.startsWith(\"BuildParam_\") && f.endsWith(\".ts\") && f !== \"feature.ts\");\n\n // Generate imports and registrations.\n const imports = files\n .map(file => {\n const className = path.parse(file).name;\n return `import ${className} from \"./${className}.js\";`;\n })\n .join(\"\\n\");\n\n const registrations = files\n .map(file => {\n const className = path.parse(file).name;\n return ` container.register(${className});`;\n })\n .join(\"\\n\");\n\n const featureContent = `import { createFeature } from \"@webiny/feature/admin\";\nimport { Container } from \"@webiny/di\";\n${imports}\n\nexport const BuildParamsInternalFeature = createFeature({\n name: \"BuildParamsInternal\",\n register(container: Container) {\n${registrations}\n }\n});\n`;\n\n fs.writeFileSync(featureFilePath, featureContent, \"utf8\");\n\n // Now we need to update Extensions.tsx to use RegisterFeature with this feature.\n await updateExtensionsTsx(ctx);\n}\n\nasync function updateExtensionsTsx(ctx: any) {\n const extensionsTsxFilePath = ctx.project.paths.workspaceFolder\n .join(\"apps\", \"admin\", \"src\", \"Extensions.tsx\")\n .toString();\n\n const project = new Project();\n project.addSourceFileAtPath(extensionsTsxFilePath);\n\n const source = project.getSourceFileOrThrow(extensionsTsxFilePath);\n\n // Check if we already have the imports.\n const buildParamsFeatureImport = \"./buildParams/feature.js\";\n const existingFeatureImport = source.getImportDeclaration(buildParamsFeatureImport);\n\n if (!existingFeatureImport) {\n let index = 1;\n const importDeclarations = source.getImportDeclarations();\n if (importDeclarations.length) {\n const last = importDeclarations[importDeclarations.length - 1];\n index = last.getChildIndex() + 1;\n }\n\n // Add import for BuildParamsInternalFeature.\n source.insertImportDeclaration(index, {\n namedImports: [\"BuildParamsInternalFeature\"],\n moduleSpecifier: buildParamsFeatureImport\n });\n\n // Add import for BuildParamsFeature.\n const buildParamsFeatureImportPath = \"@webiny/app-admin\";\n const existingBuildParamsImport = source.getImportDeclaration(buildParamsFeatureImportPath);\n\n if (!existingBuildParamsImport) {\n source.insertImportDeclaration(index, {\n namedImports: [\"BuildParamsFeature\"],\n moduleSpecifier: buildParamsFeatureImportPath\n });\n } else {\n // Add to existing import if BuildParamsFeature not already there.\n const namedImports = existingBuildParamsImport.getNamedImports();\n const hasBuildParamsFeature = namedImports.some(\n ni => ni.getName() === \"BuildParamsFeature\"\n );\n if (!hasBuildParamsFeature) {\n existingBuildParamsImport.addNamedImport(\"BuildParamsFeature\");\n }\n }\n\n // Add import for RegisterFeature if not present.\n const registerFeatureImportPath = \"@webiny/app-admin\";\n const existingRegisterFeatureImport =\n source.getImportDeclaration(registerFeatureImportPath);\n\n if (existingRegisterFeatureImport) {\n const namedImports = existingRegisterFeatureImport.getNamedImports();\n const hasRegisterFeature = namedImports.some(ni => ni.getName() === \"RegisterFeature\");\n if (!hasRegisterFeature) {\n existingRegisterFeatureImport.addNamedImport(\"RegisterFeature\");\n }\n } else {\n source.insertImportDeclaration(index, {\n namedImports: [\"RegisterFeature\"],\n moduleSpecifier: registerFeatureImportPath\n });\n }\n }\n\n // Now add <RegisterFeature> components to the Extensions component.\n const extensionsIdentifier = source.getFirstDescendant(node => {\n if (!Node.isIdentifier(node)) {\n return false;\n }\n return node.getText() === \"Extensions\";\n });\n\n if (!extensionsIdentifier) {\n throw new Error(\n `Could not find the \"Extensions\" React component in \"${extensionsTsxFilePath}\".`\n );\n }\n\n const extensionsArrowFn = extensionsIdentifier.getNextSibling(node =>\n Node.isArrowFunction(node)\n );\n\n if (!extensionsArrowFn) {\n throw new Error(`Could not find the \"Extensions\" React component arrow function.`);\n }\n\n const extensionsArrowFnFragment = extensionsArrowFn.getFirstDescendant(node => {\n return Node.isJsxFragment(node);\n });\n\n if (!extensionsArrowFnFragment) {\n throw new Error(`Could not find JSX fragment in Extensions component.`);\n }\n\n const currentContent = extensionsArrowFnFragment\n .getFullText()\n .replace(\"<>\", \"\")\n .replace(\"</>\", \"\")\n .trim();\n\n // Check if we already have the RegisterFeature components.\n if (!currentContent.includes(\"BuildParamsFeature\")) {\n const newContent = `<><RegisterFeature feature={BuildParamsFeature} /><RegisterFeature feature={BuildParamsInternalFeature} />${currentContent}</>`;\n extensionsArrowFnFragment.replaceWithText(newContent);\n }\n\n await source.save();\n}\n\nexport const AdminBuildParam = defineExtension({\n type: \"Admin/BuildParam\",\n tags: { runtimeContext: \"app-build\", appName: \"admin\" },\n description: \"Add build-time parameter to Admin app.\",\n multiple: true,\n paramsSchema: () => {\n return z.object({\n paramName: z.string(),\n value: z.union([\n z.string(),\n z.record(z.any()),\n z.array(z.any()),\n z.number(),\n z.boolean()\n ])\n });\n },\n async build(params, ctx) {\n const buildParamsDir = ctx.project.paths.workspaceFolder\n .join(\"apps\", \"admin\", \"src\", \"buildParams\")\n .toString();\n\n const { paramName, value } = params;\n\n // Serialize value to a TypeScript literal.\n const valueStr = JSON.stringify(value, null, 4);\n\n // Generate a unique class name based on the paramName.\n const hash = crypto.createHash(\"sha256\").update(paramName).digest(\"hex\");\n const className = `BuildParam_${hash.slice(-10)}`;\n const fileName = `${className}.ts`;\n const filePath = path.join(buildParamsDir, fileName);\n\n // Ensure buildParams directory exists.\n if (!fs.existsSync(buildParamsDir)) {\n fs.mkdirSync(buildParamsDir, { recursive: true });\n }\n\n // Check if file already exists.\n if (!fs.existsSync(filePath)) {\n // Create the BuildParam implementation file.\n const fileContent = `import { BuildParam } from \"webiny/admin/buildParams\";\n\nclass ${className} implements BuildParam.Interface {\n key = \"${paramName}\";\n value = ${valueStr};\n}\n\nexport default BuildParam.createImplementation({\n implementation: ${className},\n dependencies: []\n});\n`;\n fs.writeFileSync(filePath, fileContent, \"utf8\");\n }\n\n // Now we need to generate/update the feature file that imports all BuildParams.\n await generateBuildParamsFeature(buildParamsDir, ctx);\n }\n});\n"],"mappings":"AAAA,SAASA,CAAC,QAAQ,KAAK;AACvB,SAASC,eAAe;AACxB,OAAOC,MAAM,MAAM,QAAQ;AAC3B,OAAOC,IAAI,MAAM,MAAM;AACvB,OAAOC,EAAE,MAAM,IAAI;AACnB,SAASC,IAAI,EAAEC,OAAO,QAAQ,UAAU;AAExC,eAAeC,0BAA0BA,CAACC,cAAsB,EAAEC,GAAQ,EAAE;EACxE,MAAMC,eAAe,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List":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const AdminExtension: import("~/extensions/index.js").ExtensionComponent<z.ZodObject<{
|
|
3
|
+
src: z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
4
|
+
exportName: z.ZodOptional<z.ZodString>;
|
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
src: string;
|
|
7
|
+
exportName?: string | undefined;
|
|
8
|
+
}, {
|
|
9
|
+
src: string;
|
|
10
|
+
exportName?: string | undefined;
|
|
11
|
+
}>>;
|