Skip to content

Commit c93afea

Browse files
alharris-atyuthphani-srikarAaronZyLee
authored
Release: Add codegen version metadata to generate file headers, and updating package dependency versions (#340)
* build: update packages (#325) * build: update packages * build: update @graphql-codegen/core * fix(amplify-codegen): Add Amplify CLI version as a comment for the Modelgen output files (#133) * feat(amplify-codegen): Add Amplify CLI version as a comment for the Modelgen output files * fix(amplify-codegen): rephrase the amplify version comment * fix(amplify-codegen): add amplify-codegen version to version metadata comment * fix(amplify-codegen): minor changes to use lambda functions * fix(amplify-codegen): remove commented test * fix(amplify-codegen): remove optional chaining for backwards compatibility * fix(amplify-codegen): refactor the if conditional * test: add warning in context Co-authored-by: Zeyu Li <[email protected]> Co-authored-by: Yathi <[email protected]> Co-authored-by: Phani Srikar Edupuganti <[email protected]> Co-authored-by: Zeyu Li <[email protected]>
1 parent e73e421 commit c93afea

File tree

7 files changed

+314
-149
lines changed

7 files changed

+314
-149
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@
5858
"packages/*"
5959
],
6060
"devDependencies": {
61-
"@commitlint/cli": "^8.1.0",
62-
"@commitlint/config-conventional": "^8.1.0",
63-
"@commitlint/config-lerna-scopes": "^8.1.0",
61+
"@commitlint/cli": "^15.0.0",
62+
"@commitlint/config-conventional": "^15.0.0",
63+
"@commitlint/config-lerna-scopes": "^15.0.0",
6464
"@types/jest": "^25.2.1",
6565
"@types/js-yaml": "^3.12.3",
6666
"@typescript-eslint/eslint-plugin": "^2.16.0",

packages/amplify-codegen-e2e-tests/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
},
2424
"dependencies": {
2525
"amplify-codegen-e2e-core": "1.1.5",
26-
"aws-amplify": "^3.0.8",
26+
"aws-amplify": "^4.3.10",
2727
"aws-appsync": "^4.0.3",
2828
"aws-sdk": "^2.845.0",
2929
"circleci-api": "^4.1.3",

packages/amplify-codegen/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"@aws-amplify/appsync-modelgen-plugin": "1.29.10",
2424
"@aws-amplify/graphql-docs-generator": "2.4.2",
2525
"@aws-amplify/graphql-types-generator": "2.8.6",
26-
"@graphql-codegen/core": "1.8.3",
26+
"@graphql-codegen/core": "2.3.0",
2727
"amplify-codegen-appsync-model-plugin": "^1.22.3",
2828
"amplify-graphql-docs-generator": "^2.2.1",
2929
"amplify-graphql-types-generator": "^2.7.0",

packages/amplify-codegen/src/commands/models.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ async function generateModels(context) {
141141
appsyncLocalConfig.forEach((cfg, idx) => {
142142
const outPutPath = cfg.filename;
143143
fs.ensureFileSync(outPutPath);
144-
fs.writeFileSync(outPutPath, generatedCode[idx]);
144+
const contentsToWrite = [getVersionsMetadataComment(context), generatedCode[idx]].filter(content => content);
145+
const contentToWrite = contentsToWrite.join('\n\n');
146+
fs.writeFileSync(outPutPath, contentToWrite);
145147
});
146148

147149
generateEslintIgnore(context);
@@ -197,6 +199,29 @@ function getModelOutputPath(context) {
197199
}
198200
}
199201

202+
// Generate a Comment string with Amplify CLI and Amplify Codegen version metadata
203+
function getVersionsMetadataComment(context) {
204+
const versionMetadata = [];
205+
if (context.usageData && context.usageData.version) {
206+
versionMetadata.push('amplify-cli-version: ' + context.usageData.version);
207+
}
208+
209+
if (context.pluginPlatform && context.pluginPlatform.plugins) {
210+
const codegenPluginsInfo = context.pluginPlatform.plugins.codegen;
211+
if (codegenPluginsInfo && codegenPluginsInfo.length > 0) {
212+
const amplifyCodegenPluginInfo = codegenPluginsInfo.filter(plugin => plugin.packageName == 'amplify-codegen');
213+
if (amplifyCodegenPluginInfo && amplifyCodegenPluginInfo.length > 0 && amplifyCodegenPluginInfo[0].packageVersion) {
214+
versionMetadata.push('amplify-codegen-version: ' + amplifyCodegenPluginInfo[0].packageVersion);
215+
}
216+
}
217+
}
218+
219+
if (versionMetadata.length > 0) {
220+
return '// Generated using ' + versionMetadata.join(', ');
221+
}
222+
return null;
223+
}
224+
200225
function generateEslintIgnore(context) {
201226
const projectConfig = context.amplify.getProjectConfig();
202227

0 commit comments

Comments
 (0)