Skip to content

Commit d46cb5b

Browse files
committed
initial commit
1 parent db7ad26 commit d46cb5b

22 files changed

+6759
-0
lines changed

.babelrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"plugins": [
3+
"syntax-object-rest-spread",
4+
"syntax-async-functions",
5+
"transform-es2015-arrow-functions",
6+
"transform-async-to-generator",
7+
"transform-es2015-modules-commonjs",
8+
"transform-es2015-destructuring",
9+
"transform-es2015-spread",
10+
"transform-object-rest-spread",
11+
"transform-es2015-parameters",
12+
"transform-strict-mode"
13+
]
14+
}

.prettierrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
trailingComma: 'all',
3+
singleQuote: true,
4+
};

cli.json

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
{
2+
"useCommand": true,
3+
"defaultCommand": "help",
4+
"commands": {
5+
"help": {
6+
},
7+
8+
"login":{
9+
},
10+
"logout": {
11+
},
12+
"me": {
13+
},
14+
15+
"createApp": {
16+
"options": {
17+
"name": {
18+
"hasValue": true
19+
},
20+
"platform": {
21+
"hasValue": true
22+
}
23+
}
24+
},
25+
"apps": {
26+
"options": {
27+
"platform": {
28+
"hasValue": true
29+
}
30+
}
31+
},
32+
"deleteApp": {
33+
},
34+
"selectApp": {
35+
"options": {
36+
"platform": {
37+
"hasValue": true
38+
}
39+
}
40+
},
41+
42+
"uploadIpa": {
43+
},
44+
"uploadApk": {
45+
},
46+
"packages": {
47+
"options": {
48+
"platform": {
49+
"hasValue": true
50+
}
51+
}
52+
},
53+
54+
"publish": {
55+
"options": {
56+
"platform": {
57+
"hasValue": true
58+
},
59+
"name": {
60+
"hasValue": true
61+
},
62+
"description": {
63+
"hasValue": true
64+
},
65+
"metaInfo": {
66+
"hasValue": true
67+
}
68+
}
69+
},
70+
"versions": {
71+
"options": {
72+
"platform": {
73+
"hasValue": true
74+
}
75+
}
76+
},
77+
78+
"update": {
79+
"options": {
80+
"platform": {
81+
"hasValue": true
82+
},
83+
"versionId": {
84+
"hasValue": true
85+
},
86+
"packageId": {
87+
"hasValue": true
88+
}
89+
}
90+
},
91+
92+
"build": {
93+
"description": "Bundle javascript and copy assets."
94+
},
95+
"bundle": {
96+
"description": "Bundle javascript code only.",
97+
"options": {
98+
"dev": {
99+
"default": "false",
100+
"hasValue": true
101+
},
102+
"platform": {
103+
"hasValue": true
104+
},
105+
"bundleName":{
106+
"default": "index.bundlejs",
107+
"hasValue": true
108+
},
109+
"entryFile": {
110+
"default": "index.js",
111+
"hasValue": true
112+
},
113+
"intermediaDir": {
114+
"default": "build/intermedia/${platform}",
115+
"hasValue": true
116+
},
117+
"output": {
118+
"default": "build/output/${platform}.${time}.ppk",
119+
"hasValue": true
120+
},
121+
"verbose": {
122+
123+
}
124+
}
125+
},
126+
"release": {
127+
"description": "Push builded file to server."
128+
},
129+
"diff": {
130+
"description": "Create diff patch",
131+
"options": {
132+
"output": {
133+
"default": "build/output/diff",
134+
"hasValue": true
135+
}
136+
}
137+
},
138+
"diffFromApk": {
139+
"description": "Create diff patch from a Android package(.apk)",
140+
"options": {
141+
"output": {
142+
"default": "build/output/diff-${time}.apk-patch",
143+
"hasValue": true
144+
}
145+
}
146+
},
147+
"diffFromIpa": {
148+
"description": "Create diff patch from a iOS package(.ipa)",
149+
"options": {
150+
"output": {
151+
"default": "build/output/diff-${time}.ipa-patch",
152+
"hasValue": true
153+
}
154+
}
155+
}
156+
},
157+
"globalOptions":{
158+
"no-interactive": {
159+
"default": false
160+
}
161+
}
162+
}

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* Created by tdzl2003 on 2/22/16.
3+
*/
4+
module.exports = require('./lib');

