UNPKG

@dicdikshaorg/epub-player-v9

Version:

Contains Epub player library components powered by angular. These components are designed to be used in sunbird consumption platforms *(mobile app, web portal, offline desktop app)* to drive reusability, maintainability hence reducing the redundant develo

97 lines 3.96 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.addPlayerStyles = void 0; const schematics_1 = require("@angular-devkit/schematics"); const messages = require("../messages"); const project_1 = require("../../utils/project"); const workspace_1 = require("@schematics/angular/utility/workspace"); // Default styles, assets and script const SB_STYLES = [ 'node_modules/@project-sunbird/sb-styles/assets/_styles.scss' ]; const SB_ASSETS = [{ glob: '**/*.*', input: './node_modules/@project-sunbird/sunbird-epub-player-v9/lib/assets/', output: '/assets/' }]; const SB_SCRIPTS = [ 'node_modules/epubjs/dist/epub.js' ]; /** * we're simply adding styles to the 'angular.json' */ function addPlayerStyles(options) { return (host) => __awaiter(this, void 0, void 0, function* () { const workspace = yield 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 addPlayerToAngularJson(workspace, project); }); } exports.addPlayerStyles = addPlayerStyles; /** * Patches 'angular.json' to add styles */ function addPlayerToAngularJson(workspace, project) { const targetOptions = project_1.getProjectTargetOptions(project, 'build'); addStyleToTarget(targetOptions, SB_STYLES); addAssetsToTarget(targetOptions, SB_ASSETS); addScriptToTarget(targetOptions, SB_SCRIPTS); return workspace_1.updateWorkspace(workspace); } function addStyleToTarget(targetOptions, assetPaths) { const styles = targetOptions.styles; if (!styles) { targetOptions.styles = assetPaths; } else { const existingStyles = styles.map((s) => typeof s === 'string' ? s : s.input); assetPaths.forEach((style) => { if (!existingStyles.includes(typeof style === 'string' ? style : style.input)) { styles.unshift(style); } }); } } function addAssetsToTarget(targetOptions, assetPaths) { const assets = targetOptions.assets; if (!assets) { targetOptions.assets = assetPaths; } else { const existingAssets = assets.map((s) => typeof s === 'string' ? s : s.input); assetPaths.forEach((asset) => { if (!existingAssets.includes(typeof asset === 'string' ? asset : asset.input)) { assets.unshift(asset); } }); } } function addScriptToTarget(targetOptions, assetPaths) { const scripts = targetOptions.scripts; if (!scripts) { targetOptions.scripts = assetPaths; } else { const existingScripts = scripts.map((s) => typeof s === 'string' ? s : s.input); assetPaths.forEach((script) => { if (!existingScripts.includes(typeof script === 'string' ? script : script.input)) { scripts.unshift(script); } }); } } //# sourceMappingURL=add-player-style.js.map