mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-09-17 21:46:09 +08:00
fs-extra
This commit is contained in:
@@ -4,8 +4,7 @@
|
||||
|
||||
const fetch = require('isomorphic-fetch');
|
||||
let host = process.env.PUSHY_REGISTRY || 'https://update.reactnative.cn/api';
|
||||
const fs = require('fs-promise');
|
||||
import * as fsOrigin from 'fs';
|
||||
const fs = require('fs-extra');
|
||||
import request from 'request';
|
||||
import ProgressBar from 'progress';
|
||||
|
||||
@@ -13,9 +12,9 @@ let session = undefined;
|
||||
let savedSession = undefined;
|
||||
|
||||
exports.loadSession = async function() {
|
||||
if (await fs.exists('.update')) {
|
||||
if (fs.existsSync('.update')) {
|
||||
try {
|
||||
exports.replaceSession(JSON.parse(await fs.readFile('.update', 'utf8')));
|
||||
exports.replaceSession(JSON.parse(fs.readFileSync('.update', 'utf8')));
|
||||
savedSession = session;
|
||||
} catch (e) {
|
||||
console.error('Failed to parse file `.update`. Try to remove it manually.');
|
||||
@@ -32,19 +31,19 @@ exports.replaceSession = function(newSession) {
|
||||
session = newSession;
|
||||
};
|
||||
|
||||
exports.saveSession = async function() {
|
||||
exports.saveSession = function() {
|
||||
// Only save on change.
|
||||
if (session !== savedSession) {
|
||||
const current = session;
|
||||
const data = JSON.stringify(current, null, 4);
|
||||
await fs.writeFile('.update', data, 'utf8');
|
||||
fs.writeFileSync('.update', data, 'utf8');
|
||||
savedSession = current;
|
||||
}
|
||||
};
|
||||
|
||||
exports.closeSession = async function() {
|
||||
if (await fs.exists('.update')) {
|
||||
await fs.unlink('.update');
|
||||
exports.closeSession = function() {
|
||||
if (fs.existsSync('.update')) {
|
||||
fs.unlinkSync('.update');
|
||||
savedSession = undefined;
|
||||
}
|
||||
session = undefined;
|
||||
@@ -97,7 +96,7 @@ async function uploadFile(fn) {
|
||||
realUrl = host + url;
|
||||
}
|
||||
|
||||
const fileSize = (await fs.stat(fn)).size;
|
||||
const fileSize = fs.statSync(fn).size;
|
||||
|
||||
const bar = new ProgressBar(' Uploading [:bar] :percent :etas', {
|
||||
complete: '=',
|
||||
@@ -106,7 +105,7 @@ async function uploadFile(fn) {
|
||||
});
|
||||
|
||||
const info = await new Promise((resolve, reject) => {
|
||||
formData.file = fsOrigin.createReadStream(fn);
|
||||
formData.file = fs.createReadStream(fn);
|
||||
|
||||
formData.file.on('data', function(data) {
|
||||
bar.tick(data.length);
|
||||
|
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
|
||||
import {question} from './utils';
|
||||
import * as fs from 'fs-promise';
|
||||
import * as fs from 'fs-extra';
|
||||
|
||||
const {
|
||||
post,
|
||||
@@ -23,13 +23,13 @@ export function checkPlatform(platform) {
|
||||
return platform
|
||||
}
|
||||
|
||||
export async function getSelectedApp(platform) {
|
||||
export function getSelectedApp(platform) {
|
||||
checkPlatform(platform);
|
||||
|
||||
if (!await fs.exists('update.json')){
|
||||
if (!fs.existsSync('update.json')){
|
||||
throw new Error(`App not selected. run 'pushy selectApp --platform ${platform}' first!`);
|
||||
}
|
||||
const updateInfo = JSON.parse(await fs.readFile('update.json', 'utf8'));
|
||||
const updateInfo = JSON.parse(fs.readFileSync('update.json', 'utf8'));
|
||||
if (!updateInfo[platform]) {
|
||||
throw new Error(`App not selected. run 'pushy selectApp --platform ${platform}' first!`);
|
||||
}
|
||||
@@ -92,9 +92,9 @@ export const commands = {
|
||||
const id = args[0] || (await chooseApp(platform)).id;
|
||||
|
||||
let updateInfo = {};
|
||||
if (await fs.exists('update.json')) {
|
||||
if (fs.existsSync('update.json')) {
|
||||
try {
|
||||
updateInfo = JSON.parse(await fs.readFile('update.json', 'utf8'));
|
||||
updateInfo = JSON.parse(fs.readFileSync('update.json', 'utf8'));
|
||||
} catch (e) {
|
||||
console.error('Failed to parse file `update.json`. Try to remove it manually.');
|
||||
throw e;
|
||||
@@ -105,6 +105,6 @@ export const commands = {
|
||||
appId: id,
|
||||
appKey,
|
||||
};
|
||||
await fs.writeFile('update.json', JSON.stringify(updateInfo, null, 4), 'utf8');
|
||||
fs.writeFileSync('update.json', JSON.stringify(updateInfo, null, 4), 'utf8');
|
||||
},
|
||||
}
|
||||
|
@@ -3,16 +3,13 @@
|
||||
*/
|
||||
|
||||
import * as path from 'path';
|
||||
import { mkdir as mkdirRecurisve } from 'mkdir-recursive';
|
||||
import rmdirRecursive from 'rimraf';
|
||||
import { getRNVersion, translateOptions } from './utils';
|
||||
import * as fs from 'fs';
|
||||
import * as fs from 'fs-extra';
|
||||
import { ZipFile } from 'yazl';
|
||||
import { open as openZipFile } from 'yauzl';
|
||||
// import {diff} from 'node-bsdiff';
|
||||
import { question } from './utils';
|
||||
import { checkPlatform } from './app';
|
||||
import crypto from 'crypto';
|
||||
import minimist from 'minimist';
|
||||
|
||||
var diff;
|
||||
@@ -28,30 +25,6 @@ try {
|
||||
};
|
||||
}
|
||||
|
||||
function mkdir(dir) {
|
||||
return new Promise((resolve, reject) => {
|
||||
mkdirRecurisve(dir, err => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function rmdir(dir) {
|
||||
return new Promise((resolve, reject) => {
|
||||
rmdirRecursive(dir, err => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function pack(dir, output) {
|
||||
await mkdir(path.dirname(output));
|
||||
await new Promise((resolve, reject) => {
|
||||
@@ -359,8 +332,7 @@ export const commands = {
|
||||
|
||||
console.log('Bundling with React Native version: ', version);
|
||||
|
||||
await rmdir(realIntermedia);
|
||||
await mkdir(realIntermedia);
|
||||
fs.emptyDirSync(realIntermedia);
|
||||
|
||||
if (major === 0) {
|
||||
if (minor >= 56) {
|
||||
|
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
import * as fs from 'fs-extra';
|
||||
import ApkReader from 'node-apk-parser';
|
||||
import ipaReader from './ipaReader';
|
||||
|
||||
|
Reference in New Issue
Block a user