lib/api.js

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
'use strict';
2+
3+
let query = function () {
4+
var _ref2 = _asyncToGenerator(function* (url, options) {
5+
const resp = yield fetch(url, options);
6+
const json = yield resp.json();
7+
if (resp.status !== 200) {
8+
throw Object.assign(new Error(json.message || json.error), { status: resp.status });
9+
}
10+
return json;
11+
});
12+
13+
return function query(_x, _x2) {
14+
return _ref2.apply(this, arguments);
15+
};
16+
}();
17+
18+
let uploadFile = function () {
19+
var _ref3 = _asyncToGenerator(function* (fn) {
20+
var _ref4 = yield exports.post('/upload', {});
21+
22+
const url = _ref4.url,
23+
fieldName = _ref4.fieldName,
24+
formData = _ref4.formData;
25+
26+
let realUrl = url;
27+
28+
if (!/^https?\:\/\//.test(url)) {
29+
realUrl = host + url;
30+
}
31+
32+
const fileSize = fs.statSync(fn).size;
33+
34+
const bar = new _progress2.default(' Uploading [:bar] :percent :etas', {
35+
complete: '=',
36+
incomplete: ' ',
37+
total: fileSize
38+
});
39+
40+
const info = yield new Promise(function (resolve, reject) {
41+
formData.file = fs.createReadStream(fn);
42+
43+
formData.file.on('data', function (data) {
44+
bar.tick(data.length);
45+
});
46+
_request2.default.post(realUrl, {
47+
formData
48+
}, function (err, resp, body) {
49+
if (err) {
50+
return reject(err);
51+
}
52+
if (resp.statusCode > 299) {
53+
return reject(Object.assign(new Error(body), { status: resp.statusCode }));
54+
}
55+
resolve(JSON.parse(body));
56+
});
57+
});
58+
return info;
59+
});
60+
61+
return function uploadFile(_x3) {
62+
return _ref3.apply(this, arguments);
63+
};
64+
}();
65+
66+
var _request = require('request');
67+
68+
var _request2 = _interopRequireDefault(_request);
69+
70+
var _progress = require('progress');
71+
72+
var _progress2 = _interopRequireDefault(_progress);
73+
74+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
75+
76+
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
77+
78+
/**
79+
* Created by tdzl2003 on 2/13/16.
80+
*/
81+
82+
const fetch = require('isomorphic-fetch');
83+
let host = process.env.PUSHY_REGISTRY || 'https://update.reactnative.cn/api';
84+
const fs = require('fs-extra');
85+
86+
87+
let session = undefined;
88+
let savedSession = undefined;
89+
90+
exports.loadSession = _asyncToGenerator(function* () {
91+
if (fs.existsSync('.update')) {
92+
try {
93+
exports.replaceSession(JSON.parse(fs.readFileSync('.update', 'utf8')));
94+
savedSession = session;
95+
} catch (e) {
96+
console.error('Failed to parse file `.update`. Try to remove it manually.');
97+
throw e;
98+
}
99+
}
100+
});
101+
102+
exports.getSession = function () {
103+
return session;
104+
};
105+
106+
exports.replaceSession = function (newSession) {
107+
session = newSession;
108+
};
109+
110+
exports.saveSession = function () {
111+
// Only save on change.
112+
if (session !== savedSession) {
113+
const current = session;
114+
const data = JSON.stringify(current, null, 4);
115+
fs.writeFileSync('.update', data, 'utf8');
116+
savedSession = current;
117+
}
118+
};
119+
120+
exports.closeSession = function () {
121+
if (fs.existsSync('.update')) {
122+
fs.unlinkSync('.update');
123+
savedSession = undefined;
124+
}
125+
session = undefined;
126+
host = process.env.PUSHY_REGISTRY || 'https://update.reactnative.cn';
127+
};
128+
129+
function queryWithoutBody(method) {
130+
return function (api) {
131+
return query(host + api, {
132+
method,
133+
headers: {
134+
'X-AccessToken': session ? session.token : ''
135+
}
136+
});
137+
};
138+
}
139+
140+
function queryWithBody(method) {
141+
return function (api, body) {
142+
return query(host + api, {
143+
method,
144+
headers: {
145+
'Content-Type': 'application/json',
146+
'X-AccessToken': session ? session.token : ''
147+
},
148+
body: JSON.stringify(body)
149+
});
150+
};
151+
}
152+
153+
exports.get = queryWithoutBody('GET');
154+
exports.post = queryWithBody('POST');
155+
exports.put = queryWithBody('PUT');
156+
exports.doDelete = queryWithBody('DELETE');
157+
158+
exports.uploadFile = uploadFile;

0 commit comments

Comments
 (0)