@nx-dotnet/core
Version:
- Have an existing nx workspace. For creating this, see [nrwl's documentation](https://nx.dev/latest/angular/getting-started/nx-setup). - .NET SDK is installed, and `dotnet` is available on the path. For help on this, see [Microsoft's documentation](https
72 lines • 3.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.normalizeOptions = normalizeOptions;
exports.default = default_1;
exports.calculateTestTargetNameAndRoot = calculateTestTargetNameAndRoot;
const devkit_1 = require("@nx/devkit");
const path_1 = require("path");
const dotnet_1 = require("@nx-dotnet/dotnet");
const utils_1 = require("@nx-dotnet/utils");
const models_1 = require("../../models");
const add_to_sln_1 = require("../utils/add-to-sln");
const dotnet_add_1 = require("../utils/dotnet-add");
const dotnet_new_1 = require("../utils/dotnet-new");
const project_configuration_1 = require("../utils/project-configuration");
function normalizeOptions(schema) {
return {
...schema,
suffix: schema.suffix ?? (schema.pathScheme === 'nx' ? 'test' : 'Test'),
};
}
async function default_1(host, rawSchema, dotnetClient = new dotnet_1.DotNetClient((0, dotnet_1.dotnetFactory)())) {
const schema = normalizeOptions(rawSchema);
const targetProject = await (0, project_configuration_1.readProjectConfiguration)(host, schema.targetProject);
const targetProjectRoot = targetProject.root;
const targetProjectName = schema.targetProject;
const { name: testProjectName, root: testRoot } = calculateTestTargetNameAndRoot(schema.pathScheme, targetProjectName, targetProjectRoot, schema.testProjectName, schema.suffix);
if (!(0, utils_1.isNxCrystalEnabled)()) {
(0, devkit_1.addProjectConfiguration)(host, testProjectName, {
root: testRoot,
projectType: 'library',
sourceRoot: `${testRoot}`,
targets: {
build: (0, models_1.GetBuildExecutorConfiguration)(testRoot),
test: (0, models_1.GetTestExecutorConfig)(),
lint: (0, models_1.GetLintExecutorConfiguration)(),
},
tags: schema.tags
? Array.isArray(schema.tags)
? schema.tags
: schema.tags.split(',').map((tag) => tag.trim())
: [],
});
}
const baseCsProj = await (0, utils_1.findProjectFileInPath)(targetProjectRoot, host);
const baseNamespace = (0, path_1.basename)(baseCsProj).replace(/\.(csproj|vbproj|fsproj)$/, '');
const name = schema.namespaceName ??
[baseNamespace, (0, devkit_1.names)(schema.suffix).className].filter(Boolean).join('.');
const newParams = {
language: schema.language,
name,
output: testRoot,
};
(0, dotnet_new_1.runDotnetNew)(host, dotnetClient, schema.testTemplate, newParams);
(0, add_to_sln_1.addToSolutionFile)(host, testRoot, dotnetClient, schema.solutionFile);
const testCsProj = await (0, utils_1.findProjectFileInPath)(testRoot, host);
(0, dotnet_add_1.runDotnetAddProjectReference)(host, testCsProj, baseCsProj, dotnetClient);
if (!schema.skipFormat) {
await (0, devkit_1.formatFiles)(host);
}
}
function calculateTestTargetNameAndRoot(pathScheme, targetProjectName, targetProjectRoot, testProjectName, suffix) {
const nameSeperator = pathScheme === 'nx' ? '-' : '.';
const nameParts = targetProjectName.split(nameSeperator);
suffix = suffix ?? (pathScheme === 'nx' ? 'test' : 'Test');
const name = (testProjectName =
testProjectName ?? nameParts.concat([suffix]).join(nameSeperator));
return {
root: [targetProjectRoot, suffix].join(nameSeperator),
name,
};
}
//# sourceMappingURL=generator.js.map