UNPKG

@redocly/theme

Version:

Shared UI components lib

40 lines 2.17 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()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.downloadCodeWalkthrough = downloadCodeWalkthrough; const file_saver_1 = require("file-saver"); const jszip_1 = __importDefault(require("jszip")); const utils_1 = require("../../core/utils"); // https://github.com/Stuk/jszip/issues/196#issuecomment-69503828 jszip_1.default.support.nodebuffer = false; function downloadCodeWalkthrough(files, state, inputsState) { return __awaiter(this, void 0, void 0, function* () { const zip = new jszip_1.default(); const filePaths = files.map(({ path }) => path); const commonClosestDirectory = (0, utils_1.findClosestCommonDirectory)(filePaths); for (const file of files) { const fileContent = (0, utils_1.getCodeWalkthroughFileText)(file, state, inputsState); if (commonClosestDirectory === '/') { zip.file(file.path, fileContent); } else { const filePath = file.path.replace((0, utils_1.removeLeadingSlash)(`${commonClosestDirectory}/`), ''); zip.file(filePath, fileContent); } } const zipContent = yield zip.generateAsync({ type: 'blob' }); (0, file_saver_1.saveAs)(zipContent, 'sample-code.zip'); }); } //# sourceMappingURL=download-code-walkthrough.js.map