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 · modeblame

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