microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.6.3

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/appcenter/lib/codepush-node-sdk/dist/utils/file-utils.js

169lines · modecode

1"use strict";
2var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3 return new (P || (P = Promise))(function (resolve, reject) {
4 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6 function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7 step((generator = generator.apply(thisArg, _arguments || [])).next());
8 });
9};
10Object.defineProperty(exports, "__esModule", { value: true });
11const fs = require("fs");
12const path = require("path");
13const os = require("os");
14const rimraf = require("rimraf");
15const temp = require("temp");
16const _ = require("lodash");
17const noop = require('node-noop').noop;
18function fileExists(file) {
19 try {
20 return fs.statSync(file).isFile();
21 }
22 catch (e) {
23 return false;
24 }
25}
26exports.fileExists = fileExists;
27function isBinaryOrZip(path) {
28 return path.search(/\.zip$/i) !== -1
29 || path.search(/\.apk$/i) !== -1
30 || path.search(/\.ipa$/i) !== -1;
31}
32exports.isBinaryOrZip = isBinaryOrZip;
33function isDirectory(path) {
34 return fs.statSync(path).isDirectory();
35}
36exports.isDirectory = isDirectory;
37function copyFileToTmpDir(filePath) {
38 if (!isDirectory(filePath)) {
39 const outputFolderPath = temp.mkdirSync('code-push');
40 rimraf.sync(outputFolderPath);
41 fs.mkdirSync(outputFolderPath);
42 const outputFilePath = path.join(outputFolderPath, path.basename(filePath));
43 fs.writeFileSync(outputFilePath, fs.readFileSync(filePath));
44 return outputFolderPath;
45 }
46}
47exports.copyFileToTmpDir = copyFileToTmpDir;
48function generateRandomFilename(length) {
49 let filename = '';
50 const validChar = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
51 for (let i = 0; i < length; i++) {
52 filename += validChar.charAt(Math.floor(Math.random() * validChar.length));
53 }
54 return filename;
55}
56exports.generateRandomFilename = generateRandomFilename;
57function fileDoesNotExistOrIsDirectory(path) {
58 try {
59 return isDirectory(path);
60 }
61 catch (error) {
62 return true;
63 }
64}
65exports.fileDoesNotExistOrIsDirectory = fileDoesNotExistOrIsDirectory;
66function createEmptyTmpReleaseFolder(folderPath) {
67 rimraf.sync(folderPath);
68 fs.mkdirSync(folderPath);
69}
70exports.createEmptyTmpReleaseFolder = createEmptyTmpReleaseFolder;
71function removeReactTmpDir() {
72 rimraf.sync(`${os.tmpdir()}/react-*`);
73}
74exports.removeReactTmpDir = removeReactTmpDir;
75function normalizePath(filePath) {
76 // replace all backslashes coming from cli running on windows machines by slashes
77 return filePath.replace(/\\/g, '/');
78}
79exports.normalizePath = normalizePath;
80function walk(dir) {
81 return __awaiter(this, void 0, void 0, function* () {
82 const stats = yield stat(dir);
83 if (stats.isDirectory()) {
84 var files = [];
85 for (const file of yield readdir(dir)) {
86 files = files.concat(yield walk(path.join(dir, file)));
87 }
88 return files;
89 }
90 else {
91 return [dir];
92 }
93 });
94}
95exports.walk = walk;
96function stat(path) {
97 return __awaiter(this, void 0, void 0, function* () {
98 return (yield callFs(fs.stat, path))[0];
99 });
100}
101exports.stat = stat;
102function readdir(path) {
103 return __awaiter(this, void 0, void 0, function* () {
104 return (yield callFs(fs.readdir, path))[0];
105 });
106}
107exports.readdir = readdir;
108function readFile(...args) {
109 return __awaiter(this, void 0, void 0, function* () {
110 return (yield callFs(fs.readFile, ...args))[0];
111 });
112}
113exports.readFile = readFile;
114function access(path, mode) {
115 return __awaiter(this, void 0, void 0, function* () {
116 return callFs(fs.access, path, mode).then(() => { noop(); });
117 });
118}
119exports.access = access;
120function rmDir(source, recursive = true) {
121 if (recursive) {
122 return new Promise((resolve, reject) => {
123 rimraf(source, err => {
124 if (err) {
125 reject(err);
126 }
127 else {
128 resolve();
129 }
130 });
131 });
132 }
133 else {
134 return callFs(fs.rmdir, source).then(() => { noop(); });
135 }
136}
137exports.rmDir = rmDir;
138function mkTempDir(affixes) {
139 return callTemp(temp.mkdir, affixes);
140}
141exports.mkTempDir = mkTempDir;
142function callTemp(func, ...args) {
143 return new Promise((resolve, reject) => {
144 func.apply(temp, _.concat(args, [
145 (err, result) => {
146 if (err) {
147 reject(err);
148 }
149 else {
150 resolve(result);
151 }
152 }
153 ]));
154 });
155}
156function callFs(func, ...args) {
157 return new Promise((resolve, reject) => {
158 func.apply(fs, _.concat(args, [
159 (err, ...args) => {
160 if (err) {
161 reject(err);
162 }
163 else {
164 resolve(args);
165 }
166 }
167 ]));
168 });
169}
170