UNPKG

@domoinc/ryuu-angular

Version:

Angular Schematic to add @domoinc/ryuu-proxy support

75 lines 2.95 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getProject = exports.getWorkspace = exports.getRootPath = exports.parseJson = void 0; const schematics_1 = require("@angular-devkit/schematics"); const path_1 = __importDefault(require("path")); /** * Parses a JSON string and returns the corresponding JavaScript object. * If the JSON string is invalid, an empty object is returned. * @param {string} json - The JSON string to parse. * @returns {object} - The parsed JavaScript object. */ const parseJson = (json) => { try { return JSON.parse(json); } catch (e) { return {}; } }; exports.parseJson = parseJson; const getRootPath = (append) => { return path_1.default.join(__dirname, '../../', append !== null && append !== void 0 ? append : ''); }; exports.getRootPath = getRootPath; /** * Retrieves the path of the Angular workspace configuration file. * @param {Tree} host - The host tree representing the file system. * @returns {string} The path of the Angular workspace configuration file. */ const getWorkspacePath = (host) => { const possibleFiles = ['/angular.json', '/.angular.json']; const path = possibleFiles.filter(path => host.exists(path))[0]; return path; }; /** * Retrieves the workspace configuration from the given host. * @param {Tree} host - The host object representing the file system. * @returns The parsed workspace configuration object. * @throws {SchematicsException} If the workspace configuration file cannot be found. */ const getWorkspace = (host) => { const path = getWorkspacePath(host); const configBuffer = host.read(path); if (configBuffer === null) { throw new schematics_1.SchematicsException(`Could not find (${path})`); } const content = configBuffer.toString(); return (0, exports.parseJson)(content); }; exports.getWorkspace = getWorkspace; /** * Checks if the given workspace object is a valid workspace schema. * @param {any} workspace - The workspace object to check. * @returns {boolean} - True if the workspace has a 'projects' property, false otherwise. */ const isWorkspaceSchema = (workspace) => { return !!(workspace.projects); }; /** * Retrieves the project configuration object from the given workspace or host. * @param {WorkspaceSchema | Tree} workspaceOrHost - The workspace or host object. * @param {string} projectName - The name of the project to retrieve. * @returns The project configuration object. */ const getProject = (workspaceOrHost, projectName) => { const workspace = isWorkspaceSchema(workspaceOrHost) ? workspaceOrHost : (0, exports.getWorkspace)(workspaceOrHost); return workspace.projects[projectName]; }; exports.getProject = getProject; //# sourceMappingURL=utils.js.map