Skip to content

Commit

Permalink
fix(core): adjust gitignore to support generation with directory (#599)
Browse files Browse the repository at this point in the history
- include typo fix

Co-authored-by: Chris Leigh <chris.leigh@sbdinc.com>
  • Loading branch information
Tungsten78 and Chris Leigh authored Feb 3, 2023
1 parent 93a7357 commit b3856e0
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 35 deletions.
2 changes: 1 addition & 1 deletion docs/core/generators/application.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ Generate a dotnet project under the application directory.

### useNxPluginOpenAPI

- (boolean): If using a codgen project, use openapi-generator
- (boolean): If using a codegen project, use openapi-generator
2 changes: 1 addition & 1 deletion packages/core/src/generators/app/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
},
"useNxPluginOpenAPI": {
"type": "boolean",
"description": "If using a codgen project, use openapi-generator"
"description": "If using a codegen project, use openapi-generator"
}
},
"required": ["name", "language"]
Expand Down
7 changes: 0 additions & 7 deletions packages/core/src/generators/init/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ describe('init generator', () => {
expect(config).toBeTruthy();
});

it('should update gitignore', async () => {
appTree.write('.gitignore', '');
await generator(appTree, null, dotnetClient);
const gitignoreValue = appTree.read('.gitignore')?.toString();
expect(gitignoreValue).toBeTruthy();
});

it('should put dependency array inside config', async () => {
await generator(appTree, null, dotnetClient);
const config: NxDotnetConfig = readJson(appTree, CONFIG_FILE_PATH);
Expand Down
26 changes: 0 additions & 26 deletions packages/core/src/generators/init/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import {
normalizePath,
NxJsonConfiguration,
readJson,
readWorkspaceConfiguration,
Tree,
WorkspaceConfiguration,
writeJson,
} from '@nrwl/devkit';

Expand Down Expand Up @@ -43,7 +41,6 @@ export async function initGenerator(
updateNxJson(host);

if (!initialized) {
updateGitIgnore(host, readWorkspaceConfiguration(host));
addPrepareScript(host);
tasks.push(installNpmPackages(host));
}
Expand Down Expand Up @@ -75,29 +72,6 @@ function installNpmPackages(host: Tree): GeneratorCallback {
);
}

function updateGitIgnore(
host: Tree,
workspaceConfiguration: WorkspaceConfiguration,
) {
if (!host.isFile('.gitignore')) {
return;
}
let lines = (host.read('.gitignore') ?? '').toString();
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);
}

function updateNxJson(host: Tree) {
const nxJson: NxJsonConfiguration = readJson(host, 'nx.json');
nxJson.plugins = nxJson.plugins || [];
Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/generators/utils/generate-project.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { readProjectConfiguration, Tree, writeJson } from '@nrwl/devkit';
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';

import { DotNetClient, mockDotnetFactory } from '@nx-dotnet/dotnet';
import path = require('path');

import { NxDotnetProjectGeneratorSchema } from '../../models';
import { GenerateProject } from './generate-project';
Expand Down Expand Up @@ -138,4 +139,13 @@ describe('nx-dotnet project generator', () => {
).toBeDefined();
});
});

it('should create .gitignore', async () => {
await GenerateProject(appTree, options, dotnetClient, 'application');
const config = readProjectConfiguration(appTree, options.name);
const gitignoreValue = appTree
.read(path.join(config.root, '.gitignore'))
?.toString();
expect(gitignoreValue).toBeTruthy();
});
});
10 changes: 10 additions & 0 deletions packages/core/src/generators/utils/generate-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ export async function GenerateProject(
);
}

createGitIgnore(host, normalizedOptions.projectRoot);

await formatFiles(host);

return async () => {
Expand All @@ -246,6 +248,14 @@ export async function GenerateProject(
};
}

function createGitIgnore(host: Tree, projectRoot: string) {
const gitIgnorePath = normalizePath(
joinPathFragments(projectRoot, '.gitignore'),
);

host.write(gitIgnorePath, `[Bb]in/\n[Oo]bj/`);
}

export function addPrebuildMsbuildTask(
host: Tree,
options: { projectRoot: string; projectName: string },
Expand Down

0 comments on commit b3856e0

Please sign in to comment.