Skip to content

Commit 96b48f8

Browse files
author
Craigory Coppola
committed
feat(core): Set output path in generated project files
1 parent 6a58d34 commit 96b48f8

File tree

7 files changed

+105
-25
lines changed

7 files changed

+105
-25
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "nx-dotnet",
33
"license": "MIT",
4-
"version": "0.1.5-dev.9",
4+
"version": "0.1.5-dev.10",
55
"scripts": {
66
"nx": "nx",
77
"start": "nx serve",

packages/core/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
"private": false,
77
"dependencies": {
88
"chokidar": "^3.5.1",
9-
"@nx-dotnet/dotnet": "0.1.5-dev.9",
10-
"@nx-dotnet/utils": "0.1.5-dev.9",
9+
"@nx-dotnet/dotnet": "0.1.5-dev.10",
10+
"@nx-dotnet/utils": "0.1.5-dev.10",
1111
"xmldoc": "^1.1.2"
1212
},
13-
"version": "0.1.5-dev.9"
13+
"version": "0.1.5-dev.10"
1414
}

packages/core/src/generators/utils/generate-project.ts

Lines changed: 77 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
import {
2-
addProjectConfiguration, formatFiles, getWorkspaceLayout, names, NxJsonProjectConfiguration,
3-
ProjectConfiguration, ProjectType, Tree
2+
addProjectConfiguration,
3+
formatFiles,
4+
getWorkspaceLayout,
5+
names,
6+
NxJsonProjectConfiguration,
7+
ProjectConfiguration,
8+
ProjectType,
9+
Tree,
410
} from '@nrwl/devkit';
511

612
import { DotNetClient, dotnetNewOptions } from '@nx-dotnet/dotnet';
713
import { findProjectFileInPath, isDryRun } from '@nx-dotnet/utils';
14+
import { readFileSync, writeFileSync } from 'fs';
15+
import { XmlDocument, XmlNode, XmlTextNode } from 'xmldoc';
16+
import { relative, dirname } from 'path';
817

918
import {
10-
GetBuildExecutorConfiguration, GetServeExecutorConfig, GetTestExecutorConfig,
11-
NxDotnetProjectGeneratorSchema
19+
GetBuildExecutorConfiguration,
20+
GetServeExecutorConfig,
21+
GetTestExecutorConfig,
22+
NxDotnetProjectGeneratorSchema,
1223
} from '../../models';
1324
import initSchematic from '../init/generator';
1425

@@ -71,7 +82,7 @@ async function GenerateTestProject(
7182
sourceRoot: `${testRoot}`,
7283
targets: {
7384
build: GetBuildExecutorConfiguration(testName),
74-
test: GetTestExecutorConfig()
85+
test: GetTestExecutorConfig(),
7586
},
7687
tags: schema.parsedTags,
7788
});
@@ -98,16 +109,50 @@ async function GenerateTestProject(
98109
}
99110

100111
dotnetClient.new(schema['test-template'], newParams);
101-
112+
102113
if (!isDryRun()) {
103114
const testCsProj = await findProjectFileInPath(testRoot);
115+
SetOutputPath(host, testProjectName, testCsProj);
104116
const baseCsProj = await findProjectFileInPath(schema.projectRoot);
117+
SetOutputPath(host, schema.projectName, baseCsProj);
105118
dotnetClient.addProjectReference(testCsProj, baseCsProj);
106-
}
119+
}
120+
}
107121

122+
function SetOutputPath(
123+
host: Tree,
124+
projectName: string,
125+
projectFilePath: string
126+
): void {
127+
const xml: XmlDocument = new XmlDocument(
128+
readFileSync(projectFilePath).toString()
129+
);
130+
131+
const textNode: Partial<XmlTextNode> = {
132+
text: `${relative(dirname(projectFilePath), process.cwd())}\\dist\\${projectName}`,
133+
type: 'text'
134+
};
135+
textNode.toString = () => textNode.text ?? '';
136+
textNode.toStringWithIndent = () => textNode.text ?? '';
137+
138+
const el: Partial<XmlNode> = {
139+
name: 'OutputPath',
140+
attr: {},
141+
type: 'element',
142+
children: [textNode as XmlTextNode],
143+
firstChild: null,
144+
lastChild: null
145+
};
146+
147+
el.toStringWithIndent = xml.toStringWithIndent.bind(el);
148+
el.toString = xml.toString.bind(el);
149+
150+
xml.childNamed('PropertyGroup')?.children.push(el as XmlNode);
151+
152+
writeFileSync(projectFilePath, xml.toString());
108153
}
109154

