Skip to content

Commit

Permalink
feat(sdk): generate GitAttributes file ignoring generated files (#2214)
Browse files Browse the repository at this point in the history
## Proposed change

Generate GitAttributes file ignoring generated files
  • Loading branch information
kpanot authored Oct 2, 2024
2 parents 96dc5ce + f678898 commit 620c7db
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/@ama-sdk/schematics/migration.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
"version": "11.0.0-alpha.0",
"description": "Updates of @ama-sdk/schematics to v11.0.*",
"factory": "./schematics/ng-update/index#updateV11_0"
},
"migration-v11_4": {
"version": "11.4.0-alpha.0",
"description": "Updates of @ama-sdk/schematics to v11.4.*",
"factory": "./schematics/ng-update/index#updateV11_4"
}
}
}
4 changes: 4 additions & 0 deletions packages/@ama-sdk/schematics/schematics/migrate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ import { updateRegenScript } from '../ng-update/typescript/v11.0/update-regen-sc
import { gt, minVersion } from 'semver';
import { isTypescriptSdk } from '../helpers/is-typescript-project';
import {updateOpenApiVersionInProject} from '../ng-update/typescript/v10.3/update-openapiversion';
import { updateV11_4 as updateV114 } from '../ng-update/typescript';

/* eslint-disable @typescript-eslint/naming-convention */
const tsMigrationMap: MigrationRulesMap = {
'~10.3.2': updateOpenApiVersionInProject(),
'11.0.*': [
updateRegenScript
],
'11.4.0-alpha.0': [
updateV114
]
};
/* eslint-enable @typescript-eslint/naming-convention */
Expand Down
16 changes: 15 additions & 1 deletion packages/@ama-sdk/schematics/schematics/ng-update/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
updateV10_0 as tsUpdateV10_0,
updateV10_1 as tsUpdateV10_1,
updateV10_3 as tsUpdateV10_3,
updateV11_0 as tsUpdateV11_0
updateV11_0 as tsUpdateV11_0,
updateV11_4 as tsUpdateV11_4
} from './typescript';
import { isTypescriptSdk } from '../helpers/is-typescript-project';

Expand Down Expand Up @@ -61,3 +62,16 @@ export function updateV11_0(): Rule {
return tree;
};
}

/**
* update of Otter library V11.4
*/
export function updateV11_4(): Rule {
return (tree, context) => {
if (isTypescriptSdk(tree)) {
return tsUpdateV11_4()(tree, context);
}

return tree;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { addPresetsRenovate } from './v10.1/add-presets-renovate';
import { updateOpenApiVersionInProject } from './v10.3/update-openapiversion';
import { updateRegenScript } from './v11.0/update-regen-script';
import { updateOpenapitoolsFile } from './v11.0/update-openapitools';
import { createGitAttributesFile } from './v11.4/create-gitattributes';

/**
* update of Otter library V10.0
Expand Down Expand Up @@ -54,3 +55,14 @@ export function updateV11_0(): Rule {

return chain(updateRules);
}

/**
* Update of Ama-sdk library V11.4
*/
export function updateV11_4(): Rule {
const updateRules: Rule[] = [
createGitAttributesFile
];

return chain(updateRules);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { Rule } from '@angular-devkit/schematics';

/**
* Create a default git attributes file (if it does not already exist)
* @param tree
*/
export const createGitAttributesFile: Rule = (tree) => {
const gitAttributesFilePath = '.gitattributes';
if (!tree.exists(gitAttributesFilePath)) {
tree.create(gitAttributesFilePath, `# Generated files
src/api/** linguist-generated
src/spec/api-mocks.ts linguist-generated
src/spec/operation-adapter.ts linguist-generated
# uncomment the following line if there is no core model:
# src/models/base/** linguist-generated
# in case of core models, the \`index.ts\` file should be ignored as follows:
# !src/models/base/<model>/index.ts
`);
}

return tree;
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const baseFileList = [
'/.editorconfig',
'/.eslintignore',
'/.eslintrc.js',
'/.gitattributes',
'/.gitignore',
'/.openapi-generator-ignore',
'/.renovaterc.json',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Generated files
src/spec/api-mocks.ts linguist-generated
src/spec/operation-adapter.ts linguist-generated
src/api/** linguist-generated
src/models/base/** linguist-generated

# in case of core models, the `index.ts` file should be ignored as follows:
# !src/models/base/<model>/index.ts

0 comments on commit 620c7db

Please sign in to comment.