UNPKG

@zowe/imperative

Version:
80 lines 3.49 kB
"use strict"; /* * This program and the accompanying materials are made available under the terms of the * Eclipse Public License v2.0 which accompanies this distribution, and is available at * https://www.eclipse.org/legal/epl-v20.html * * SPDX-License-Identifier: EPL-2.0 * * Copyright Contributors to the Zowe Project. * */ 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 }); /* eslint-disable no-console */ const fs = require("fs"); const path = require("path"); const ImperativeError_1 = require("../../../error/src/ImperativeError"); /** * Imperative web diff generator. Accepts the diffContent and constructs * the whole webb diff browser view * * @export * @class WebDiffGenerator */ class WebDiffGenerator { /** * Create an instance of WebDiffGenerator. * @param {ImperativeConfig} - Imperative config containing data about the CLI * @param {string} - Output directory for web diff files */ constructor(config, webDiffDir) { this.mConfig = config; this.webDiffDir = webDiffDir; } /** * Diff directory builder at the cli home to open the diff strings comparison * in the browser. */ buildDiffDir() { return __awaiter(this, void 0, void 0, function* () { // requiring fs-extra for later use in copying the dir and files const fsExtra = yield require("fs-extra"); // Ensure web diff dir exists if (!fs.existsSync(this.webDiffDir)) { fs.mkdirSync(this.webDiffDir); } // getting the template directory for web-diff in the root of project const templateWebDiffDir = path.join(__dirname, "../../../../web-diff"); if (!fs.existsSync(templateWebDiffDir)) { throw new ImperativeError_1.ImperativeError({ msg: `The web-diff distribution directory does not exist:\n "${templateWebDiffDir}"` }); } // getting the files required to copied const dirsToCopy = [templateWebDiffDir]; // copying files from template web diff dir to cli home web diff dir dirsToCopy.forEach((dir) => { const destDir = path.join(this.webDiffDir, path.relative(templateWebDiffDir, dir)); if (!fs.existsSync(destDir)) { fs.mkdirSync(destDir); } fs.readdirSync(dir) .filter((pathname) => fs.statSync(path.join(dir, pathname)).isFile()) .forEach((filename) => { fsExtra.copySync(path.join(dir, filename), path.join(destDir, filename)); }); }); }); } } exports.default = WebDiffGenerator; //# sourceMappingURL=WebDiffGenerator.js.map