@doku-dev/doku-fragment
Version:
A new Angular UI library that moving away from Bootstrap and built from scratch.
78 lines • 3.81 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getProjectStyleFile = exports.getProjectTargetOptions = exports.getActiveProject = void 0;
const core_1 = require("@angular-devkit/core");
const schematics_1 = require("@angular-devkit/schematics");
// Regular expression that matches all files that have a proper stylesheet extension
const validStyleFileRegex = /\.(c|le|sc|sa)ss/;
/**
* Get project from workspace by name or get directly if single project.
* @param tree Host tree
* @param projectName Project name from schema
* @returns Project definition or undefined
*/
function getActiveProject(workspace, projectName) {
return __awaiter(this, void 0, void 0, function* () {
let project;
// Get workspace project by name.
if (!project && projectName) {
project = workspace.projects.get(projectName);
}
// If project by name does not exists, get directly in the workspace if it's a single project.
if (!project && workspace.projects.size === 1) {
project = Array.from(workspace.projects.values()).at(0);
}
return project;
});
}
exports.getActiveProject = getActiveProject;
/**
* Get options for the build target of the given project
*/
function getProjectTargetOptions(project, buildTarget) {
const buildTargetObject = project.targets.get(buildTarget);
if (buildTargetObject === null || buildTargetObject === void 0 ? void 0 : buildTargetObject.options) {
return buildTargetObject.options;
}
throw new schematics_1.SchematicsException(`Cannot determine project target configuration for: ${buildTarget}.`);
}
exports.getProjectTargetOptions = getProjectTargetOptions;
/**
* Gets a style file with the given extension in a project and returns its path. If no
* extension is specified, it will return null.
*/
function getProjectStyleFile(project) {
const buildOptions = getProjectTargetOptions(project, 'build');
if (buildOptions['styles'] &&
Array.isArray(buildOptions['styles']) &&
buildOptions['styles'].length) {
const styles = buildOptions['styles']
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.map((s) => (typeof s === 'string' ? s : s['input']))
.filter((value) => !!value);
// Look for the default style file that is generated for new projects by the Angular CLI. This
// default style file is usually called `styles.extension` unless it has been changed explicitly.
const defaultMainStylePath = styles.find((path) => {
const expectedPathWithoutExtension = `${project.sourceRoot}/styles`;
const pathMatched = path.startsWith(expectedPathWithoutExtension);
const validExtension = validStyleFileRegex.test(path);
return pathMatched && validExtension;
});
if (defaultMainStylePath) {
return (0, core_1.normalize)(defaultMainStylePath);
}
return null;
}
return null;
}
exports.getProjectStyleFile = getProjectStyleFile;
//# sourceMappingURL=util.js.map