@aws-amplify/amplify-util-uibuilder 1.3.0-rc.c36fa71f5.0 → 1.3.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.
- package/CHANGELOG.md +14 -1
- package/lib/clients/amplify-studio-client.d.ts +17 -0
- package/lib/clients/amplify-studio-client.d.ts.map +1 -0
- package/lib/clients/amplify-studio-client.js +145 -0
- package/lib/clients/amplify-studio-client.js.map +1 -0
- package/lib/clients/index.d.ts +2 -0
- package/lib/clients/index.d.ts.map +1 -0
- package/lib/clients/index.js +9 -0
- package/lib/clients/index.js.map +1 -0
- package/lib/commands/cloneComponentsFromEnv.d.ts +1 -1
- package/lib/commands/cloneComponentsFromEnv.d.ts.map +1 -1
- package/lib/commands/cloneComponentsFromEnv.js +15 -31
- package/lib/commands/cloneComponentsFromEnv.js.map +1 -1
- package/lib/commands/generateComponents.d.ts.map +1 -1
- package/lib/commands/generateComponents.js +14 -12
- package/lib/commands/generateComponents.js.map +1 -1
- package/lib/commands/utils/{createUiBuilderComponent.d.ts → codegenResources.d.ts} +5 -3
- package/lib/commands/utils/codegenResources.d.ts.map +1 -0
- package/lib/commands/utils/{createUiBuilderComponent.js → codegenResources.js} +26 -4
- package/lib/commands/utils/codegenResources.js.map +1 -0
- package/lib/commands/utils/environmentHelpers.d.ts +5 -0
- package/lib/commands/utils/environmentHelpers.d.ts.map +1 -0
- package/lib/commands/utils/environmentHelpers.js +25 -0
- package/lib/commands/utils/environmentHelpers.js.map +1 -0
- package/lib/commands/utils/index.d.ts +8 -0
- package/lib/commands/utils/index.d.ts.map +1 -0
- package/lib/commands/utils/index.js +20 -0
- package/lib/commands/utils/index.js.map +1 -0
- package/lib/commands/utils/syncAmplifyUiBuilderComponents.d.ts +9 -18
- package/lib/commands/utils/syncAmplifyUiBuilderComponents.d.ts.map +1 -1
- package/lib/commands/utils/syncAmplifyUiBuilderComponents.js +8 -80
- package/lib/commands/utils/syncAmplifyUiBuilderComponents.js.map +1 -1
- package/lib/index.d.ts +3 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +5 -5
- package/lib/index.js.map +1 -1
- package/package.json +14 -6
- package/src/__tests__/cloneComponentsFromEnv.test.ts +33 -26
- package/src/__tests__/createUiBuilderComponent.test.ts +14 -13
- package/src/__tests__/generateComponents.test.ts +40 -30
- package/src/__tests__/getAmplifyDataSchema.test.ts +102 -0
- package/src/__tests__/syncAmplifyUiComponents.test.ts +55 -33
- package/src/clients/amplify-studio-client.ts +161 -0
- package/src/clients/index.ts +1 -0
- package/src/commands/cloneComponentsFromEnv.ts +26 -29
- package/src/commands/generateComponents.ts +19 -12
- package/src/commands/utils/{createUiBuilderComponent.ts → codegenResources.ts} +39 -11
- package/src/commands/utils/environmentHelpers.ts +32 -0
- package/src/commands/utils/index.ts +7 -0
- package/src/commands/utils/syncAmplifyUiBuilderComponents.ts +38 -81
- package/src/index.ts +15 -5
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/commands/utils/amplifyUiBuilderService.d.ts +0 -5
- package/lib/commands/utils/amplifyUiBuilderService.d.ts.map +0 -1
- package/lib/commands/utils/amplifyUiBuilderService.js +0 -20
- package/lib/commands/utils/amplifyUiBuilderService.js.map +0 -1
- package/lib/commands/utils/createUiBuilderComponent.d.ts.map +0 -1
- package/lib/commands/utils/createUiBuilderComponent.js.map +0 -1
- package/src/commands/utils/amplifyUiBuilderService.ts +0 -22
|
@@ -1,85 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateUiBuilderThemes = exports.generateUiBuilderComponents =
|
|
4
|
-
const amplifyUiBuilderService_1 = require("./amplifyUiBuilderService");
|
|
3
|
+
exports.generateUiBuilderThemes = exports.generateUiBuilderComponents = void 0;
|
|
5
4
|
const amplify_prompts_1 = require("amplify-prompts");
|
|
6
|
-
const
|
|
5
|
+
const codegenResources_1 = require("./codegenResources");
|
|
7
6
|
const getUiBuilderComponentsPath_1 = require("./getUiBuilderComponentsPath");
|
|
8
|
-
const
|
|
9
|
-
const getEnvName = (context, envName) => {
|
|
10
|
-
const args = (0, extractArgs_1.extractArgs)(context);
|
|
11
|
-
return envName ? envName : args.environmentName ? args.environmentName : context.exeInfo.localEnvInfo.envName;
|
|
12
|
-
};
|
|
13
|
-
exports.getEnvName = getEnvName;
|
|
14
|
-
const resolveAppId = async (context) => {
|
|
15
|
-
return await context.amplify.invokePluginMethod(context, 'awscloudformation', undefined, 'resolveAppId', [context]);
|
|
16
|
-
};
|
|
17
|
-
exports.resolveAppId = resolveAppId;
|
|
18
|
-
const getAppId = async (context) => {
|
|
19
|
-
const appId = (0, extractArgs_1.extractArgs)(context).appId || (await (0, exports.resolveAppId)(context));
|
|
20
|
-
if (!appId) {
|
|
21
|
-
throw new Error('Unable to sync Studio components since appId could not be determined. This can happen when you hit the soft limit of number of apps that you can have in Amplify console.');
|
|
22
|
-
}
|
|
23
|
-
return appId;
|
|
24
|
-
};
|
|
25
|
-
exports.getAppId = getAppId;
|
|
26
|
-
async function listUiBuilderComponents(context, envName) {
|
|
27
|
-
const environmentName = (0, exports.getEnvName)(context, envName);
|
|
28
|
-
const appId = await (0, exports.getAppId)(context);
|
|
29
|
-
try {
|
|
30
|
-
const amplifyUIBuilder = await (0, amplifyUiBuilderService_1.getAmplifyUIBuilderService)(context, environmentName, appId);
|
|
31
|
-
let nextToken;
|
|
32
|
-
const uiBuilderComponents = [];
|
|
33
|
-
do {
|
|
34
|
-
const response = await amplifyUIBuilder
|
|
35
|
-
.exportComponents({
|
|
36
|
-
appId,
|
|
37
|
-
environmentName,
|
|
38
|
-
nextToken
|
|
39
|
-
})
|
|
40
|
-
.promise();
|
|
41
|
-
uiBuilderComponents.push(...response.entities);
|
|
42
|
-
nextToken = response.nextToken;
|
|
43
|
-
} while (nextToken);
|
|
44
|
-
amplify_prompts_1.printer.debug(JSON.stringify(uiBuilderComponents, null, 2));
|
|
45
|
-
return { entities: uiBuilderComponents };
|
|
46
|
-
}
|
|
47
|
-
catch (e) {
|
|
48
|
-
amplify_prompts_1.printer.debug(e);
|
|
49
|
-
throw e;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
exports.listUiBuilderComponents = listUiBuilderComponents;
|
|
53
|
-
async function listUiBuilderThemes(context, envName) {
|
|
54
|
-
const environmentName = (0, exports.getEnvName)(context, envName);
|
|
55
|
-
const appId = await (0, exports.getAppId)(context);
|
|
56
|
-
try {
|
|
57
|
-
const amplifyUIBuilder = await (0, amplifyUiBuilderService_1.getAmplifyUIBuilderService)(context, environmentName, appId);
|
|
58
|
-
let nextToken;
|
|
59
|
-
const uiBuilderThemes = [];
|
|
60
|
-
do {
|
|
61
|
-
const response = await amplifyUIBuilder
|
|
62
|
-
.exportThemes({
|
|
63
|
-
appId,
|
|
64
|
-
environmentName,
|
|
65
|
-
})
|
|
66
|
-
.promise();
|
|
67
|
-
uiBuilderThemes.push(...response.entities);
|
|
68
|
-
nextToken = response.nextToken;
|
|
69
|
-
} while (nextToken);
|
|
70
|
-
amplify_prompts_1.printer.debug(JSON.stringify(uiBuilderThemes, null, 2));
|
|
71
|
-
return { entities: uiBuilderThemes };
|
|
72
|
-
}
|
|
73
|
-
catch (e) {
|
|
74
|
-
amplify_prompts_1.printer.debug(e);
|
|
75
|
-
throw e;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
exports.listUiBuilderThemes = listUiBuilderThemes;
|
|
79
|
-
function generateUiBuilderComponents(context, componentSchemas) {
|
|
7
|
+
const generateUiBuilderComponents = (context, componentSchemas, dataSchema) => {
|
|
80
8
|
const componentResults = componentSchemas.map(schema => {
|
|
81
9
|
try {
|
|
82
|
-
const component = (0,
|
|
10
|
+
const component = (0, codegenResources_1.createUiBuilderComponent)(context, schema, dataSchema);
|
|
83
11
|
return { resultType: 'SUCCESS', component };
|
|
84
12
|
}
|
|
85
13
|
catch (e) {
|
|
@@ -90,12 +18,12 @@ function generateUiBuilderComponents(context, componentSchemas) {
|
|
|
90
18
|
});
|
|
91
19
|
amplify_prompts_1.printer.debug(`Generated ${componentResults.filter(result => result.resultType === 'SUCCESS').length} components in ${(0, getUiBuilderComponentsPath_1.getUiBuilderComponentsPath)(context)}`);
|
|
92
20
|
return componentResults;
|
|
93
|
-
}
|
|
21
|
+
};
|
|
94
22
|
exports.generateUiBuilderComponents = generateUiBuilderComponents;
|
|
95
|
-
|
|
23
|
+
const generateUiBuilderThemes = (context, themeSchemas) => {
|
|
96
24
|
const themeResults = themeSchemas.map(schema => {
|
|
97
25
|
try {
|
|
98
|
-
const theme = (0,
|
|
26
|
+
const theme = (0, codegenResources_1.createUiBuilderTheme)(context, schema);
|
|
99
27
|
return { resultType: 'SUCCESS', theme };
|
|
100
28
|
}
|
|
101
29
|
catch (e) {
|
|
@@ -106,6 +34,6 @@ function generateUiBuilderThemes(context, themeSchemas) {
|
|
|
106
34
|
});
|
|
107
35
|
amplify_prompts_1.printer.debug(`Generated ${themeResults.filter(result => result.resultType === 'SUCCESS').length} themes in ${(0, getUiBuilderComponentsPath_1.getUiBuilderComponentsPath)(context)}`);
|
|
108
36
|
return themeResults;
|
|
109
|
-
}
|
|
37
|
+
};
|
|
110
38
|
exports.generateUiBuilderThemes = generateUiBuilderThemes;
|
|
111
39
|
//# sourceMappingURL=syncAmplifyUiBuilderComponents.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"syncAmplifyUiBuilderComponents.js","sourceRoot":"","sources":["../../../src/commands/utils/syncAmplifyUiBuilderComponents.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"syncAmplifyUiBuilderComponents.js","sourceRoot":"","sources":["../../../src/commands/utils/syncAmplifyUiBuilderComponents.ts"],"names":[],"mappings":";;;AAAA,qDAA0C;AAK1C,yDAAoF;AACpF,6EAA0E;AAMnE,MAAM,2BAA2B,GAAG,CAAC,OAAmB,EAAE,gBAAuB,EAAE,UAA8B,EAUnH,EAAE;IACL,MAAM,gBAAgB,GAAG,gBAAgB,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;QACrD,IAAI;YACF,MAAM,SAAS,GAAG,IAAA,2CAAwB,EAAC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;YACxE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;SAC7C;QAAC,OAAO,CAAC,EAAE;YACV,yBAAO,CAAC,KAAK,CAAC,6BAA6B,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;YAC1D,yBAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACjB,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;SACrE;IACH,CAAC,CAAC,CAAC;IAEH,yBAAO,CAAC,KAAK,CACX,aAAa,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,MAAM,kBAAkB,IAAA,uDAA0B,EAChI,OAAO,CACR,EAAE,CACJ,CAAC;IACF,OAAO,gBAAgB,CAAC;AAC1B,CAAC,CAAC;AA5BW,QAAA,2BAA2B,+BA4BtC;AAMK,MAAM,uBAAuB,GAAG,CAAC,OAAmB,EAAE,YAAmB,EAU3E,EAAE;IACL,MAAM,YAAY,GAAG,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;QAC7C,IAAI;YACF,MAAM,KAAK,GAAG,IAAA,uCAAoB,EAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YACpD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;SACzC;QAAC,OAAO,CAAC,EAAE;YACV,yBAAO,CAAC,KAAK,CAAC,6BAA6B,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;YAC1D,yBAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACjB,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;SACrE;IACH,CAAC,CAAC,CAAC;IAEH,yBAAO,CAAC,KAAK,CACX,aAAa,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,MAAM,cAAc,IAAA,uDAA0B,EAAC,OAAO,CAAC,EAAE,CACtI,CAAC;IACF,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC;AA1BW,QAAA,uBAAuB,2BA0BlC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { $TSContext } from 'amplify-cli-core';
|
|
2
|
-
export declare
|
|
3
|
-
export declare
|
|
2
|
+
export declare const executeAmplifyCommand: (context: $TSContext, cmd: string) => Promise<void>;
|
|
3
|
+
export declare const handleAmplifyEvent: (context: $TSContext, { event }: {
|
|
4
4
|
event: string;
|
|
5
|
-
})
|
|
5
|
+
}) => Promise<void>;
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAQ9C,eAAO,MAAM,qBAAqB,YAAmB,UAAU,OAAO,MAAM,KAAG,QAAQ,IAAI,CAM1F,CAAC;AAKF,eAAO,MAAM,kBAAkB,YAAmB,UAAU;WAAsB,MAAM;MAAK,QAAQ,IAAI,CAMxG,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -5,18 +5,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.handleAmplifyEvent = exports.executeAmplifyCommand = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
|
-
async
|
|
8
|
+
const executeAmplifyCommand = async (context, cmd) => {
|
|
9
9
|
const commandsDirPath = path_1.default.normalize(path_1.default.join(__dirname, 'commands'));
|
|
10
|
-
const commandPath = path_1.default.join(commandsDirPath, cmd
|
|
10
|
+
const commandPath = path_1.default.join(commandsDirPath, cmd || context.input.command);
|
|
11
11
|
const commandModule = require(commandPath);
|
|
12
12
|
await commandModule.run(context);
|
|
13
|
-
}
|
|
13
|
+
};
|
|
14
14
|
exports.executeAmplifyCommand = executeAmplifyCommand;
|
|
15
|
-
async
|
|
15
|
+
const handleAmplifyEvent = async (context, { event }) => {
|
|
16
16
|
const eventHandlersDirPath = path_1.default.normalize(path_1.default.join(__dirname, 'event-handlers'));
|
|
17
17
|
const eventHandlerPath = path_1.default.join(eventHandlersDirPath, `handle-${event}`);
|
|
18
18
|
const eventHandlerModule = require(eventHandlerPath);
|
|
19
19
|
await eventHandlerModule.run(context);
|
|
20
|
-
}
|
|
20
|
+
};
|
|
21
21
|
exports.handleAmplifyEvent = handleAmplifyEvent;
|
|
22
22
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AACA,gDAAwB;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AACA,gDAAwB;AAOjB,MAAM,qBAAqB,GAAG,KAAK,EAAE,OAAmB,EAAE,GAAW,EAAiB,EAAE;IAC7F,MAAM,eAAe,GAAG,cAAI,CAAC,SAAS,CAAC,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC;IACzE,MAAM,WAAW,GAAG,cAAI,CAAC,IAAI,CAAC,eAAe,EAAE,GAAG,IAAI,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAE7E,MAAM,aAAa,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAC3C,MAAM,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AACnC,CAAC,CAAC;AANW,QAAA,qBAAqB,yBAMhC;AAKK,MAAM,kBAAkB,GAAG,KAAK,EAAE,OAAmB,EAAE,EAAE,KAAK,EAAqB,EAAiB,EAAE;IAC3G,MAAM,oBAAoB,GAAG,cAAI,CAAC,SAAS,CAAC,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC,CAAC;IACpF,MAAM,gBAAgB,GAAG,cAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,UAAU,KAAK,EAAE,CAAC,CAAC;IAE5E,MAAM,kBAAkB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IACrD,MAAM,kBAAkB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AACxC,CAAC,CAAC;AANW,QAAA,kBAAkB,sBAM7B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/amplify-util-uibuilder",
|
|
3
|
-
"version": "1.3.0
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -13,15 +13,16 @@
|
|
|
13
13
|
"access": "public"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@aws-amplify/codegen-ui": "^2.2
|
|
17
|
-
"@aws-amplify/codegen-ui-react": "^2.2
|
|
18
|
-
"amplify-cli-core": "2.12.0
|
|
16
|
+
"@aws-amplify/codegen-ui": "^2.3.2",
|
|
17
|
+
"@aws-amplify/codegen-ui-react": "^2.3.2",
|
|
18
|
+
"amplify-cli-core": "2.12.0",
|
|
19
19
|
"amplify-prompts": "2.2.0",
|
|
20
20
|
"aws-sdk": "^2.1113.0",
|
|
21
21
|
"ora": "^4.0.3"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/fs-extra": "^8.0.1",
|
|
25
|
+
"@types/jest": "^26.0.20",
|
|
25
26
|
"@types/semver": "^7.1.0"
|
|
26
27
|
},
|
|
27
28
|
"jest": {
|
|
@@ -30,9 +31,16 @@
|
|
|
30
31
|
"transform": {
|
|
31
32
|
"^.+\\.tsx?$": "ts-jest"
|
|
32
33
|
},
|
|
34
|
+
"globals": {
|
|
35
|
+
"window": {},
|
|
36
|
+
"ts-jest": {
|
|
37
|
+
"diagnostics": true
|
|
38
|
+
}
|
|
39
|
+
},
|
|
33
40
|
"collectCoverage": true,
|
|
34
41
|
"collectCoverageFrom": [
|
|
35
42
|
"src/**/*.ts",
|
|
43
|
+
"!**/*.test.ts",
|
|
36
44
|
"!**/node_modules/**",
|
|
37
45
|
"!src/__tests__/**",
|
|
38
46
|
"!lib/**"
|
|
@@ -43,7 +51,7 @@
|
|
|
43
51
|
],
|
|
44
52
|
"testEnvironment": "node",
|
|
45
53
|
"testURL": "http://localhost/",
|
|
46
|
-
"testRegex": "(src/(__tests__|__e2e__|__e2e_v2__)/.*.test.ts)$",
|
|
54
|
+
"testRegex": "((src/(__tests__|__e2e__|__e2e_v2__))/.*.test.ts)$",
|
|
47
55
|
"moduleFileExtensions": [
|
|
48
56
|
"ts",
|
|
49
57
|
"tsx",
|
|
@@ -59,5 +67,5 @@
|
|
|
59
67
|
"usePathForSuiteName": "true",
|
|
60
68
|
"addFileAttribute": "true"
|
|
61
69
|
},
|
|
62
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "f13d9d36118d853454b977b559a5d523cc126c0c"
|
|
63
71
|
}
|
|
@@ -1,49 +1,56 @@
|
|
|
1
|
+
import aws from 'aws-sdk'; // eslint-disable-line import/no-extraneous-dependencies
|
|
1
2
|
import * as extractArgsDependency from '../commands/utils/extractArgs';
|
|
2
|
-
import * as listUiBuilderComponentsDependency from '../commands/utils/syncAmplifyUiBuilderComponents';
|
|
3
3
|
import { run } from '../commands/cloneComponentsFromEnv';
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
4
|
+
|
|
5
|
+
const extractArgsDependencyMock = extractArgsDependency as any;
|
|
6
|
+
const awsMock = aws as any;
|
|
7
|
+
|
|
8
|
+
jest.mock('../commands/utils/extractArgs');
|
|
9
|
+
jest.mock('amplify-cli-core');
|
|
10
|
+
|
|
11
|
+
const mockedComponentExport = jest.fn((envName: string) => {
|
|
12
|
+
if (envName === 'newEnvName') {
|
|
13
|
+
return {
|
|
14
|
+
entities: [],
|
|
15
|
+
};
|
|
16
|
+
}
|
|
7
17
|
return {
|
|
8
|
-
|
|
9
|
-
return {
|
|
10
|
-
createComponent: () => ({
|
|
11
|
-
promise: () => true,
|
|
12
|
-
}),
|
|
13
|
-
};
|
|
14
|
-
}),
|
|
18
|
+
entities: [{}],
|
|
15
19
|
};
|
|
16
20
|
});
|
|
17
|
-
jest.
|
|
18
|
-
jest.mock('../commands/utils/syncAmplifyUiBuilderComponents');
|
|
21
|
+
const mockedComponentCreate = jest.fn(() => ({ entity: {} }));
|
|
19
22
|
|
|
20
23
|
describe('can clone components to new environment', () => {
|
|
21
24
|
let context: any;
|
|
22
25
|
beforeEach(() => {
|
|
23
26
|
context = {
|
|
24
27
|
amplify: {
|
|
25
|
-
invokePluginMethod: () =>
|
|
28
|
+
invokePluginMethod: () => ({}),
|
|
29
|
+
},
|
|
30
|
+
input: {
|
|
31
|
+
options: {
|
|
32
|
+
appId: 'testAppId',
|
|
33
|
+
envName: 'testEnvName',
|
|
34
|
+
},
|
|
26
35
|
},
|
|
27
36
|
};
|
|
28
|
-
|
|
37
|
+
extractArgsDependencyMock.extractArgs = jest.fn().mockImplementation(() => ({
|
|
29
38
|
sourceEnvName: 'sourceEnvName',
|
|
30
39
|
newEnvName: 'newEnvName',
|
|
31
40
|
appId: 'appId',
|
|
32
41
|
environmentName: 'environmentName',
|
|
33
42
|
}));
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return {
|
|
41
|
-
entities: [{}],
|
|
42
|
-
};
|
|
43
|
-
});
|
|
43
|
+
awsMock.AmplifyUIBuilder = jest.fn(() => ({
|
|
44
|
+
exportComponents: jest.fn(({ environmentName }) => ({
|
|
45
|
+
promise: () => mockedComponentExport(environmentName),
|
|
46
|
+
})),
|
|
47
|
+
createComponent: jest.fn(() => ({ promise: () => mockedComponentCreate() })),
|
|
48
|
+
}));
|
|
44
49
|
});
|
|
50
|
+
|
|
45
51
|
it('clones components to a new env', async () => {
|
|
46
52
|
await run(context);
|
|
47
|
-
expect(
|
|
53
|
+
expect(mockedComponentExport).toBeCalledTimes(2);
|
|
54
|
+
expect(mockedComponentCreate).toBeCalledTimes(1);
|
|
48
55
|
});
|
|
49
56
|
});
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import * as codegen from '@aws-amplify/codegen-ui';
|
|
1
|
+
import * as codegen from '@aws-amplify/codegen-ui'; // eslint-disable-line import/no-extraneous-dependencies
|
|
2
2
|
import {
|
|
3
3
|
generateAmplifyUiBuilderIndexFile,
|
|
4
4
|
createUiBuilderTheme,
|
|
5
5
|
createUiBuilderComponent,
|
|
6
|
-
} from '../commands/utils/
|
|
6
|
+
} from '../commands/utils/codegenResources';
|
|
7
|
+
|
|
7
8
|
jest.mock('@aws-amplify/codegen-ui');
|
|
8
|
-
const
|
|
9
|
+
const codegenMock = codegen as any;
|
|
9
10
|
const renderSchemaToTemplateMock = jest.fn();
|
|
10
11
|
|
|
11
12
|
describe('can create a ui builder component', () => {
|
|
@@ -41,20 +42,20 @@ describe('can create a ui builder component', () => {
|
|
|
41
42
|
properties: {},
|
|
42
43
|
variants: [],
|
|
43
44
|
};
|
|
44
|
-
|
|
45
|
+
codegenMock.StudioTemplateRendererManager = jest.fn().mockImplementation(() => ({
|
|
45
46
|
renderSchemaToTemplate: renderSchemaToTemplateMock,
|
|
46
47
|
}));
|
|
47
48
|
});
|
|
48
|
-
it('calls the renderManager',
|
|
49
|
-
|
|
50
|
-
expect(new
|
|
49
|
+
it('calls the renderManager', () => {
|
|
50
|
+
createUiBuilderComponent(context, schema);
|
|
51
|
+
expect(new codegenMock.StudioTemplateRendererManager().renderSchemaToTemplate).toBeCalled();
|
|
51
52
|
});
|
|
52
|
-
it('calls the renderManager for themes',
|
|
53
|
-
|
|
54
|
-
expect(new
|
|
53
|
+
it('calls the renderManager for themes', () => {
|
|
54
|
+
createUiBuilderTheme(context, schema);
|
|
55
|
+
expect(new codegenMock.StudioTemplateRendererManager().renderSchemaToTemplate).toBeCalled();
|
|
55
56
|
});
|
|
56
|
-
it('calls the renderManager for index file',
|
|
57
|
-
|
|
58
|
-
expect(new
|
|
57
|
+
it('calls the renderManager for index file', () => {
|
|
58
|
+
generateAmplifyUiBuilderIndexFile(context, [schema]);
|
|
59
|
+
expect(new codegenMock.StudioTemplateRendererManager().renderSchemaToTemplate).toBeCalled();
|
|
59
60
|
});
|
|
60
61
|
});
|
|
@@ -1,33 +1,31 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as
|
|
3
|
-
import * as listUiBuilderComponentsDependency from '../commands/utils/syncAmplifyUiBuilderComponents';
|
|
4
|
-
import * as generateUiBuilderComponentsDependency from '../commands/utils/syncAmplifyUiBuilderComponents';
|
|
5
|
-
import * as generateUiBuilderThemesDependency from '../commands/utils/syncAmplifyUiBuilderComponents';
|
|
6
|
-
import * as listUiBuilderThemesDependency from '../commands/utils/syncAmplifyUiBuilderComponents';
|
|
7
|
-
import * as generateAmplifyUiBuilderIndexFileDependency from '../commands/utils/createUiBuilderComponent';
|
|
1
|
+
import aws from 'aws-sdk'; // eslint-disable-line import/no-extraneous-dependencies
|
|
2
|
+
import * as utils from '../commands/utils';
|
|
8
3
|
import { run } from '../commands/generateComponents';
|
|
9
|
-
jest.mock('../commands/utils/syncAmplifyUiBuilderComponents');
|
|
10
|
-
jest.mock('../commands/utils/createUiBuilderComponent');
|
|
11
|
-
jest.mock('../commands/utils/shouldRenderComponents');
|
|
12
|
-
jest.mock('../commands/utils/notifyMissingPackages');
|
|
13
|
-
const shouldRenderComponentsDependency_mock = shouldRenderComponentsDependency as any;
|
|
14
|
-
const notifyMissingPackagesDependency_mock = notifyMissingPackagesDependency as any;
|
|
15
|
-
const listUiBuilderComponentsDependency_mock = listUiBuilderComponentsDependency as any;
|
|
16
|
-
const generateUiBuilderComponentsDependency_mock = generateUiBuilderComponentsDependency as any;
|
|
17
|
-
const generateUiBuilderThemesDependency_mock = generateUiBuilderThemesDependency as any;
|
|
18
|
-
const listUiBuilderThemesDependency_mock = listUiBuilderThemesDependency as any;
|
|
19
|
-
const generateAmplifyUiBuilderIndexFileDependency_mock = generateAmplifyUiBuilderIndexFileDependency as any;
|
|
20
4
|
|
|
21
|
-
|
|
22
|
-
|
|
5
|
+
jest.mock('../commands/utils');
|
|
6
|
+
jest.mock('amplify-cli-core');
|
|
7
|
+
const awsMock = aws as any;
|
|
8
|
+
const utilsMock = utils as any;
|
|
9
|
+
|
|
10
|
+
utilsMock.shouldRenderComponents = jest.fn().mockImplementation(() => true);
|
|
11
|
+
utilsMock.notifyMissingPackages = jest.fn().mockImplementation(() => true);
|
|
23
12
|
|
|
24
13
|
describe('can generate components', () => {
|
|
25
14
|
let context: any;
|
|
26
15
|
let schemas: any;
|
|
27
|
-
let
|
|
28
|
-
let generateUiBuilderThemes: any;
|
|
16
|
+
let mockedExport: jest.Mock<any, any>;
|
|
29
17
|
beforeEach(() => {
|
|
30
|
-
context = {
|
|
18
|
+
context = {
|
|
19
|
+
amplify: {
|
|
20
|
+
invokePluginMethod: () => ({}),
|
|
21
|
+
},
|
|
22
|
+
input: {
|
|
23
|
+
options: {
|
|
24
|
+
appId: 'testAppId',
|
|
25
|
+
envName: 'testEnvName',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
};
|
|
31
29
|
schemas = {
|
|
32
30
|
entities: [
|
|
33
31
|
{
|
|
@@ -38,15 +36,27 @@ describe('can generate components', () => {
|
|
|
38
36
|
},
|
|
39
37
|
],
|
|
40
38
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
mockedExport = jest.fn(() => ({
|
|
40
|
+
entities: schemas.entities,
|
|
41
|
+
}));
|
|
42
|
+
awsMock.AmplifyUIBuilder = jest.fn(() => ({
|
|
43
|
+
exportComponents: jest.fn(() => ({
|
|
44
|
+
promise: () => mockedExport(),
|
|
45
|
+
})),
|
|
46
|
+
exportThemes: jest.fn(() => ({
|
|
47
|
+
promise: () => mockedExport(),
|
|
48
|
+
})),
|
|
49
|
+
}));
|
|
50
|
+
utilsMock.generateUiBuilderComponents = jest.fn().mockImplementation(() => schemas.entities);
|
|
51
|
+
utilsMock.generateUiBuilderThemes = jest.fn().mockImplementation(() => schemas.entities);
|
|
52
|
+
utilsMock.getAmplifyDataSchema = jest.fn().mockImplementation(() => undefined);
|
|
53
|
+
utilsMock.generateAmplifyUiBuilderIndexFile = jest.fn().mockImplementation(() => true);
|
|
46
54
|
});
|
|
55
|
+
|
|
47
56
|
it('runs generateComponents', async () => {
|
|
48
57
|
await run(context);
|
|
49
|
-
expect(
|
|
50
|
-
expect(
|
|
58
|
+
expect(mockedExport).toBeCalledTimes(2);
|
|
59
|
+
expect(utilsMock.generateUiBuilderComponents).toBeCalledTimes(1);
|
|
60
|
+
expect(utilsMock.generateUiBuilderThemes).toBeCalledTimes(1);
|
|
51
61
|
});
|
|
52
62
|
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import aws from 'aws-sdk'; // eslint-disable-line import/no-extraneous-dependencies
|
|
2
|
+
import { AmplifyCategories, AmplifySupportedService } from 'amplify-cli-core'; // eslint-disable-line import/no-extraneous-dependencies
|
|
3
|
+
import { printer } from 'amplify-prompts'; // eslint-disable-line import/no-extraneous-dependencies
|
|
4
|
+
import { AmplifyStudioClient } from '../clients';
|
|
5
|
+
import { getAmplifyDataSchema } from '../commands/utils';
|
|
6
|
+
|
|
7
|
+
const awsMock = aws as any;
|
|
8
|
+
const printerMock = printer as any;
|
|
9
|
+
|
|
10
|
+
jest.mock('amplify-cli-core', () => ({
|
|
11
|
+
...jest.requireActual('amplify-cli-core'),
|
|
12
|
+
stateManager: {
|
|
13
|
+
getMeta: jest.fn(() => ({
|
|
14
|
+
[AmplifyCategories.API]: {
|
|
15
|
+
MyResourceName: {
|
|
16
|
+
service: AmplifySupportedService.APPSYNC,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
})),
|
|
20
|
+
},
|
|
21
|
+
FeatureFlags: {
|
|
22
|
+
getBoolean: () => false,
|
|
23
|
+
getNumber: () => 0,
|
|
24
|
+
},
|
|
25
|
+
}));
|
|
26
|
+
jest.mock('amplify-prompts');
|
|
27
|
+
|
|
28
|
+
const getMockedSchema = jest.fn(
|
|
29
|
+
// eslint-disable-next-line no-useless-escape, spellcheck/spell-checker
|
|
30
|
+
() => `export const schema = {\n \"models\": {\n \"Blog\": {\n \"name\": \"Blog\",\n \"fields\": {\n \"id\": {\n \"name\": \"id\",\n \"isArray\": false,\n \"type\": \"ID\",\n \"isRequired\": true,\n \"attributes\": []\n },\n \"title\": {\n \"name\": \"title\",\n \"isArray\": false,\n \"type\": \"String\",\n \"isRequired\": false,\n \"attributes\": []\n },\n \"content\": {\n \"name\": \"content\",\n \"isArray\": false,\n \"type\": \"String\",\n \"isRequired\": false,\n \"attributes\": []\n },\n \"status\": {\n \"name\": \"status\",\n \"isArray\": false,\n \"type\": {\n \"enum\": \"Status\"\n },\n \"isRequired\": false,\n \"attributes\": []\n },\n \"createdAt\": {\n \"name\": \"createdAt\",\n \"isArray\": false,\n \"type\": \"AWSDateTime\",\n \"isRequired\": false,\n \"attributes\": [],\n \"isReadOnly\": true\n },\n \"updatedAt\": {\n \"name\": \"updatedAt\",\n \"isArray\": false,\n \"type\": \"AWSDateTime\",\n \"isRequired\": false,\n \"attributes\": [],\n \"isReadOnly\": true\n }\n },\n \"syncable\": true,\n \"pluralName\": \"Blogs\",\n \"attributes\": [\n {\n \"type\": \"model\",\n \"properties\": {}\n },\n {\n \"type\": \"auth\",\n \"properties\": {\n \"rules\": [\n {\n \"allow\": \"public\",\n \"operations\": [\n \"create\",\n \"update\",\n \"delete\",\n \"read\"\n ]\n }\n ]\n }\n }\n ]\n }\n },\n \"enums\": {\n \"Status\": {\n \"name\": \"Status\",\n \"values\": [\n \"ENABLED\",\n \"DISABLED\"\n ]\n }\n },\n \"nonModels\": {},\n \"version\": \"demo\"\n};`,
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
describe('should sync amplify backend models', () => {
|
|
34
|
+
let context: any;
|
|
35
|
+
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
context = {
|
|
38
|
+
exeInfo: {
|
|
39
|
+
projectConfig: {
|
|
40
|
+
javascript: {
|
|
41
|
+
config: {
|
|
42
|
+
SourceDir: 'src',
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
amplify: {
|
|
48
|
+
invokePluginMethod: () => ({}),
|
|
49
|
+
},
|
|
50
|
+
parameters: {
|
|
51
|
+
argv: [],
|
|
52
|
+
},
|
|
53
|
+
input: {
|
|
54
|
+
options: {
|
|
55
|
+
appId: 'testAppId',
|
|
56
|
+
envName: 'testEnvName',
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('should getAmplifyBackendModels', async () => {
|
|
63
|
+
awsMock.AmplifyBackend = jest.fn(() => ({
|
|
64
|
+
getBackendAPIModels: jest.fn(() => ({
|
|
65
|
+
promise: () => ({
|
|
66
|
+
Models: getMockedSchema(),
|
|
67
|
+
}),
|
|
68
|
+
})),
|
|
69
|
+
}));
|
|
70
|
+
const client = await AmplifyStudioClient.setClientInfo(context);
|
|
71
|
+
const dataSchema = await getAmplifyDataSchema(client);
|
|
72
|
+
expect(getMockedSchema).toBeCalled();
|
|
73
|
+
expect(dataSchema).toBeDefined();
|
|
74
|
+
expect(Object.keys(dataSchema!.models)).toContain('Blog');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('should handle Models not found', async () => {
|
|
78
|
+
awsMock.AmplifyBackend = jest.fn(() => ({
|
|
79
|
+
getBackendAPIModels: jest.fn(() => ({
|
|
80
|
+
promise: jest.fn(() => ({
|
|
81
|
+
Models: undefined,
|
|
82
|
+
})),
|
|
83
|
+
})),
|
|
84
|
+
}));
|
|
85
|
+
const client = await AmplifyStudioClient.setClientInfo(context);
|
|
86
|
+
const dataSchema = await getAmplifyDataSchema(client);
|
|
87
|
+
expect(dataSchema).toBeUndefined();
|
|
88
|
+
expect(printerMock.debug).toHaveBeenCalledWith('Provided ResourceName: MyResourceName did not yield Models.');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('should handle network error', async () => {
|
|
92
|
+
awsMock.AmplifyBackend = jest.fn(() => ({
|
|
93
|
+
getBackendAPIModels: jest.fn(() => ({
|
|
94
|
+
promise: jest.fn().mockRejectedValue(new Error('Network Error')),
|
|
95
|
+
})),
|
|
96
|
+
}));
|
|
97
|
+
const client = await AmplifyStudioClient.setClientInfo(context);
|
|
98
|
+
const dataSchema = await getAmplifyDataSchema(client);
|
|
99
|
+
expect(dataSchema).toBeUndefined();
|
|
100
|
+
expect(printerMock.debug).toHaveBeenCalledWith('Error: Models not found in AmplifyBackend:GetBackendAPIModels response: Network Error');
|
|
101
|
+
});
|
|
102
|
+
});
|