Skip to content

Commit a3c7f87

Browse files
committed
app use suffix replace preffix
1 parent 31af0b9 commit a3c7f87

7 files changed

Lines changed: 56 additions & 27 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ CodePush Server is a CodePush progam server! microsoft CodePush cloud is slow in
1212
## 正确使用code-push热更新
1313

1414
- 苹果允许使用热更新[Apple's developer agreement](https://developer.apple.com/programs/ios/information/iOS_Program_Information_4_3_15.pdf), 但是规定不能弹框提示用户更新,影响用户体验。 而Google Play恰好相反,必须弹框告知用户更新。然而中国的android市场都必须关闭更新弹框,否则会在审核应用时以“请上传最新版本的二进制应用包”驳回应用。
15-
- react-native 不同平台bundle包不一样,在使用code-push-server的时候必须创建不同的应用来区分(eg. ios_CodePushDemo 和 android_CodePushDemo)
15+
- react-native 不同平台bundle包不一样,在使用code-push-server的时候必须创建不同的应用来区分(eg. CodePushDemo-ios 和 CodePushDemo-android)
1616
- react-native-code-push只更新资源文件,不会更新java和Objective C,所以npm升级依赖包版本的时候,如果依赖包使用的本地化实现, 这时候必须更改应用版本号(ios修改Info.plist中的CFBundleShortVersionString, android修改build.gradle中的versionName), 然后重新编译app发布到应用商店。
17-
- 推荐使用code-push release-react 命令发布应用,该命令合并了打包和发布命令(eg. code-push release-react ios_CodePushDemo ios -d Production)
17+
- 推荐使用code-push release-react 命令发布应用,该命令合并了打包和发布命令(eg. code-push release-react CodePushDemo-ios ios -d Production)
1818

1919
## EXAMPLE
2020

‎docs/react-native-code-push.md‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ $ PORT=3000 HOST=127.0.0.1 node ./bin/www
5959

6060
```shell
6161
$ code-push login http://127.0.0.1:3000 #浏览器中登录获取token,用户名:admin, 密码:123456
62-
$ code-push app add ios_CodePushDemo #创建iOS版, 获取Production DeploymentKey
63-
$ code-push app add android_CodePushDemo #创建android版,获取获取Production DeploymentKey
62+
$ code-push app add CodePushDemo-ios #创建iOS版, 获取Production DeploymentKey
63+
$ code-push app add CodePushDemo-android #创建android版,获取获取Production DeploymentKey
6464
```
6565

6666
## 配置CodePushDemo react-native项目
@@ -69,7 +69,7 @@ $ code-push app add android_CodePushDemo #创建android版,获取获取Product
6969

7070
编辑`Info.plist`文件,添加`CodePushDeploymentKey`和`CodePushServerURL`
7171

72-
1. `CodePushDeploymentKey`值设置为ios_CodePushDemo的Production DeploymentKey值。
72+
1. `CodePushDeploymentKey`值设置为CodePushDemo-ios的Production DeploymentKey值。
7373

7474
2. `CodePushServerURL`值设置为code-push-server服务地址 http://127.0.0.1:3000/ 不在同一台机器的时候,请将127.0.0.1改成外网ip或者域名地址。
7575

@@ -88,7 +88,7 @@ $ code-push app add android_CodePushDemo #创建android版,获取获取Product
8888

8989
编辑`MainApplication.java`
9090

91-
1. `YourKey`替换成android_CodePushDemo的Production DeploymentKey值
91+
1. `YourKey`替换成CodePushDemo-android的Production DeploymentKey值
9292

9393
2. `YourCodePushServerUrl`值设置为code-push-server服务地址 http://127.0.0.1:3000/ 不在同一台机器的时候,请将127.0.0.1改成外网ip或者域名地址。
9494

@@ -150,21 +150,21 @@ $ cd app/build/outputs/apk #将打好的包app-release.apk安装到您的手机
150150

151151
## 发布更新到服务上
152152

153-
iOS和android要分开发布,所以创建了`ios_CodePushDemo`和`android_CodePushDemo`应用
153+
iOS和android要分开发布,所以创建了`CodePushDemo-ios`和`CodePushDemo-android`应用
154154

155155
```shell
156156
$ cd /path/to/CodePushDemo
157-
$ code-push release-react ios_CodePushDemo ios -d Production #iOS版
158-
$ code-push release-react android_CodePushDemo android -d Production #android版
157+
$ code-push release-react CodePushDemo-ios ios -d Production #iOS版
158+
$ code-push release-react CodePushDemo-android android -d Production #android版
159159
```
160160

161161

162162
## 注意事项
163163

164164
- 苹果允许使用热更新[Apple's developer agreement](https://developer.apple.com/programs/ios/information/iOS_Program_Information_4_3_15.pdf), 但是规定不能弹框提示用户更新,影响用户体验。 而Google Play恰好相反,必须弹框告知用户更新。然而中国的android市场都必须关闭更新弹框,否则会在审核应用时以“请上传最新版本的二进制应用包”驳回应用。
165-
- react-native 不同平台bundle包不一样,在使用code-push-server的时候必须创建不同的应用来区分(eg. ios_CodePushDemo 和 android_CodePushDemo)
165+
- react-native 不同平台bundle包不一样,在使用code-push-server的时候必须创建不同的应用来区分(eg. CodePushDemo-ios 和 CodePushDemo-android)
166166
- react-native-code-push只更新资源文件,不会更新java和Objective C,所以npm升级依赖包版本的时候,如果依赖包使用的本地化实现, 这时候必须更改应用版本号(ios修改Info.plist中的CFBundleShortVersionString, android修改build.gradle中的versionName), 然后重新编译app发布到应用商店。
167-
- 推荐使用code-push release-react 命令发布应用,该命令合并了打包和发布命令(eg. code-push release-react ios_CodePushDemo ios -d Production)
167+
- 推荐使用code-push release-react 命令发布应用,该命令合并了打包和发布命令(eg. code-push release-react CodePushDemo-ios ios -d Production)
168168

169169
## 例子
170170

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "code-push-server",
3-
"description": "Base on microsoft CodePush project, adaptor code-push-cli and react-native-code-push, setup react-native hot update service for yourself",
3+
"description": "CodePush service",
44
"version": "0.2.1",
55
"license": "MIT",
66
"repository": {

‎routes/apps.js‎

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ var AppManager = require('../core/services/app-manager');
1111
var PackageManager = require('../core/services/package-manager');
1212
var common = require('../core/utils/common');
1313
var config = require('../core/config');
14+
const REGEX = /^(\w+)(-android|-ios)$/;
15+
const REGEX_ANDROID = /^(\w+)(-android)$/;
16+
const REGEX_IOS = /^(\w+)(-ios)$/;
17+
const OLD_REGEX_ANDROID = /^(android_)/;
18+
const OLD_REGEX_IOS = /^(ios_)/;
1419

1520
router.get('/',
1621
middleware.checkToken, function(req, res, next) {
@@ -203,15 +208,16 @@ router.post('/:appName/deployments/:deploymentName/release',
203208
var uid = req.users.id;
204209
var deployments = new Deployments();
205210
var packageManager = new PackageManager();
206-
const AREGEX = /^android_/;
207-
var pubType = '';
208-
if (AREGEX.test(appName)) {
209-
pubType = 'android';
210-
} else {
211-
pubType = 'ios';
212-
}
213211
accountManager.collaboratorCan(uid, appName)
214212
.then(function (col) {
213+
var pubType = '';
214+
if (REGEX_ANDROID.test(appName)) {
215+
pubType = 'android';
216+
} else if (REGEX_IOS.test(appName)) {
217+
pubType = 'ios';
218+
} else {
219+
throw new Error(`you have to rename app name, eg. Demo-android Demo-ios`);
220+
}
215221
return deployments.findDeloymentByName(deploymentName, col.appid)
216222
.then(function (deploymentInfo) {
217223
if (_.isEmpty(deploymentInfo)) {
@@ -425,6 +431,17 @@ router.patch('/:appName',
425431
var appManager = new AppManager();
426432
return accountManager.ownerCan(uid, appName)
427433
.then(function (col) {
434+
if (REGEX_ANDROID.test(appName) || OLD_REGEX_ANDROID.test(appName)) {
435+
if (!REGEX_ANDROID.test(newAppName)) {
436+
throw new Error(`new appName have to point -android suffix! eg. Demo-android`);
437+
}
438+
} else if (REGEX_IOS.test(appName) || OLD_REGEX_IOS.test(appName)) {
439+
if (!REGEX_IOS.test(newAppName)) {
440+
throw new Error(`new appName have to point -ios suffix! eg. Demo-ios`);
441+
}
442+
} else {
443+
throw new Error(`appName have to point -android or -ios suffix! eg. ${appName}-android ${appName}-ios`);
444+
}
428445
return appManager.findAppByName(uid, newAppName)
429446
.then(function (appInfo) {
430447
if (!_.isEmpty(appInfo)){
@@ -476,14 +493,13 @@ router.post('/', middleware.checkToken, function (req, res, next) {
476493
if (_.isEmpty(appName)) {
477494
return res.status(406).send("Please input name!");
478495
}
479-
const REGEX = /^[android_|ios_]/;
480496
appManager.findAppByName(uid, appName)
481497
.then(function (appInfo) {
482498
if (!_.isEmpty(appInfo)){
483499
throw new Error(appName + " Exist!");
484500
}
485501
if (!REGEX.test(appName)) {
486-
throw new Error(`appName have to point android_ or ios_ prefix! like android_${appName} ios_${appName}`);
502+
throw new Error(`appName have to point -android or -ios suffix! eg. ${appName}-android ${appName}-ios`);
487503
}
488504
return appManager.addApp(uid, appName, req.users.identical)
489505
.then(function () {

‎test/api/apps/apps.test.js‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ describe('api/apps/apps.test.js', function() {
1313
var authToken;
1414
var machineName = `Login-${Math.random()}`;
1515
var friendlyName = `Login-${Math.random()}`;
16-
var appName = 'ios_test';
17-
var newAppName = 'ios_newtest';
16+
var appName = 'test-ios';
17+
var newAppName = 'newtest-ios';
1818
var bearerToken;
1919
var testDeployment = 'test';
2020
var newTestDeployment = 'newtest';
@@ -73,7 +73,7 @@ describe('api/apps/apps.test.js', function() {
7373
.end(function(err, res) {
7474
should.not.exist(err);
7575
res.status.should.equal(406);
76-
res.text.should.equal(`appName have to point android_ or ios_ prefix! like android_${appName} ios_${appName}`);
76+
res.text.should.equal(`appName have to point -android or -ios suffix! eg. ${appName}-android ${appName}-ios`);
7777
done();
7878
});
7979
});
@@ -429,7 +429,20 @@ describe('api/apps/apps.test.js', function() {
429429
});
430430
});
431431

432-
it(`should rename apps successful when new name does exists`, function(done) {
432+
it(`should not rename apps successful when new name invalid`, function(done) {
433+
var newAppName = 'newtest';
434+
request.patch(`/apps/${appName}`)
435+
.set('Authorization', `Bearer ${bearerToken}`)
436+
.send({name: newAppName})
437+
.end(function(err, res) {
438+
should.not.exist(err);
439+
res.status.should.equal(406);
440+
res.text.should.equal(`new appName have to point -ios suffix! eg. Demo-ios`);
441+
done();
442+
});
443+
});
444+
445+
it(`should rename apps successful`, function(done) {
433446
request.patch(`/apps/${appName}`)
434447
.set('Authorization', `Bearer ${bearerToken}`)
435448
.send({name: newAppName})

‎test/api/apps/release.test.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('api/apps/release.test.js', function() {
1313
var authToken;
1414
var machineName = `Login-${Math.random()}`;
1515
var friendlyName = `Login-${Math.random()}`;
16-
var appName = 'ios_demo';
16+
var appName = 'Demo-ios';
1717
var bearerToken;
1818

1919
before(function(done){

‎test/api/index/index.test.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe('api/index/index.test.js', function() {
77
var account = '522539441@qq.com';
88
var password = '123456';
99
var authToken;
10-
var appName = 'ios_demo';
10+
var appName = 'Demo-ios';
1111
var deploymentKey;
1212
var packageHash;
1313
var label;

0 commit comments

Comments
 (0)