Skip to content

Commit

Permalink
fix(amplify-codegen): generate eslintignore in js (#5865)
Browse files Browse the repository at this point in the history
  • Loading branch information
iartemiev authored Nov 19, 2020
1 parent c82d642 commit baa8a6f
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion packages/amplify-codegen/src/commands/models.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require('path');
const { parse } = require('graphql');
const { readFileSync, writeFileSync, ensureFileSync, pathExistsSync, lstatSync, readdirSync } = require('fs-extra');
const { readFileSync, writeFileSync, ensureFileSync, pathExistsSync, lstatSync, readdirSync, appendFileSync } = require('fs-extra');
const gqlCodeGen = require('@graphql-codegen/core');

const appSyncDataStoreCodeGen = require('amplify-codegen-appsync-model-plugin');
Expand Down Expand Up @@ -70,6 +70,7 @@ async function generateModels(context) {
ensureFileSync(outPutPath);
writeFileSync(outPutPath, generatedCode[idx]);
});
generateEslintIgnore(context);
context.print.info(`Successfully generated models. Generated models can be found ${outputPath}`);
}

Expand Down Expand Up @@ -116,4 +117,26 @@ function getModelOutputPath(context) {
return '.';
}
}

function generateEslintIgnore(context) {
const projectConfig = context.amplify.getProjectConfig();
if (projectConfig.frontend !== 'javascript') {
return;
}

const { projectPath } = context.amplify.getEnvInfo();
const eslintIgnorePath = path.join(projectPath, '.eslintignore');
const modelFolder = path.join(getModelOutputPath(context), 'models');

if (!pathExistsSync(eslintIgnorePath)) {
writeFileSync(eslintIgnorePath, modelFolder);
return;
}

const eslintContents = readFileSync(eslintIgnorePath);

if (!eslintContents.includes(modelFolder)) {
appendFileSync(eslintIgnorePath, `\n${modelFolder}`);
}
}
module.exports = generateModels;

0 comments on commit baa8a6f

Please sign in to comment.