@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
87 lines • 4.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.readProjectConfiguration = readProjectConfiguration;
exports.updateProjectConfiguration = updateProjectConfiguration;
exports.readProjectJson = readProjectJson;
exports.readInferredProjectConfiguration = readInferredProjectConfiguration;
const devkit_1 = require("@nx/devkit");
const workspace_context_1 = require("nx/src/utils/workspace-context");
const create_nodes_1 = require("../../graph/create-nodes");
const project_configuration_utils_1 = require("nx/src/project-graph/utils/project-configuration-utils");
const utils_1 = require("@nx-dotnet/utils");
const try_read_json_1 = require("./try-read-json");
async function readProjectConfiguration(tree, name, root) {
const projectJson = readProjectJson(tree, name);
const inferredProject = await readInferredProjectConfiguration(tree, name, root);
if (projectJson && inferredProject) {
const rootMap = {};
(0, project_configuration_utils_1.mergeProjectConfigurationIntoRootMap)(rootMap, inferredProject, undefined, undefined, true);
(0, project_configuration_utils_1.mergeProjectConfigurationIntoRootMap)(rootMap, projectJson, undefined, undefined, true);
return (0, project_configuration_utils_1.readProjectConfigurationsFromRootMap)(rootMap)[name];
}
if (projectJson)
return projectJson;
if (inferredProject)
return inferredProject;
throw new Error(`Project ${name} not found. Found projects: ${Object.keys((await getNxDotnetProjects(tree)).projects)}`);
}
async function updateProjectConfiguration(tree, name, root, update) {
const projectJsonConfiguration = readProjectJson(tree, name);
const inferredConfiguration = await readInferredProjectConfiguration(tree, name, root);
const updatedProjectJson = update(projectJsonConfiguration, inferredConfiguration);
if (projectJsonConfiguration) {
(0, devkit_1.updateProjectConfiguration)(tree, name, updatedProjectJson);
}
else {
(0, devkit_1.addProjectConfiguration)(tree, name, {
root,
...updatedProjectJson,
});
}
return {
name,
...updatedProjectJson,
root,
};
}
function readProjectJson(tree, projectName) {
try {
return (0, devkit_1.readProjectConfiguration)(tree, projectName);
}
catch {
return null;
}
}
async function readInferredProjectConfiguration(tree, name, root) {
const inferredProjects = await getNxDotnetProjects(tree);
return (inferredProjects.projects[name] ?? (root && inferredProjects.rootMap[root]));
}
async function getNxDotnetProjects(tree) {
const rootMap = {};
const config = (0, utils_1.readConfig)(tree);
if (config.inferProjects === false) {
return { rootMap, projects: {} };
}
// During a generator run the workspace context has not
// been updated with new files created by the generator.
// Setting it back up will ensure its up to date, and allow
// the files created by dotnet new to be picked up by the glob.
(0, workspace_context_1.setupWorkspaceContext)(tree.root);
const projectFiles = (0, devkit_1.glob)(tree, [create_nodes_1.createNodes[0]]);
for (const file of projectFiles) {
if ((0, create_nodes_1.isFileIgnored)(file, config)) {
continue;
}
const fileContents = tree.read(file, 'utf-8');
if (!fileContents) {
continue;
}
const project = (0, create_nodes_1.createProjectDefinition)(file, fileContents, config, (0, devkit_1.readNxJson)(tree), (0, try_read_json_1.tryReadJson)(tree, 'package.json'));
if (!project) {
continue;
}
(0, project_configuration_utils_1.mergeProjectConfigurationIntoRootMap)(rootMap, project, undefined, undefined, true);
}
return { rootMap, projects: (0, project_configuration_utils_1.readProjectConfigurationsFromRootMap)(rootMap) };
}
//# sourceMappingURL=project-configuration.js.map