UNPKG

@rxap/plugin-utilities

Version:

Provides utility functions for Nx plugins, such as retrieving project dependencies, determining output paths, and interacting with package.json files. It simplifies common tasks within Nx executors and generators. This package helps streamline plugin deve

78 lines 3.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GuessOutputPathFromContext = GuessOutputPathFromContext; exports.GuessOutputPathFromTargetString = GuessOutputPathFromTargetString; exports.GuessOutputPath = GuessOutputPath; const workspace_utilities_1 = require("@rxap/workspace-utilities"); const path_1 = require("path"); const project_1 = require("./project"); const project_target_1 = require("./project-target"); function GuessOutputPathFromContext(context, projectName = context.projectName, configurationName = context.configurationName, targetName = 'build') { if (!projectName) { throw new Error('The projectName is undefined. Ensure the projectName is passed into the executor context.'); } if (!(0, project_target_1.HasProjectTarget)(context, projectName, targetName)) { console.warn(`Could not find target '${targetName}' for project '${projectName}'. Falling back to the project source root.`); return (0, project_1.GetProjectSourceRoot)(context, projectName); } const target = (0, project_target_1.GetProjectTarget)(context, projectName, targetName); if (!target) { throw new Error(`Could not find target 'build' for project '${projectName}'`); } const projectRoot = (0, project_1.GetProjectRoot)(context, projectName); return GuessOutputPath(projectName, projectRoot, target, configurationName); } function GuessOutputPathFromTargetString(context, targetString) { let configurationName = context.configurationName; let targetName = 'build'; let projectName = context.projectName; if (targetString) { const [name, target, configuration] = targetString.split(':'); if (!name) { throw new Error(`Could not extract the project name from the build target '${targetString}'`); } if (!target) { throw new Error(`Could not extract the target name from the build target '${targetString}'`); } projectName = name; targetName = target; configurationName = configuration; } return GuessOutputPathFromContext(context, projectName, configurationName, targetName); } function isAngularBuildOutputPath(outputPath) { return outputPath && typeof outputPath === 'object' && 'base' in outputPath; } function GuessOutputPath(projectName, projectRoot, buildTarget, configurationName) { let outputPath = (0, workspace_utilities_1.GetTargetOptions)(buildTarget, configurationName)['outputPath']; if (!outputPath) { if (buildTarget.outputs && buildTarget.outputs.length) { const [output] = buildTarget.outputs; if (output.match(/\.[a-zA-Z]+$/)) { outputPath = (0, path_1.dirname)(output); } else { outputPath = output; } } else { outputPath = (0, path_1.join)('dist', projectRoot); } } if (!outputPath) { throw new Error(`The outputPath is undefined. Ensure the outputPath is passed into the target options.`); } if (typeof outputPath === 'object') { if (isAngularBuildOutputPath(outputPath)) { return outputPath.base; } } if (typeof outputPath !== 'string') { throw new Error(`The outputPath is not a string. Found: ${outputPath}`); } return outputPath .replace(/\{projectName}/, projectName) .replace(/\{projectRoot}/, projectRoot) .replace(/\{workspaceRoot}\//, ''); } //# sourceMappingURL=guess-output-path.js.map