From 28a11bc19e629588e3e36145b98552d4c90439a0 Mon Sep 17 00:00:00 2001 From: tdzl2003 Date: Tue, 5 Apr 2016 00:48:22 +0800 Subject: [PATCH] bugfixes --- .../modules/update/UpdateContext.java | 12 ++++++++-- .../modules/update/UpdateModule.java | 8 +++++-- lib/index.js | 8 +++++-- local-cli/src/bundle.js | 23 +++++++++++++++---- local-cli/src/versions.js | 9 ++++---- 5 files changed, 44 insertions(+), 16 deletions(-) diff --git a/android/src/main/java/cn/reactnative/modules/update/UpdateContext.java b/android/src/main/java/cn/reactnative/modules/update/UpdateContext.java index aa61dab..c46e2c7 100644 --- a/android/src/main/java/cn/reactnative/modules/update/UpdateContext.java +++ b/android/src/main/java/cn/reactnative/modules/update/UpdateContext.java @@ -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() { diff --git a/android/src/main/java/cn/reactnative/modules/update/UpdateModule.java b/android/src/main/java/cn/reactnative/modules/update/UpdateModule.java index c2ad033..be68b69 100644 --- a/android/src/main/java/cn/reactnative/modules/update/UpdateModule.java +++ b/android/src/main/java/cn/reactnative/modules/update/UpdateModule.java @@ -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; } diff --git a/lib/index.js b/lib/index.js index c9943aa..f74c8de 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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}); } diff --git a/local-cli/src/bundle.js b/local-cli/src/bundle.js index faeeb0c..44ebde3 100644 --- a/local-cli/src/bundle.js +++ b/local-cli/src/bundle.js @@ -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}) { diff --git a/local-cli/src/versions.js b/local-cli/src/versions.js index 0250285..23c2604 100644 --- a/local-cli/src/versions.js +++ b/local-cli/src/versions.js @@ -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}) {