UNPKG

@project-sunbird/sunbird-epub-player-v9

Version:

The Epub player library is 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 development

77 lines 3.7 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.addPlayerModuleToAppModule = addPlayerModuleToAppModule; const schematics_1 = require("@angular-devkit/schematics"); const ng_ast_utils_1 = require("@schematics/angular/utility/ng-ast-utils"); const ast_utils_1 = require("@schematics/angular/utility/ast-utils"); const change_1 = require("@schematics/angular/utility/change"); const ts = require("@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript"); const workspace_1 = require("@schematics/angular/utility/workspace"); const messages = require("../messages"); const project_1 = require("../../utils/project"); const MODULE_NAME = 'SunbirdEpubPlayerModule'; const PACKAGE_NAME = '@project-sunbird/sunbird-epub-player-v9'; /** * Patches main application module by adding 'SunbirdEpubPlayerModule' import. * * Relevant 'angular.json' structure is: * * { * "projects" : { * "projectName": { * "architect": { * "build": { * "options": { * "main": "src/main.ts" * } * } * } * } * }, * "defaultProject": "projectName" * } * */ function addPlayerModuleToAppModule(options) { return (host) => __awaiter(this, void 0, void 0, function* () { const workspace = yield (0, workspace_1.getWorkspace)(host); const projectName = options.project || workspace.extensions.defaultProject; // 1. getting project by name const project = workspace.projects.get(projectName); if (!project) { throw new schematics_1.SchematicsException(messages.noProject(projectName)); } // 2. getting main file for project const projectBuildOptions = (0, project_1.getProjectTargetOptions)(project, 'build'); const mainFilePath = projectBuildOptions.main; if (!mainFilePath || !host.read(mainFilePath)) { throw new schematics_1.SchematicsException(messages.noMainFile(projectName)); } // 3. getting main app module file const appModuleFilePath = (0, ng_ast_utils_1.getAppModulePath)(host, mainFilePath); const appModuleFileText = host.read(appModuleFilePath); if (appModuleFileText === null) { throw new schematics_1.SchematicsException(messages.noModuleFile(appModuleFilePath)); } // 4. adding `NgbModule` to the app module const appModuleSource = ts.createSourceFile(appModuleFilePath, appModuleFileText.toString('utf-8'), ts.ScriptTarget.Latest, true); const changes = (0, ast_utils_1.addImportToModule)(appModuleSource, appModuleFilePath, MODULE_NAME, PACKAGE_NAME); const recorder = host.beginUpdate(appModuleFilePath); for (const change of changes) { if (change instanceof change_1.InsertChange) { recorder.insertLeft(change.pos, change.toAdd); } } host.commitUpdate(recorder); }); } //# sourceMappingURL=add-player-module.js.map