Skip to content

Commit

Permalink
fix(core): #38 - Misc fixes for .gitignore updates (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder authored May 6, 2021
1 parent 62f42a1 commit 5f2d5c9
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions packages/core/src/generators/init/generator.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {
formatFiles,
NxJsonConfiguration,
readJson,
readWorkspaceConfiguration,
Tree,
WorkspaceConfiguration,
writeJson,
} from '@nrwl/devkit';

Expand All @@ -22,17 +23,31 @@ export default async function (host: Tree) {
host.write(CONFIG_FILE_PATH, JSON.stringify(configObject, null, 2));

updateNxJson(host);
updateGitIgnore(host);
await formatFiles(host);
if (!initialized) {
updateGitIgnore(host, readWorkspaceConfiguration(host));
}
}

function updateGitIgnore(host: Tree) {
function updateGitIgnore(
host: Tree,
workspaceConfiguration: WorkspaceConfiguration,
) {
if (!host.isFile('.gitignore')) {
return;
}
let lines = (host.read('.gitignore') ?? '').toString();
lines += '\r\napps/*/bin';
lines += '\r\napps/*/obj';
lines += `\n${
workspaceConfiguration.workspaceLayout?.appsDir || 'apps'
}/*/bin`;
lines += `\n${
workspaceConfiguration.workspaceLayout?.appsDir || 'apps'
}/*/obj`;
lines += `\n${
workspaceConfiguration.workspaceLayout?.libsDir || 'libs'
}/*/bin`;
lines += `\n${
workspaceConfiguration.workspaceLayout?.libsDir || 'libs'
}/*/obj`;
host.write('.gitignore', lines);
}

Expand Down

0 comments on commit 5f2d5c9

Please sign in to comment.