Skip to content

Commit 48e1634

Browse files
Enjoy, world!
0 parents  commit 48e1634

File tree

101 files changed

+14843
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+14843
-0
lines changed

.editorconfig

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# editorconfig.org
2+
3+
root = true
4+
5+
[**]
6+
indent_size = 4
7+
indent_style = space
8+
charset = utf-8
9+
end_of_line = lf
10+
trim_trailing_whitespace = true
11+
12+
[**.html]
13+
indent_size = 2
14+
15+
[**.jade]
16+
indent_size = 2
17+
18+
[**.json]
19+
indent_size = 2
20+
21+
[**.scss]
22+
indent_size = 2
23+
insert_final_newline = true
24+
25+
[**.css]
26+
indent_size = 2
27+
insert_final_newline = true
28+
29+
[**.md]
30+
trim_trailing_whitespace = false
31+
32+
[**.js]
33+
indent_size = 2
34+
insert_final_newline = true
35+
36+
[**.yml]
37+
indent_size = 2
38+
39+
[Makefile]
40+
indent_style = tab

.gitignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Logs
2+
logs
3+
*.log
4+
5+
# Runtime data
6+
pids
7+
*.pid
8+
*.seed
9+
*.DS_Store
10+
11+
.grunt
12+
13+
# Dependency directory
14+
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
15+
node_modules
16+
17+
coverage
18+
19+
.idea

.travis.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
language: node_js
2+
env:
3+
- CXX=g++-4.8
4+
addons:
5+
apt:
6+
sources:
7+
- ubuntu-toolchain-r-test
8+
packages:
9+
- g++-4.8
10+
11+
services:
12+
- redis-server
13+
- mysql
14+
15+
node_js:
16+
- "8.10.0"
17+
- "7.5"
18+
- "7"
19+
- "6.9.5"
20+
- "6.1"
21+
- "6"
22+
23+
cache:
24+
directories:
25+
- node_modules
26+
before_install:
27+
# Update Node.js modules
28+
- "test ! -d node_modules || npm prune"
29+
- "test ! -d node_modules || npm rebuild"
30+
script: "npm run-script coverage"
31+
after_script: "npm install [email protected] && cat ./coverage/lcov.info | coveralls"

