1
0
mirror of https://gitcode.com/github-mirrors/react-native-update-cli.git synced 2025-11-22 16:26:10 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

Support oss

This commit is contained in:
sunnylqm
2020-03-06 18:56:15 +08:00
parent 76d958c623
commit 0b217484b7
7 changed files with 302 additions and 1174 deletions

View File

@@ -2,7 +2,7 @@
* Created by tdzl2003 on 2/13/16.
*/
const fetch = require('isomorphic-fetch');
const fetch = require('node-fetch');
let host = process.env.PUSHY_REGISTRY || 'https://update.reactnative.cn/api';
const fs = require('fs-extra');
import request from 'request';
@@ -17,7 +17,9 @@ exports.loadSession = async function() {
exports.replaceSession(JSON.parse(fs.readFileSync('.update', 'utf8')));
savedSession = session;
} catch (e) {
console.error('Failed to parse file `.update`. Try to remove it manually.');
console.error(
'Failed to parse file `.update`. Try to remove it manually.',
);
throw e;
}
}
@@ -54,7 +56,9 @@ async function query(url, options) {
const resp = await fetch(url, options);
const json = await resp.json();
if (resp.status !== 200) {
throw Object.assign(new Error(json.message || json.error), { status: resp.status });
throw Object.assign(new Error(json.message || json.error), {
status: resp.status,
});
}
return json;
}
@@ -89,7 +93,7 @@ exports.put = queryWithBody('PUT');
exports.doDelete = queryWithBody('DELETE');
async function uploadFile(fn) {
const { url, fieldName, formData } = await exports.post('/upload', {});
const { url, formData } = await exports.post('/upload', {});
let realUrl = url;
if (!/^https?\:\/\//.test(url)) {
@@ -120,9 +124,17 @@ async function uploadFile(fn) {
return reject(err);
}
if (resp.statusCode > 299) {
return reject(Object.assign(new Error(body), { status: resp.statusCode }));
return reject(
Object.assign(new Error(body), { status: resp.statusCode }),
);
}
resolve(JSON.parse(body));
resolve(
body
? // qiniu
JSON.parse(body)
: // aliyun oss
{ hash: formData.key },
);
},
);
});

View File

@@ -47,7 +47,7 @@ export async function choosePackage(appId) {
export const commands = {
uploadIpa: async function({ args }) {
const fn = args[0];
if (!fn) {
if (!fn || !fn.endsWith('.ipa')) {
throw new Error('Usage: pushy uploadIpa <ipaFile>');
}
const { versionName, buildTime } = await getIpaInfo(fn);
@@ -60,12 +60,12 @@ export const commands = {
hash,
buildTime,
});
saveToLocal(fn, `${appId}/${id}.ipa`);
saveToLocal(fn, `${appId}/package/${id}.ipa`);
console.log(`Ipa uploaded: ${id}`);
},
uploadApk: async function({ args }) {
const fn = args[0];
if (!fn) {
if (!fn || !fn.endsWith('.apk')) {
throw new Error('Usage: pushy uploadApk <apkFile>');
}
const { versionName, buildTime } = await getApkInfo(fn);
@@ -78,7 +78,7 @@ export const commands = {
hash,
buildTime,
});
saveToLocal(fn, `${appId}/${id}.apk`);
saveToLocal(fn, `${appId}/package/${id}.apk`);
console.log(`Apk uploaded: ${id}`);
},
packages: async function({ options }) {

View File

@@ -95,7 +95,8 @@ export async function getIpaInfo(fn) {
const localDir = path.resolve(os.homedir(), '.pushy');
fs.ensureDirSync(localDir);
export function saveToLocal(originPath, destName) {
const destPath = path.join(localDir, destName);
fs.ensureDirSync(path.dirname(destPath));
fs.copyFileSync(originPath, destPath);
// TODO
// const destPath = path.join(localDir, destName);
// fs.ensureDirSync(path.dirname(destPath));
// fs.copyFileSync(originPath, destPath);
}

View File

@@ -8,7 +8,7 @@ const {
put,
uploadFile,
} = require('./api');
import { question } from './utils';
import { question, saveToLocal } from './utils';
import { checkPlatform, getSelectedApp } from './app';
import { choosePackage } from './package';
@@ -86,6 +86,8 @@ export const commands = {
description: description || await question('Enter description:'),
metaInfo: metaInfo || await question('Enter meta info:'),
});
// TODO local diff
saveToLocal(fn, `${appId}/ppk/${id}.ppk`);
console.log(`Version published: ${id}`);
const v = await question('Would you like to bind packages to this version?(Y/N)');