1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
tdzl2003 2016-04-05 00:48:22 +08:00
parent 2b39280f50
commit 28a11bc19e
5 changed files with 44 additions and 16 deletions
android/src/main/java/cn/reactnative/modules/update
lib
local-cli/src

@ -124,6 +124,14 @@ public class UpdateContext {
this.clearUp();
}
public void clearRollbackMark() {
SharedPreferences.Editor editor = sp.edit();
editor.putBoolean("rolledBack", false);
editor.apply();
this.clearUp();
}
public static String getBundleUrl(Context context) {
return new UpdateContext(context.getApplicationContext()).getBundleUrl();
}
@ -133,7 +141,7 @@ public class UpdateContext {
}
public String getBundleUrl() {
return this.getBundleUrl((String)null);
return this.getBundleUrl((String) null);
}
public String getBundleUrl(String defaultAssetsUrl) {
@ -150,7 +158,7 @@ public class UpdateContext {
editor.putBoolean("shouldRollback", true);
editor.apply();
}
return new File(rootDir, currentVersion+"/index.bundlejs").toURI().toString();
return (new File(rootDir, currentVersion+"/index.bundlejs").toString());
}
private void rollBack() {

@ -34,8 +34,12 @@ public class UpdateModule extends ReactContextBaseJavaModule{
constants.put("downloadRootDir", updateContext.getRootDir());
constants.put("packageVersion", updateContext.getPackageVersion());
constants.put("currentVersion", updateContext.getCurrentVersion());
constants.put("firstTime", updateContext.isFirstTime());
constants.put("rolledBack", updateContext.isRolledBack());
constants.put("isFirstTime", updateContext.isFirstTime());
boolean isRolledBack = updateContext.isRolledBack();
constants.put("isRolledBack", isRolledBack);
if (isRolledBack) {
updateContext.clearRollbackMark();
}
return constants;
}

@ -38,6 +38,10 @@ There is available update:
export async function checkUpdate(APPKEY) {
const resp = await fetch(`${host}/checkUpdate/${APPKEY}`, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
packageVersion: packageVersion,
hash: currentVersion,
@ -75,11 +79,11 @@ export async function downloadUpdate(options) {
}
}
export async function switchVersion({hash}) {
export async function switchVersion(hash) {
HotUpdate.reloadUpdate({hashName:hash});
}
export async function switchVersionLater({hash}) {
export async function switchVersionLater(hash) {
HotUpdate.setNeedUpdate({hashName:hash});
}

@ -12,6 +12,7 @@ import * as fs from 'fs';
import {ZipFile} from 'yazl';
import {open as openZipFile} from 'yauzl';
import {diff} from 'node-bsdiff';
import { question } from './utils';
import crypto from 'crypto';
@ -28,8 +29,7 @@ function mkdir(dir){
}
async function pack(dir, output){
const realOutput = output.replace(/\$\{time\}/g, '' + Date.now());
await mkdir(path.dirname(realOutput));
await mkdir(path.dirname(output));
await new Promise((resolve, reject) => {
var zipfile = new ZipFile();
@ -57,13 +57,13 @@ async function pack(dir, output){
addDirectory(dir, '');
zipfile.outputStream.on('error', err => reject(err));
zipfile.outputStream.pipe(fs.createWriteStream(realOutput))
zipfile.outputStream.pipe(fs.createWriteStream(output))
.on("close", function() {
resolve();
});
zipfile.end();
});
console.log('Bundled saved to: ' + realOutput);
console.log('Bundled saved to: ' + output);
}
function readEntire(entry, zipFile) {
@ -94,6 +94,8 @@ function basename(fn) {
}
async function diffWithPPK(origin, next, output) {
await mkdir(path.dirname(output));
const originEntries = {};
const originMap = {};
@ -208,6 +210,8 @@ async function diffWithPPK(origin, next, output) {
}
async function diffWithPackage(origin, next, output, originBundleName, transformPackagePath = v=>v) {
await mkdir(path.dirname(output));
const originEntries = {};
const originMap = {};
@ -320,6 +324,7 @@ export const commands = {
dev,
verbose
} = translateOptions(options);
const realOutput = output.replace(/\$\{time\}/g, '' + Date.now());
if (!platform) {
throw new Error('Platform must be specified.');
@ -359,7 +364,14 @@ export const commands = {
console.log('Packing');
await pack(intermediaDir, output);
await pack(intermediaDir, realOutput);
const v = await question('Would you like to publish it?(Y/N)');
if (v.toLowerCase() === 'y') {
await this.publish({args: [realOutput], options: {
platform,
}})
}
},
async diff({args, options}) {
@ -374,6 +386,7 @@ export const commands = {
}
await diffWithPPK(origin, next, realOutput, 'index.bundlejs');
console.log(`${realOutput} generated.`);
},
async diffFromApk({args, options}) {

@ -57,7 +57,6 @@ async function chooseVersion(appId) {
case 'B': offset = 0; break;
default:
{
console.log(data.find(v=>v.id === (cmd | 0)));
const v = data.find(v=>v.id === (cmd | 0));
if (v) {
return v;
@ -79,16 +78,16 @@ export const commands = {
const { hash } = await uploadFile(fn);
const { id } = await post(`/app/${appId}/version/create`, {
name,
name: name || await question('Enter version name:') || '(未命名)',
hash,
description,
metaInfo,
description: description || await question('Enter description:'),
metaInfo: metaInfo || await question('Enter meta info:'),
});
console.log('Ok.');
const v = await question('Would you like to bind packages to this version?(Y/N)');
if (v.toLowerCase() === 'y') {
await this.update({args:[], options:{packageId: id, }});
await this.update({args:[], options:{packageId: id, platform}});
}
},
versions: async function({options}) {