CHANGELOG.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Changelog for code-push-server
2+
3+
## 0.5.x
4+
5+
## 新特性
6+
- 针对文本增量更新进行优化,使用google `diff-match-patch` 算法计算差异
7+
- react-native-code-push Android客户端适配,需要合并https://github.com/Microsoft/react-native-code-push/pull/1393, 才能正常使用文本增量更新功能。
8+
- react-native-code-push iOS客户端适配 (需要合并https://github.com/Microsoft/react-native-code-push/pull/1399)
9+
- react-native-code-push Windows客户端适配 (进行中)
10+
11+
## fixbug
12+
13+
- 修复统计数据激活数
14+
- 修复灰度发布bug
15+
- rollback后增加计算和最后一次增量更新版本
16+
17+
## 如何升级到该版本
18+
19+
### 升级数据库
20+
21+
`$ npm run upgrade`
22+
23+
or
24+
25+
`$ code-push-server-db upgrade`
26+
27+
28+
## 0.4.x
29+
30+
### 新特性
31+
32+
- targetBinaryVersion 支持正则匹配, `deployments_versions`新增字段`min_version`,`max_version`
33+
- `*` 匹配所有版本
34+
- `1.2.3` 匹配特定版本`1.2.3`
35+
- `1.2`/`1.2.*` 匹配所有1.2补丁版本
36+
- `>=1.2.3<1.3.7`
37+
- `~1.2.3` 匹配`>=1.2.3<1.3.0`
38+
- `^1.2.3` 匹配`>=1.2.3<2.0.0`
39+
- 添加docker编排服务部署,更新文档
40+
- Support Tencent cloud cos storageType
41+
42+
## 如何升级到该版本
43+
44+
- 升级数据库
45+
`$ ./bin/db upgrade`
46+
or
47+
`$ mysql codepush < ./sql/codepush-v0.4.0-patch.sql`
48+
49+
- 处理存量数据
50+
``` shell
51+
$ git clone https://github.com/lisong/tools
52+
$ cd tools
53+
$ npm i
54+
$ vim ./bin/fixMinMaxVersion //修改数据配置
55+
$ node ./bin/fixMinMaxVersion //出现提示 success
56+
```
57+
58+
## 0.3.x
59+
60+
- 支持灰度发布
61+
- 适配`code-push app add` 命令,应用不再以名字区分平台,而是以类型区分平台
62+
- 数据库表apps新增字段`os`,`platform`
63+
- 完善`code-push release/release-react/release-cordova` 命令
64+
- 数据库表packages新增`is_disabled`,`rollout`字段
65+
- 适配`code-push patch`命令
66+
- 新增`log_report_download`,`log_report_deploy`日志表
67+
- 升级npm依赖包

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
(The MIT License)
2+
3+
Copyright (c) 2016-present tablee <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
'Software'), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Makefile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
ROOT=$(shell pwd)
2+
3+
test: test-integration
4+
5+
# test-unit:
6+
# @echo "\nRunning unit tests..."
7+
# @NODE_ENV=test CONFIG_FILE=${ROOT}/config/config.test.js mocha test/unit --recursive
8+
9+
test-integration:
10+
@echo "\nRunning integration tests..."
11+
@NODE_ENV=test CONFIG_FILE=${ROOT}/config/config.test.js mocha test/api/init
12+
@NODE_ENV=test PORT=3000 HOST=127.0.0.1 CONFIG_FILE=${ROOT}/config/config.test.js node bin/www &
13+
@NODE_ENV=test CONFIG_FILE=${ROOT}/config/config.test.js mocha \
14+
test/api/users test/api/auth test/api/account test/api/accessKeys test/api/apps test/api/index --recursive --timeout 15000
15+
16+
coverage:
17+
@echo "\n\nRunning coverage report..."
18+
rm -rf coverage
19+
# @NODE_ENV=test CONFIG_FILE=${ROOT}/config/config.test.js ./node_modules/istanbul/lib/cli.js cover --report lcovonly --dir coverage/core ./node_modules/.bin/_mocha \
20+
# test/unit -- -R spec --recursive --timeout 15000
21+
@NODE_ENV=test CONFIG_FILE=${ROOT}/config/config.test.js mocha test/api/init
22+
@NODE_ENV=test PORT=3000 HOST=127.0.0.1 CONFIG_FILE=${ROOT}/config/config.test.js node bin/www &
23+
@NODE_ENV=test CONFIG_FILE=${ROOT}/config/config.test.js ./node_modules/istanbul/lib/cli.js cover --report lcovonly --dir coverage/api ./node_modules/.bin/_mocha \
24+
test/api/users test/api/auth test/api/account test/api/accessKeys test/api/apps test/api/index -- -R spec --recursive --timeout 15000
25+
@NODE_ENV=test CONFIG_FILE=${ROOT}/config/config.test.js ./node_modules/istanbul/lib/cli.js report
26+
27+
.PHONY: coverage

Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: pm2 start process.json && pm2 logs all

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# CodePush Server [source](https://github.com/EddyVerbruggen/code-push-server)
2+
3+
## What's this then?
4+
This CodePush server is like a polyfill for MicroSoft's CodePush server, but with support for NativeScript apps.
5+
6+
Huge thanks to [this project](https://github.com/lisong/code-push-server) which this project is based upon.
7+
We didn't fork it because significant (non-unforkeable) changes had to be made (replacing hardcoded Chinese text by English comes to mind).
8+
9+
You can either roll your own clone of this server or use [the shared service we provide](https://nativescript-codepush-server.herokuapp.com/) (which is configured by default by the [NativeScript CodePush plugin](https://github.com/EddyVerbruggen/nativescript-code-push)).
10+
11+
## Support Storage mode
12+
13+
- local *storage bundle file in local machine*
14+
- qiniu *storage bundle file in [qiniu](http://www.qiniu.com/)*
15+
- s3 *storage bundle file in [aws](https://aws.amazon.com/)*
16+
- oss *storage bundle file in [aliyun](https://www.aliyun.com/product/oss)*
17+
- tencentcloud *storage bundle file in [tencentcloud](https://cloud.tencent.com/product/cos)*
18+
19+
### Shell login
20+
21+
With the [NativeScript CodePush CLI]() installed (`npm i -g nativescript-code-push`), you can do:
22+
23+
```shell
24+
$ nativescript-code-push login https://nativescript-codepush-server.herokuapp.com # or your own server endpoint
25+
```
26+
27+
### Web interface
28+
29+
[nativescript-codepush-server.herokuapp.com](https://nativescript-codepush-server.herokuapp.com/)
30+
31+
## HOW TO INSTALL code-push-server
32+
33+
- [Installation manual](https://github.com/EddyVerbruggen/code-push-server/blob/master/docs/README.md)
34+
35+
## DEFAULT ACCOUNT AND PASSWORD
36+
37+
- account: `admin`
38+
- password: `123456`

app.js

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
var express = require('express');
2+
var path = require('path');
3+
var favicon = require('serve-favicon');
4+
var cookieParser = require('cookie-parser');
5+
var bodyParser = require('body-parser');
6+
var helmet = require('helmet');
7+
var config = require('./core/config');
8+
var _ = require('lodash');
9+
var fs = require('fs');
10+
11+
var routes = require('./routes/index');
12+
var auth = require('./routes/auth');
13+
var accessKeys = require('./routes/accessKeys');
14+
var account = require('./routes/account');
15+
var users = require('./routes/users');
16+
var apps = require('./routes/apps');
17+
var AppError = require('./core/app-error');
18+
var log4js = require('log4js');
19+
var log = log4js.getLogger("cps:app");
20+
var app = express();
21+
app.use(helmet());
22+
app.disable('x-powered-by');
23+
// view engine setup
24+
app.set('views', path.join(__dirname, 'views'));
25+
app.set('view engine', 'pug');
26+
27+
app.use(log4js.connectLogger(log4js.getLogger("http"), {level: log4js.levels.INFO, nolog:'\\.gif|\\.jpg|\\.js|\\.css$' }));
28+
29+
app.use(bodyParser.json());
30+
app.use(bodyParser.urlencoded({ extended: false }));
31+
app.use(cookieParser());
32+
app.use(express.static(path.join(__dirname, 'public')));
33+
34+
//use nginx in production
35+
//if (app.get('env') === 'development') {
36+
log.debug("set Access-Control Header");
37+
app.all('*', function(req, res, next) {
38+
res.header("Access-Control-Allow-Origin", "*");
39+
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization, X-CodePush-Plugin-Version, X-CodePush-Plugin-Name, X-CodePush-SDK-Version");
40+
res.header("Access-Control-Allow-Methods","PUT,POST,GET,PATCH,DELETE,OPTIONS");
41+
log.debug("use set Access-Control Header");
42+
next();
43+
});
44+
//}
45+
46+
log.debug("config common.storageType value: " + _.get(config, 'common.storageType'));
47+
48+
if (_.get(config, 'common.storageType') === 'local') {
49+
var localStorageDir = _.get(config, 'local.storageDir');
50+
if (localStorageDir) {
51+
52+
log.debug("config common.storageDir value: " + localStorageDir);
53+
54+
if (!fs.existsSync(localStorageDir)) {
55+
var e = new Error(`Please create dir ${localStorageDir}`);
56+
log.error(e);
57+
throw e;
58+
}
59+
try {
60+
log.debug('checking storageDir fs.W_OK | fs.R_OK');
61+
fs.accessSync(localStorageDir, fs.W_OK | fs.R_OK);
62+
log.debug('storageDir fs.W_OK | fs.R_OK is ok');
63+
} catch (e) {
64+
log.error(e);
65+
throw e;
66+
}
67+
log.debug("static download uri value: " + _.get(config, 'local.public', '/download'));
68+
app.use(_.get(config, 'local.public', '/download'), express.static(localStorageDir));
69+
} else {
70+
log.error('please config local storageDir');
71+
}
72+
}
73+
74+
app.use('/', routes);
75+
app.use('/auth', auth);
76+
app.use('/accessKeys', accessKeys);
77+
app.use('/account', account);
78+
app.use('/users', users);
79+
app.use('/apps', apps);
80+
81+
// development error handler
82+
// will print stacktrace
83+
if (app.get('env') === 'development') {
84+
app.use(function(req, res, next) {
85+
var err = new AppError.NotFound();
86+
res.status(err.status || 404);
87+
res.render('error', {
88+
message: err.message,
89+
error: err
90+
});
91+
log.error(err);
92+
});
93+
app.use(function(err, req, res, next) {
94+
res.status(err.status || 500);
95+
res.render('error', {
96+
message: err.message,
97+
error: err
98+
});
99+
log.error(err);
100+
});
101+
} else {
102+
app.use(function(req, res, next) {
103+
var e = new AppError.NotFound();
104+
res.status(404).send(e.message);
105+
log.debug(e);
106+
});
107+
// production error handler
108+
// no stacktraces leaked to user
109+
app.use(function(err, req, res, next) {
110+
if (err instanceof AppError.AppError) {
111+
res.send(err.message);
112+
log.debug(err);
113+
} else {
114+
res.status(err.status || 500).send(err.message);
115+
log.error(err);
116+
}
117+
});
118+
}
119+
120+
module.exports = app;

0 commit comments

Comments
 (0)