Skip to content

Commit

Permalink
feat(core): Set output path in generated project files
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Apr 21, 2021
1 parent 6a58d34 commit 96b48f8
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "nx-dotnet",
"license": "MIT",
"version": "0.1.5-dev.9",
"version": "0.1.5-dev.10",
"scripts": {
"nx": "nx",
"start": "nx serve",
Expand Down
6 changes: 3 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"private": false,
"dependencies": {
"chokidar": "^3.5.1",
"@nx-dotnet/dotnet": "0.1.5-dev.9",
"@nx-dotnet/utils": "0.1.5-dev.9",
"@nx-dotnet/dotnet": "0.1.5-dev.10",
"@nx-dotnet/utils": "0.1.5-dev.10",
"xmldoc": "^1.1.2"
},
"version": "0.1.5-dev.9"
"version": "0.1.5-dev.10"
}
91 changes: 77 additions & 14 deletions packages/core/src/generators/utils/generate-project.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
import {
addProjectConfiguration, formatFiles, getWorkspaceLayout, names, NxJsonProjectConfiguration,
ProjectConfiguration, ProjectType, Tree
addProjectConfiguration,
formatFiles,
getWorkspaceLayout,
names,
NxJsonProjectConfiguration,
ProjectConfiguration,
ProjectType,
Tree,
} from '@nrwl/devkit';

import { DotNetClient, dotnetNewOptions } from '@nx-dotnet/dotnet';
import { findProjectFileInPath, isDryRun } from '@nx-dotnet/utils';
import { readFileSync, writeFileSync } from 'fs';
import { XmlDocument, XmlNode, XmlTextNode } from 'xmldoc';
import { relative, dirname } from 'path';

import {
GetBuildExecutorConfiguration, GetServeExecutorConfig, GetTestExecutorConfig,
NxDotnetProjectGeneratorSchema
GetBuildExecutorConfiguration,
GetServeExecutorConfig,
GetTestExecutorConfig,
NxDotnetProjectGeneratorSchema,
} from '../../models';
import initSchematic from '../init/generator';

Expand Down Expand Up @@ -71,7 +82,7 @@ async function GenerateTestProject(
sourceRoot: `${testRoot}`,
targets: {
build: GetBuildExecutorConfiguration(testName),
test: GetTestExecutorConfig()
test: GetTestExecutorConfig(),
},
tags: schema.parsedTags,
});
Expand All @@ -98,16 +109,50 @@ async function GenerateTestProject(
}

dotnetClient.new(schema['test-template'], newParams);

if (!isDryRun()) {
const testCsProj = await findProjectFileInPath(testRoot);
SetOutputPath(host, testProjectName, testCsProj);
const baseCsProj = await findProjectFileInPath(schema.projectRoot);
SetOutputPath(host, schema.projectName, baseCsProj);
dotnetClient.addProjectReference(testCsProj, baseCsProj);
}
}
}

function SetOutputPath(
host: Tree,
projectName: string,
projectFilePath: string
): void {
const xml: XmlDocument = new XmlDocument(
readFileSync(projectFilePath).toString()
);

const textNode: Partial<XmlTextNode> = {
text: `${relative(dirname(projectFilePath), process.cwd())}\\dist\\${projectName}`,
type: 'text'
};
textNode.toString = () => textNode.text ?? '';
textNode.toStringWithIndent = () => textNode.text ?? '';

const el: Partial<XmlNode> = {
name: 'OutputPath',
attr: {},
type: 'element',
children: [textNode as XmlTextNode],
firstChild: null,
lastChild: null
};

el.toStringWithIndent = xml.toStringWithIndent.bind(el);
el.toString = xml.toString.bind(el);

xml.childNamed('PropertyGroup')?.children.push(el as XmlNode);

writeFileSync(projectFilePath, xml.toString());
}

export async function GenerateProject (
export async function GenerateProject(
host: Tree,
options: NxDotnetProjectGeneratorSchema,
dotnetClient: DotNetClient,
Expand All @@ -119,22 +164,29 @@ export async function GenerateProject (

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

const projectConfiguration: ProjectConfiguration & NxJsonProjectConfiguration = {
const projectConfiguration: ProjectConfiguration &
NxJsonProjectConfiguration = {
root: normalizedOptions.projectRoot,
projectType: projectType,
sourceRoot: `${normalizedOptions.projectRoot}`,
targets: {
build: GetBuildExecutorConfiguration(normalizedOptions.name),
serve: GetServeExecutorConfig()
serve: GetServeExecutorConfig(),
},
tags: normalizedOptions.parsedTags,
}
};

if (options['test-template'] !== 'none') {
projectConfiguration.targets.test = GetTestExecutorConfig(normalizedOptions.projectName + '-test')
projectConfiguration.targets.test = GetTestExecutorConfig(
normalizedOptions.projectName + '-test'
);
}

addProjectConfiguration(host, normalizedOptions.projectName, projectConfiguration);
addProjectConfiguration(
host,
normalizedOptions.projectName,
projectConfiguration
);

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

if (options['test-template'] !== 'none') {
await GenerateTestProject(normalizedOptions, host, dotnetClient, projectType);
await GenerateTestProject(
normalizedOptions,
host,
dotnetClient,
projectType
);
} else {
SetOutputPath(
host,
normalizedOptions.projectName,
await findProjectFileInPath(normalizedOptions.projectRoot)
);
}

await formatFiles(host);
Expand Down
4 changes: 2 additions & 2 deletions packages/dotnet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": false,
"main": "src/index.js",
"dependencies": {
"@nx-dotnet/utils": "0.1.5-dev.9"
"@nx-dotnet/utils": "0.1.5-dev.10"
},
"version": "0.1.5-dev.9"
"version": "0.1.5-dev.10"
}
23 changes: 20 additions & 3 deletions packages/dotnet/src/lib/models/dotnet-test/dotnet-test-flags.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
export type dotnetTestFlags =
| 'test-adapter-path'
| 'blame'
| 'blame-crash-collect-always'
| 'blame-crash-dump-type'
| 'blame-crash'
| 'blame-crash-dump-type';
| 'blame-hang-dump'
| 'blame-hang-timeout'
| 'blame-hang'
| 'blame'
| 'collect'
| 'configuration'
| 'diag'
| 'filter'
| 'framework'
| 'list-tests'
| 'logger'
| 'no-build'
| 'no-restore'
| 'nologo'
| 'results-directory'
| 'settings'
| 'test-adapter-path'
| 'verbosity';
2 changes: 1 addition & 1 deletion packages/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"main": "src/index.js",
"generators": "./generators.json",
"executors": "./executors.json",
"version": "0.1.5-dev.9"
"version": "0.1.5-dev.10"
}
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"rimraf": "^3.0.2",
"xmldoc": "^1.1.2"
},
"version": "0.1.5-dev.9"
"version": "0.1.5-dev.10"
}

0 comments on commit 96b48f8

Please sign in to comment.