Skip to content

Commit

Permalink
fix: ignore files when generating with yarn (#939)
Browse files Browse the repository at this point in the history
## Proposed change
- updates on _gitignore_ when package manager is yarn
- sdk generator in monorepo to not touch yarn config

<!-- Please include a summary of the changes and the related issue.
Please also include relevant motivation and context. List any
dependencies that is required for this change. -->

## Related issues

- 🐛 Fixes #(issue)
- 🚀 Feature #(issue)

<!-- Please make sure to follow the contributing guidelines on
https://github.com/amadeus-digital/Otter/blob/main/CONTRIBUTING.md -->
  • Loading branch information
mrednic-1A authored Oct 23, 2023
2 parents e1c2c8c + d294ae1 commit 4874a36
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/.env

### yarn ###
# https://yarnpkg.com/advanced/qa#which-files-should-be-gitignored
# https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored

.yarn/*
!.yarn/releases
Expand Down
5 changes: 3 additions & 2 deletions packages/@o3r/core/schematics/ng-add/project-setup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export const prepareProject = (options: NgAddSchematicsSchema) => async (tree: T
readPackageJson, removePackages, renamedPackagesV7toV8, updateImports, isMultipackagesContext, getO3rPeerDeps
} = await import('@o3r/schematics');
const installOtterLinter = await shouldOtterLinterBeInstalled(context);
const workspaceProject = options.projectName && getWorkspaceConfig(tree)?.projects?.[options.projectName] || undefined;
const workspaceConfig = getWorkspaceConfig(tree);
const workspaceProject = options.projectName && workspaceConfig?.projects?.[options.projectName] || undefined;
const projectType = workspaceProject?.projectType;
const depsInfo = getO3rPeerDeps(corePackageJsonPath);
const internalPackagesToInstallWithNgAdd = Array.from(new Set([
Expand Down Expand Up @@ -105,7 +106,7 @@ export const prepareProject = (options: NgAddSchematicsSchema) => async (tree: T
];
}
const commonRules = [
genericUpdates(),
genericUpdates(workspaceConfig),
o3rBasicUpdates(options.projectName, o3rCoreVersion, projectType),
ngAddPackages(internalPackagesToInstallWithNgAdd,
{ skipConfirmation: true, version: o3rCoreVersion, parentPackageInfo: '@o3r/core - setup', projectName: options.projectName, dependencyType: type, workingDirectory: projectDirectory }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import type { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
import { getPackageManager, WorkspaceSchema } from '@o3r/schematics';

/**
* Generic basic updates to be done on a repository
*
* @param workspaceConfig
*/
export function genericUpdates(): Rule {
export function genericUpdates(workspaceConfig?: WorkspaceSchema | null): Rule {

const updateGitIgnore = (tree: Tree, _context: SchematicContext) => {
// update gitignore
Expand All @@ -20,6 +23,29 @@ ${folderToExclude}
`;
}
});
const packageManager = getPackageManager({workspaceConfig});
if (packageManager === 'yarn') {
gitignore += `
### yarn ###
# https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored
.yarn/*
!.yarn/releases
!.yarn/patches
!.yarn/plugins
!.yarn/sdks
!.yarn/versions
# if you are NOT using Zero-installs, then:
# comment the following lines
# !.yarn/cache
# and uncomment the following lines
.pnp.*
`;
}
tree.overwrite('/.gitignore', gitignore);
}
return tree;
Expand Down
18 changes: 16 additions & 2 deletions packages/@o3r/core/schematics/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,29 @@ export function generateSdk(options: NgGenerateSdkSchema): Rule {
renameTemplateFiles()
]), MergeStrategy.Overwrite);

const packageManager = getPackageManager({ workspaceConfig });
const yarnrcPath = '.yarnrc.yml';
const yarnrcBeforeSdkGeneration = tree.exists(yarnrcPath) ? tree.readText(yarnrcPath) : '';

return chain([
externalSchematic<NgGenerateTypescriptSDKShellSchematicsSchema>('@ama-sdk/schematics', 'typescript-shell', {
...options,
package: projectName,
name: scope,
directory: targetPath,
packageManager: getPackageManager({workspaceConfig}),
packageManager,
skipInstall: !!options.specPath || options.skipInstall
}),
packageManager === 'yarn' ? (t) => {
if (yarnrcBeforeSdkGeneration) {
// discard changes done by sdk shell generator standalone on yarnrc
t.overwrite(yarnrcPath, yarnrcBeforeSdkGeneration);
} else {
// delete yarnrc created by sdk shell generator standalone
t.delete(yarnrcPath);
}
return t;
} : noop,
isNx ? nxRegisterProjectTasks(options, targetPath, cleanName) : ngRegisterProjectTasks(options, targetPath, cleanName),
updateTsConfig(targetPath, projectName, scope),
cleanStandaloneFiles(targetPath),
Expand All @@ -58,7 +72,7 @@ export function generateSdk(options: NgGenerateSdkSchema): Rule {
...options,
specPath: options.specPath,
directory: targetPath,
packageManager: getPackageManager({workspaceConfig})
packageManager
}), [installTaskId]);
} : noop
])(tree, context);
Expand Down

0 comments on commit 4874a36

Please sign in to comment.