MCPcopy
hub / github.com/midwayjs/midway / transformFrameworkToConfiguration

Function transformFrameworkToConfiguration

packages/mock/src/utils.ts:40–86  ·  view source on GitHub ↗
(
  Framework: any,
  loadMode: 'commonjs' | 'esm'
)

Source from the content-addressed store, hash-verified

38 * @param Framework
39 */
40export async function transformFrameworkToConfiguration<
41 T extends IMidwayFramework<any, any, any>,
42>(
43 Framework: any,
44 loadMode: 'commonjs' | 'esm'
45): Promise<{
46 [key: string]: any;
47 Configuration: any;
48}> {
49 if (!Framework) return null;
50 let CustomFramework = Framework;
51 if (typeof Framework === 'string') {
52 Framework = await loadModule(Framework, {
53 loadMode,
54 safeLoad: true,
55 });
56 }
57
58 if (Framework.Configuration) {
59 return Framework;
60 }
61
62 if (Framework.Framework) {
63 CustomFramework = Framework.Framework;
64 } else {
65 CustomFramework = Framework;
66 }
67
68 assert.ok(CustomFramework, `can't found custom framework ${Framework}`);
69
70 @Configuration({
71 namespace: new Framework().getFrameworkName(),
72 })
73 class CustomConfiguration {
74 async onServerReady(container: IMidwayContainer) {
75 const customFramework = (await container.getAsync<T>(
76 CustomFramework as any
77 )) as T;
78 await customFramework.run();
79 }
80 }
81
82 return {
83 Configuration: CustomConfiguration,
84 Framework,
85 };
86}
87
88export async function removeFile(file: string) {
89 try {

Callers 2

createFunctionAppFunction · 0.90
createLightAppFunction · 0.90

Calls 2

loadModuleFunction · 0.90
okMethod · 0.80

Tested by

no test coverage detected