@dlr-eoc/core-ui
Version:
This project includes schematics to add the base UKIS-Layout to an angular application. The Layout is based on Clarity so [add this first](https://clarity.design/get-started/developing/angular)!
136 lines • 5.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.hasArchitectBuildOptionsMain = hasArchitectBuildOptionsMain;
exports.hasArchitectTestOptionsStyles = hasArchitectTestOptionsStyles;
exports.hasArchitectBuildOptionsStyles = hasArchitectBuildOptionsStyles;
exports.hasSchematicsStyle = hasSchematicsStyle;
exports.checkProjectIsApplication = checkProjectIsApplication;
exports.checkProjectSourceRoot = checkProjectSourceRoot;
exports.getDefaultProjectName = getDefaultProjectName;
exports.getProjectName = getProjectName;
exports.getStyleExt = getStyleExt;
exports.ruleInstallTask = ruleInstallTask;
const schematics_1 = require("@angular-devkit/schematics");
const tasks_1 = require("@angular-devkit/schematics/tasks");
const workspace_models_1 = require("@schematics/angular/utility/workspace-models");
/**
* Type Guard
*
* workspaces.ProjectDefinition: extensions?.architect?.build?.options?.main
*/
function hasArchitectBuildOptionsMain(extensions) {
var _a, _b, _c;
return (_c = (_b = (_a = extensions === null || extensions === void 0 ? void 0 : extensions.architect) === null || _a === void 0 ? void 0 : _a.build) === null || _b === void 0 ? void 0 : _b.options) === null || _c === void 0 ? void 0 : _c.main;
}
/**
* Type Guard
*
* workspaces.ProjectDefinition: extensions?.architect?.test?.options?.styles;
*/
function hasArchitectTestOptionsStyles(extensions) {
var _a, _b, _c;
return (_c = (_b = (_a = extensions === null || extensions === void 0 ? void 0 : extensions.architect) === null || _a === void 0 ? void 0 : _a.test) === null || _b === void 0 ? void 0 : _b.options) === null || _c === void 0 ? void 0 : _c.styles;
}
/**
* Type Guard
*
* workspaces.ProjectDefinition: extensions?.architect?.build?.options?.styles
*/
function hasArchitectBuildOptionsStyles(extensions) {
var _a, _b, _c;
return (_c = (_b = (_a = extensions === null || extensions === void 0 ? void 0 : extensions.architect) === null || _a === void 0 ? void 0 : _a.build) === null || _b === void 0 ? void 0 : _b.options) === null || _c === void 0 ? void 0 : _c.styles;
}
/**
* Type Guard
*
* workspaces.WorkspaceDefinition or workspaces.ProjectDefinition: extensions?.schematics
*/
function hasSchematicsStyle(extensions) {
var _a;
return (_a = extensions === null || extensions === void 0 ? void 0 : extensions.schematics) === null || _a === void 0 ? void 0 : _a['@schematics/angular:component'];
}
/**
* Check if the Project exists in workspaces.WorkspaceDefinition
*/
function checkForProject(workspace, projectName) {
if (!workspace.projects.has(projectName)) {
throw new schematics_1.SchematicsException(`Could not find Project ${projectName} in the workspace check your --project`);
}
else {
return workspace.projects.get(projectName);
}
}
/**
* Check if the Project in workspaces.WorkspaceDefinition is of type application
*/
function checkProjectIsApplication(workspace, projectName) {
const projecOrDefaultName = projectName || getDefaultProjectName(workspace);
if (projecOrDefaultName) {
const project = checkForProject(workspace, projecOrDefaultName);
if (project) {
// https://github.com/angular/angular-cli/blob/HEAD/packages/angular/pwa/pwa/index.ts#L100
if (project.extensions['projectType'] !== workspace_models_1.ProjectType.Application) {
throw new schematics_1.SchematicsException(`You should add @dlr-eoc/core-ui only to an angular application not a library!`);
}
}
}
}
function checkProjectSourceRoot(project, context) {
if (!project.sourceRoot) {
project.sourceRoot = 'src';
context.logger.warn(`Project.sourceRoot is not defined in the workspace, assuming /src!`);
return true;
}
else {
return true;
}
}
/**
* Get the defaultProject from workspaces.WorkspaceDefinition if there is a defaultProject
*/
function getDefaultProjectName(workspace) {
const defaultProjectName = workspace.extensions['defaultProject'];
if (defaultProjectName) {
return defaultProjectName;
}
else if (!defaultProjectName) {
throw new schematics_1.SchematicsException(`Could not find a default Project in the workspace and you didn't set a project`);
}
}
/**
* Returns projectName or the defaultProject
*/
function getProjectName(workspace, projectName) {
if (!projectName) {
return getDefaultProjectName(workspace);
}
else {
return projectName;
}
}
/**
* Get the Style extension of workspaces.ProjectDefinition or workspaces.WorkspaceDefinition or 'scss'
*/
function getStyleExt(project, workspace, context) {
let styleExt = 'scss';
if (hasSchematicsStyle(project.extensions)) {
styleExt = project.extensions.schematics['@schematics/angular:component'].style;
}
else if (hasSchematicsStyle(workspace.extensions)) {
styleExt = workspace.extensions.schematics['@schematics/angular:component'].style;
}
else {
context.logger.info(`In your workspace is no style extension defined use default ${styleExt}`);
}
return styleExt;
}
/**
* Install node packages
*/
function ruleInstallTask() {
return (tree, context) => {
context.addTask(new tasks_1.NodePackageInstallTask());
return tree;
};
}
//# sourceMappingURL=workspace-utils.js.map