110-
export async function GenerateProject (
155+
export async function GenerateProject(
111156
host: Tree,
112157
options: NxDotnetProjectGeneratorSchema,
113158
dotnetClient: DotNetClient,
@@ -119,22 +164,29 @@ export async function GenerateProject (
119164

120165
const normalizedOptions = normalizeOptions(host, options, projectType);
121166

122-
const projectConfiguration: ProjectConfiguration & NxJsonProjectConfiguration = {
167+
const projectConfiguration: ProjectConfiguration &
168+
NxJsonProjectConfiguration = {
123169
root: normalizedOptions.projectRoot,
124170
projectType: projectType,
125171
sourceRoot: `${normalizedOptions.projectRoot}`,
126172
targets: {
127173
build: GetBuildExecutorConfiguration(normalizedOptions.name),
128-
serve: GetServeExecutorConfig()
174+
serve: GetServeExecutorConfig(),
129175
},
130176
tags: normalizedOptions.parsedTags,
131-
}
177+
};
132178

133179
if (options['test-template'] !== 'none') {
134-
projectConfiguration.targets.test = GetTestExecutorConfig(normalizedOptions.projectName + '-test')
180+
projectConfiguration.targets.test = GetTestExecutorConfig(
181+
normalizedOptions.projectName + '-test'
182+
);
135183
}
136184

137-
addProjectConfiguration(host, normalizedOptions.projectName, projectConfiguration);
185+
addProjectConfiguration(
186+
host,
187+
normalizedOptions.projectName,
188+
projectConfiguration
189+
);
138190

139191
const newParams: dotnetNewOptions = [
140192
{
@@ -160,7 +212,18 @@ export async function GenerateProject (
160212
dotnetClient.new(normalizedOptions.template, newParams);
161213

162214
if (options['test-template'] !== 'none') {
163-
await GenerateTestProject(normalizedOptions, host, dotnetClient, projectType);
215+
await GenerateTestProject(
216+
normalizedOptions,
217+
host,
218+
dotnetClient,
219+
projectType
220+
);
221+
} else {
222+
SetOutputPath(
223+
host,
224+
normalizedOptions.projectName,
225+
await findProjectFileInPath(normalizedOptions.projectRoot)
226+
);
164227
}
165228

166229
await formatFiles(host);

packages/dotnet/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"private": false,
44
"main": "src/index.js",
55
"dependencies": {
6-
"@nx-dotnet/utils": "0.1.5-dev.9"
6+
"@nx-dotnet/utils": "0.1.5-dev.10"
77
},
8-
"version": "0.1.5-dev.9"
8+
"version": "0.1.5-dev.10"
99
}
Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
export type dotnetTestFlags =
2-
| 'test-adapter-path'
3-
| 'blame'
2+
| 'blame-crash-collect-always'
3+
| 'blame-crash-dump-type'
44
| 'blame-crash'
5-
| 'blame-crash-dump-type';
5+
| 'blame-hang-dump'
6+
| 'blame-hang-timeout'
7+
| 'blame-hang'
8+
| 'blame'
9+
| 'collect'
10+
| 'configuration'
11+
| 'diag'
12+
| 'filter'
13+
| 'framework'
14+
| 'list-tests'
15+
| 'logger'
16+
| 'no-build'
17+
| 'no-restore'
18+
| 'nologo'
19+
| 'results-directory'
20+
| 'settings'
21+
| 'test-adapter-path'
22+
| 'verbosity';

packages/typescript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
"main": "src/index.js",
44
"generators": "./generators.json",
55
"executors": "./executors.json",
6-
"version": "0.1.5-dev.9"
6+
"version": "0.1.5-dev.10"
77
}

packages/utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
"rimraf": "^3.0.2",
88
"xmldoc": "^1.1.2"
99
},
10-
"version": "0.1.5-dev.9"
10+
"version": "0.1.5-dev.10"
1111
}

0 commit comments

Comments
 (0)