microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
bf370babc67fceb47785d380f57673f963c53d2b

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

lib/codepush-node-sdk/dist/update-contents/zip.js

54lines · modecode

1"use strict";
2/// <reference path="../../typings/index.d.ts" />
3var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4 return new (P || (P = Promise))(function (resolve, reject) {
5 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7 function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
8 step((generator = generator.apply(thisArg, _arguments || [])).next());
9 });
10};
11Object.defineProperty(exports, "__esModule", { value: true });
12const fs = require("fs");
13const path = require("path");
14const yazl = require("yazl");
15const fileUtils = require("../utils/file-utils");
16function zip(updateContentsPath, outputDir) {
17 return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
18 const releaseFiles = [];
19 if (!fileUtils.isDirectory(updateContentsPath)) {
20 releaseFiles.push({
21 sourceLocation: updateContentsPath,
22 targetLocation: fileUtils.normalizePath(path.basename(updateContentsPath)) // Put the file in the root
23 });
24 }
25 const directoryPath = updateContentsPath;
26 const baseDirectoryPath = path.join(directoryPath, '..'); // For legacy reasons, put the root directory in the zip
27 const files = yield fileUtils.walk(updateContentsPath);
28 files.forEach((filePath) => {
29 const relativePath = path.relative(baseDirectoryPath, filePath);
30 releaseFiles.push({
31 sourceLocation: filePath,
32 targetLocation: fileUtils.normalizePath(relativePath)
33 });
34 });
35 if (!outputDir) {
36 outputDir = process.cwd();
37 }
38 const packagePath = path.join(outputDir, fileUtils.generateRandomFilename(15) + '.zip');
39 const zipFile = new yazl.ZipFile();
40 const writeStream = fs.createWriteStream(packagePath);
41 zipFile.outputStream.pipe(writeStream)
42 .on('error', (error) => {
43 reject(error);
44 })
45 .on('close', () => {
46 resolve(packagePath);
47 });
48 releaseFiles.forEach((releaseFile) => {
49 zipFile.addFile(releaseFile.sourceLocation, releaseFile.targetLocation);
50 });
51 zipFile.end();
52 }));
53}
54exports.default = zip;
55