UNPKG

@tekdi/sunbird-quml-player

Version:

The QuML player library components are powered by Angular. This player is primarily designed to be used on Sunbird consumption platforms (mobile app, web portal, offline desktop app) to drive reusability and maintainability, hence reducing the redundant d

95 lines 4.07 kB
"use strict"; 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.addLibraryStyles = void 0; const schematics_1 = require("@angular-devkit/schematics"); const workspace_1 = require("@schematics/angular/utility/workspace"); const project_1 = require("../../utils/project"); const messages = require("../messages"); const STYLE_FILEPATH = [ 'node_modules/@project-sunbird/sunbird-quml-player/lib/assets/styles/quml-carousel.css', 'node_modules/@project-sunbird/sb-styles/assets/styles.scss', 'node_modules/katex/dist/katex.min.css', ]; const SCRIPT_FILEPATH = [ "node_modules/katex/dist/katex.min.js", "node_modules/jquery/dist/jquery.min.js" ]; const LIBRARY_ASSETS = { glob: '**/*.*', input: './node_modules/@project-sunbird/sunbird-quml-player/lib/assets/', output: '/assets/' }; function addLibraryStyles(options) { return (host, context) => __awaiter(this, void 0, void 0, function* () { const workspace = yield (0, workspace_1.getWorkspace)(host); const projectName = options.project || workspace.extensions.defaultProject; const project = workspace.projects.get(projectName); if (!project) { throw new schematics_1.SchematicsException(messages.noProject(projectName)); } // just patching 'angular.json' return addStyleToAngularJson(project, context, projectName); }); } exports.addLibraryStyles = addLibraryStyles; /** * Patches 'angular.json' to add '_styles.scss' styles */ function addStyleToAngularJson(project, context, projectName) { const targetOptions = (0, project_1.getProjectTargetOptions)(project, 'build'); const styles = targetOptions.styles; context.logger.info("Adding styles to angular.json"); for (const PATH of STYLE_FILEPATH) { if (!styles) { targetOptions.styles = [PATH]; } else { const existingStyles = styles.map((s) => typeof s === 'string' ? s : s.input); if (!existingStyles.includes(PATH)) { styles.unshift(PATH); } } } const scripts = targetOptions.scripts; context.logger.info("Adding scripts to angular.json"); for (const PATH of SCRIPT_FILEPATH) { if (!scripts) { targetOptions.scripts = [PATH]; } else { const existingScripts = scripts.map((s) => typeof s === 'string' ? s : s.input); if (!existingScripts.includes(PATH)) { scripts.unshift(PATH); } } } const assets = targetOptions.assets; context.logger.info("Adding assets to angular.json"); if (!assets) { targetOptions.assets = [LIBRARY_ASSETS]; } else { const existingAssets = assets.map((a) => typeof a === 'string' ? a : a.input); if (!existingAssets.includes(LIBRARY_ASSETS.input)) { assets.unshift(LIBRARY_ASSETS); } } context.logger.info("updating angular.json..."); return (0, workspace_1.updateWorkspace)((defaultWorkspace) => { let defaultProject = defaultWorkspace.projects.get(projectName); const buildTarget = defaultProject.targets.get('build'); buildTarget.options.styles = styles; buildTarget.options.scripts = scripts; buildTarget.options.assets = assets; }); } //# sourceMappingURL=add-library-styles.js.map