angular-toaster
Version:
An Angular Toaster Notification library based on AngularJS-Toaster
62 lines (61 loc) • 3.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getProjectTargetOptions = getProjectTargetOptions;
exports.getProjectBuildTargets = getProjectBuildTargets;
exports.getProjectTestTargets = getProjectTestTargets;
exports.getProjectMainFile = getProjectMainFile;
exports.getProjectFromWorkspace = getProjectFromWorkspace;
const schematics_1 = require("@angular-devkit/schematics");
/** Resolves the architect options for the build target of the given project. */
function getProjectTargetOptions(project, buildTarget) {
var _a, _b;
const options = (_b = (_a = project.targets) === null || _a === void 0 ? void 0 : _a.get(buildTarget)) === null || _b === void 0 ? void 0 : _b.options;
if (!options) {
throw new schematics_1.SchematicsException(`Cannot determine project target configuration for: ${buildTarget}.`);
}
return options;
}
/** Gets all of the default CLI-provided build targets in a project. */
function getProjectBuildTargets(project) {
return getTargetsByBuilderName(project, (builder) => builder === "@angular-devkit/build-angular:application" ||
builder === "@angular-devkit/build-angular:browser" ||
builder === "@angular-devkit/build-angular:browser-esbuild");
}
/** Gets all of the default CLI-provided testing targets in a project. */
function getProjectTestTargets(project) {
return getTargetsByBuilderName(project, (builder) => builder === "@angular-devkit/build-angular:karma");
}
/** Gets all targets from the given project that pass a predicate check. */
function getTargetsByBuilderName(project, predicate) {
return Array.from(project.targets.keys())
.filter((name) => { var _a; return predicate((_a = project.targets.get(name)) === null || _a === void 0 ? void 0 : _a.builder); })
.map((name) => project.targets.get(name));
}
/** Looks for the main TypeScript file in the given project and returns its path. */
function getProjectMainFile(project) {
const buildOptions = getProjectTargetOptions(project, "build");
// `browser` is for the `@angular-devkit/build-angular:application` builder while
// `main` is for the `@angular-devkit/build-angular:browser` builder.
const mainPath = (buildOptions["browser"] || buildOptions["main"]);
if (!mainPath) {
throw new schematics_1.SchematicsException(`Could not find the project main file inside of the ` +
`workspace config (${project.sourceRoot})`);
}
return mainPath;
}
/**
* Finds the specified project configuration in the workspace. Throws an error if the project
* couldn't be found.
*/
function getProjectFromWorkspace(workspace, projectName) {
if (!projectName) {
// TODO(crisbeto): some schematics APIs have the project name as optional so for now it's
// simpler to allow undefined and checking it at runtime. Eventually we should clean this up.
throw new schematics_1.SchematicsException("Project name is required.");
}
const project = workspace.projects.get(projectName);
if (!project) {
throw new schematics_1.SchematicsException(`Could not find project in workspace: ${projectName}`);
}
return project;
}