react-native-update-cli 2.1.2 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/api.js +7 -4
- package/lib/bundle.js +7 -1
- package/lib/utils/constants.js +9 -3
- package/lib/utils/http-helper.js +90 -0
- package/lib/utils/index.js +1 -1
- package/package.json +1 -1
- package/src/api.ts +7 -6
- package/src/bundle.ts +6 -2
- package/src/utils/constants.ts +3 -3
- package/src/utils/http-helper.ts +83 -0
package/lib/api.js
CHANGED
|
@@ -54,6 +54,7 @@ const _tcpping = /*#__PURE__*/ _interop_require_default(require("tcp-ping"));
|
|
|
54
54
|
const _packagejson = /*#__PURE__*/ _interop_require_default(require("../package.json"));
|
|
55
55
|
const _constants = require("./utils/constants");
|
|
56
56
|
const _i18n = require("./utils/i18n");
|
|
57
|
+
const _httphelper = require("./utils/http-helper");
|
|
57
58
|
function _interop_require_default(obj) {
|
|
58
59
|
return obj && obj.__esModule ? obj : {
|
|
59
60
|
default: obj
|
|
@@ -62,7 +63,6 @@ function _interop_require_default(obj) {
|
|
|
62
63
|
const tcpPing = _util.default.promisify(_tcpping.default.ping);
|
|
63
64
|
let session;
|
|
64
65
|
let savedSession;
|
|
65
|
-
const host = process.env.PUSHY_REGISTRY || process.env.RNU_API || _constants.defaultEndpoint;
|
|
66
66
|
const userAgent = `react-native-update-cli/${_packagejson.default.version}`;
|
|
67
67
|
const getSession = ()=>session;
|
|
68
68
|
const replaceSession = (newSession)=>{
|
|
@@ -96,7 +96,9 @@ const closeSession = ()=>{
|
|
|
96
96
|
session = undefined;
|
|
97
97
|
};
|
|
98
98
|
async function query(url, options) {
|
|
99
|
-
const
|
|
99
|
+
const baseUrl = await _httphelper.getBaseUrl;
|
|
100
|
+
const fullUrl = `${baseUrl}${url}`;
|
|
101
|
+
const resp = await (0, _nodefetch.default)(fullUrl, options);
|
|
100
102
|
const text = await resp.text();
|
|
101
103
|
let json;
|
|
102
104
|
try {
|
|
@@ -112,7 +114,7 @@ async function query(url, options) {
|
|
|
112
114
|
return json;
|
|
113
115
|
}
|
|
114
116
|
function queryWithoutBody(method) {
|
|
115
|
-
return (api)=>query(
|
|
117
|
+
return (api)=>query(api, {
|
|
116
118
|
method,
|
|
117
119
|
headers: {
|
|
118
120
|
'User-Agent': userAgent,
|
|
@@ -121,7 +123,7 @@ function queryWithoutBody(method) {
|
|
|
121
123
|
});
|
|
122
124
|
}
|
|
123
125
|
function queryWithBody(method) {
|
|
124
|
-
return (api, body)=>query(
|
|
126
|
+
return (api, body)=>query(api, {
|
|
125
127
|
method,
|
|
126
128
|
headers: {
|
|
127
129
|
'User-Agent': userAgent,
|
|
@@ -141,6 +143,7 @@ async function uploadFile(fn, key) {
|
|
|
141
143
|
});
|
|
142
144
|
let realUrl = url;
|
|
143
145
|
if (backupUrl) {
|
|
146
|
+
// @ts-ignore
|
|
144
147
|
if (global.USE_ACC_OSS) {
|
|
145
148
|
realUrl = backupUrl;
|
|
146
149
|
} else {
|
package/lib/bundle.js
CHANGED
|
@@ -544,6 +544,7 @@ async function diffFromPPK(origin, next, output) {
|
|
|
544
544
|
throw new Error('Bundle file not found! Please use default bundle file name and path.');
|
|
545
545
|
}
|
|
546
546
|
const copies = {};
|
|
547
|
+
const copiesv2 = {};
|
|
547
548
|
const zipfile = new _yazl.ZipFile();
|
|
548
549
|
const writePromise = new Promise((resolve, reject)=>{
|
|
549
550
|
zipfile.outputStream.on('error', (err)=>{
|
|
@@ -601,6 +602,7 @@ async function diffFromPPK(origin, next, output) {
|
|
|
601
602
|
addEntry(base);
|
|
602
603
|
}
|
|
603
604
|
copies[entry.fileName] = originMap[entry.crc32];
|
|
605
|
+
copiesv2[entry.crc32] = entry.fileName;
|
|
604
606
|
return;
|
|
605
607
|
}
|
|
606
608
|
// New file.
|
|
@@ -631,6 +633,7 @@ async function diffFromPPK(origin, next, output) {
|
|
|
631
633
|
//console.log({copies, deletes});
|
|
632
634
|
zipfile.addBuffer(Buffer.from(JSON.stringify({
|
|
633
635
|
copies,
|
|
636
|
+
copiesv2,
|
|
634
637
|
deletes
|
|
635
638
|
})), '__diff.json');
|
|
636
639
|
zipfile.end();
|
|
@@ -661,6 +664,7 @@ async function diffFromPackage(origin, next, output, originBundleName, transform
|
|
|
661
664
|
throw new Error('Bundle file not found! Please use default bundle file name and path.');
|
|
662
665
|
}
|
|
663
666
|
const copies = {};
|
|
667
|
+
const copiesv2 = {};
|
|
664
668
|
const zipfile = new _yazl.ZipFile();
|
|
665
669
|
const writePromise = new Promise((resolve, reject)=>{
|
|
666
670
|
zipfile.outputStream.on('error', (err)=>{
|
|
@@ -697,6 +701,7 @@ async function diffFromPackage(origin, next, output, originBundleName, transform
|
|
|
697
701
|
// If moved from other place
|
|
698
702
|
if (originMap[entry.crc32]) {
|
|
699
703
|
copies[entry.fileName] = originMap[entry.crc32];
|
|
704
|
+
copiesv2[entry.crc32] = entry.fileName;
|
|
700
705
|
return;
|
|
701
706
|
}
|
|
702
707
|
return new Promise((resolve, reject)=>{
|
|
@@ -714,7 +719,8 @@ async function diffFromPackage(origin, next, output, originBundleName, transform
|
|
|
714
719
|
}
|
|
715
720
|
});
|
|
716
721
|
zipfile.addBuffer(Buffer.from(JSON.stringify({
|
|
717
|
-
copies
|
|
722
|
+
copies,
|
|
723
|
+
copiesv2
|
|
718
724
|
})), '__diff.json');
|
|
719
725
|
zipfile.end();
|
|
720
726
|
await writePromise;
|
package/lib/utils/constants.js
CHANGED
|
@@ -15,8 +15,8 @@ _export(exports, {
|
|
|
15
15
|
credentialFile: function() {
|
|
16
16
|
return credentialFile;
|
|
17
17
|
},
|
|
18
|
-
|
|
19
|
-
return
|
|
18
|
+
defaultEndpoints: function() {
|
|
19
|
+
return defaultEndpoints;
|
|
20
20
|
},
|
|
21
21
|
pricingPageUrl: function() {
|
|
22
22
|
return pricingPageUrl;
|
|
@@ -40,4 +40,10 @@ const credentialFile = IS_CRESC ? '.cresc.token' : '.update';
|
|
|
40
40
|
const updateJson = IS_CRESC ? 'cresc.config.json' : 'update.json';
|
|
41
41
|
const tempDir = IS_CRESC ? '.cresc.temp' : '.pushy';
|
|
42
42
|
const pricingPageUrl = IS_CRESC ? 'https://cresc.dev/pricing' : 'https://pushy.reactnative.cn/pricing.html';
|
|
43
|
-
const
|
|
43
|
+
const defaultEndpoints = IS_CRESC ? [
|
|
44
|
+
'https://api.cresc.dev',
|
|
45
|
+
'https://api.cresc.app'
|
|
46
|
+
] : [
|
|
47
|
+
'https://update.reactnative.cn/api',
|
|
48
|
+
'https://update.react-native.cn/api'
|
|
49
|
+
];
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
getBaseUrl: function() {
|
|
13
|
+
return getBaseUrl;
|
|
14
|
+
},
|
|
15
|
+
ping: function() {
|
|
16
|
+
return ping;
|
|
17
|
+
},
|
|
18
|
+
promiseAny: function() {
|
|
19
|
+
return promiseAny;
|
|
20
|
+
},
|
|
21
|
+
testUrls: function() {
|
|
22
|
+
return testUrls;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
const _constants = require("./constants");
|
|
26
|
+
function promiseAny(promises) {
|
|
27
|
+
return new Promise((resolve, reject)=>{
|
|
28
|
+
let count = 0;
|
|
29
|
+
for (const promise of promises){
|
|
30
|
+
Promise.resolve(promise).then(resolve).catch(()=>{
|
|
31
|
+
count++;
|
|
32
|
+
if (count === promises.length) {
|
|
33
|
+
reject(new Error('All promises were rejected'));
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
const ping = async (url)=>{
|
|
40
|
+
let pingFinished = false;
|
|
41
|
+
return Promise.race([
|
|
42
|
+
fetch(url, {
|
|
43
|
+
method: 'HEAD'
|
|
44
|
+
}).then(({ status, statusText })=>{
|
|
45
|
+
pingFinished = true;
|
|
46
|
+
if (status === 200) {
|
|
47
|
+
// console.log('ping success', url);
|
|
48
|
+
return url;
|
|
49
|
+
}
|
|
50
|
+
// console.log('ping failed', url, status, statusText);
|
|
51
|
+
throw new Error('ping failed');
|
|
52
|
+
}).catch((e)=>{
|
|
53
|
+
pingFinished = true;
|
|
54
|
+
// console.log('ping error', url, e);
|
|
55
|
+
throw new Error('ping error');
|
|
56
|
+
}),
|
|
57
|
+
new Promise((_, reject)=>setTimeout(()=>{
|
|
58
|
+
reject(new Error('ping timeout'));
|
|
59
|
+
if (!pingFinished) {
|
|
60
|
+
// console.log('ping timeout', url);
|
|
61
|
+
}
|
|
62
|
+
}, 2000))
|
|
63
|
+
]);
|
|
64
|
+
};
|
|
65
|
+
const testUrls = async (urls)=>{
|
|
66
|
+
if (!(urls == null ? void 0 : urls.length)) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
const ret = await promiseAny(urls.map(ping));
|
|
70
|
+
if (ret) {
|
|
71
|
+
return ret;
|
|
72
|
+
}
|
|
73
|
+
// console.log('all ping failed, use first url:', urls[0]);
|
|
74
|
+
return urls[0];
|
|
75
|
+
};
|
|
76
|
+
const getBaseUrl = (async ()=>{
|
|
77
|
+
const testEndpoint = process.env.PUSHY_REGISTRY || process.env.RNU_API;
|
|
78
|
+
if (testEndpoint) {
|
|
79
|
+
return testEndpoint;
|
|
80
|
+
}
|
|
81
|
+
return testUrls(_constants.defaultEndpoints.map((url)=>`${url}/status`)).then((ret)=>{
|
|
82
|
+
let baseUrl = _constants.defaultEndpoints[0];
|
|
83
|
+
if (ret) {
|
|
84
|
+
// remove /status
|
|
85
|
+
baseUrl = ret.replace('/status', '');
|
|
86
|
+
}
|
|
87
|
+
// console.log('baseUrl', baseUrl);
|
|
88
|
+
return baseUrl;
|
|
89
|
+
});
|
|
90
|
+
})();
|
package/lib/utils/index.js
CHANGED
|
@@ -40,7 +40,7 @@ const _chalk = /*#__PURE__*/ _interop_require_default(require("chalk"));
|
|
|
40
40
|
const _compareversions = require("compare-versions");
|
|
41
41
|
const _fsextra = /*#__PURE__*/ _interop_require_default(require("fs-extra"));
|
|
42
42
|
const _packagejson = /*#__PURE__*/ _interop_require_default(require("../../package.json"));
|
|
43
|
-
const _latestversion = /*#__PURE__*/ _interop_require_default(require("
|
|
43
|
+
const _latestversion = /*#__PURE__*/ _interop_require_default(require("./latest-version"));
|
|
44
44
|
const _appinfoparser = /*#__PURE__*/ _interop_require_default(require("./app-info-parser"));
|
|
45
45
|
const _checkplugin = require("./check-plugin");
|
|
46
46
|
const _read = require("read");
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -10,18 +10,16 @@ import packageJson from '../package.json';
|
|
|
10
10
|
import type { Package, Session } from './types';
|
|
11
11
|
import {
|
|
12
12
|
credentialFile,
|
|
13
|
-
defaultEndpoint,
|
|
14
13
|
pricingPageUrl,
|
|
15
14
|
} from './utils/constants';
|
|
16
15
|
import { t } from './utils/i18n';
|
|
16
|
+
import { getBaseUrl } from 'utils/http-helper';
|
|
17
17
|
|
|
18
18
|
const tcpPing = util.promisify(tcpp.ping);
|
|
19
19
|
|
|
20
20
|
let session: Session | undefined;
|
|
21
21
|
let savedSession: Session | undefined;
|
|
22
22
|
|
|
23
|
-
const host =
|
|
24
|
-
process.env.PUSHY_REGISTRY || process.env.RNU_API || defaultEndpoint;
|
|
25
23
|
|
|
26
24
|
const userAgent = `react-native-update-cli/${packageJson.version}`;
|
|
27
25
|
|
|
@@ -64,7 +62,9 @@ export const closeSession = () => {
|
|
|
64
62
|
};
|
|
65
63
|
|
|
66
64
|
async function query(url: string, options: fetch.RequestInit) {
|
|
67
|
-
const
|
|
65
|
+
const baseUrl = await getBaseUrl;
|
|
66
|
+
const fullUrl = `${baseUrl}${url}`;
|
|
67
|
+
const resp = await fetch(fullUrl, options);
|
|
68
68
|
const text = await resp.text();
|
|
69
69
|
let json: any;
|
|
70
70
|
try {
|
|
@@ -83,7 +83,7 @@ async function query(url: string, options: fetch.RequestInit) {
|
|
|
83
83
|
|
|
84
84
|
function queryWithoutBody(method: string) {
|
|
85
85
|
return (api: string) =>
|
|
86
|
-
query(
|
|
86
|
+
query(api, {
|
|
87
87
|
method,
|
|
88
88
|
headers: {
|
|
89
89
|
'User-Agent': userAgent,
|
|
@@ -94,7 +94,7 @@ function queryWithoutBody(method: string) {
|
|
|
94
94
|
|
|
95
95
|
function queryWithBody(method: string) {
|
|
96
96
|
return (api: string, body?: Record<string, any>) =>
|
|
97
|
-
query(
|
|
97
|
+
query(api, {
|
|
98
98
|
method,
|
|
99
99
|
headers: {
|
|
100
100
|
'User-Agent': userAgent,
|
|
@@ -116,6 +116,7 @@ export async function uploadFile(fn: string, key?: string) {
|
|
|
116
116
|
});
|
|
117
117
|
let realUrl = url;
|
|
118
118
|
if (backupUrl) {
|
|
119
|
+
// @ts-ignore
|
|
119
120
|
if (global.USE_ACC_OSS) {
|
|
120
121
|
realUrl = backupUrl;
|
|
121
122
|
} else {
|
package/src/bundle.ts
CHANGED
|
@@ -597,6 +597,7 @@ async function diffFromPPK(origin: string, next: string, output: string) {
|
|
|
597
597
|
}
|
|
598
598
|
|
|
599
599
|
const copies = {};
|
|
600
|
+
const copiesv2 = {};
|
|
600
601
|
|
|
601
602
|
const zipfile = new YazlZipFile();
|
|
602
603
|
|
|
@@ -668,6 +669,7 @@ async function diffFromPPK(origin: string, next: string, output: string) {
|
|
|
668
669
|
addEntry(base);
|
|
669
670
|
}
|
|
670
671
|
copies[entry.fileName] = originMap[entry.crc32];
|
|
672
|
+
copiesv2[entry.crc32] = entry.fileName;
|
|
671
673
|
return;
|
|
672
674
|
}
|
|
673
675
|
|
|
@@ -700,7 +702,7 @@ async function diffFromPPK(origin: string, next: string, output: string) {
|
|
|
700
702
|
|
|
701
703
|
//console.log({copies, deletes});
|
|
702
704
|
zipfile.addBuffer(
|
|
703
|
-
Buffer.from(JSON.stringify({ copies, deletes })),
|
|
705
|
+
Buffer.from(JSON.stringify({ copies, copiesv2, deletes })),
|
|
704
706
|
'__diff.json',
|
|
705
707
|
);
|
|
706
708
|
zipfile.end();
|
|
@@ -747,6 +749,7 @@ async function diffFromPackage(
|
|
|
747
749
|
}
|
|
748
750
|
|
|
749
751
|
const copies = {};
|
|
752
|
+
const copiesv2 = {};
|
|
750
753
|
|
|
751
754
|
const zipfile = new YazlZipFile();
|
|
752
755
|
|
|
@@ -792,6 +795,7 @@ async function diffFromPackage(
|
|
|
792
795
|
// If moved from other place
|
|
793
796
|
if (originMap[entry.crc32]) {
|
|
794
797
|
copies[entry.fileName] = originMap[entry.crc32];
|
|
798
|
+
copiesv2[entry.crc32] = entry.fileName;
|
|
795
799
|
return;
|
|
796
800
|
}
|
|
797
801
|
|
|
@@ -810,7 +814,7 @@ async function diffFromPackage(
|
|
|
810
814
|
}
|
|
811
815
|
});
|
|
812
816
|
|
|
813
|
-
zipfile.addBuffer(Buffer.from(JSON.stringify({ copies })), '__diff.json');
|
|
817
|
+
zipfile.addBuffer(Buffer.from(JSON.stringify({ copies, copiesv2 })), '__diff.json');
|
|
814
818
|
zipfile.end();
|
|
815
819
|
await writePromise;
|
|
816
820
|
}
|
package/src/utils/constants.ts
CHANGED
|
@@ -10,6 +10,6 @@ export const pricingPageUrl = IS_CRESC
|
|
|
10
10
|
? 'https://cresc.dev/pricing'
|
|
11
11
|
: 'https://pushy.reactnative.cn/pricing.html';
|
|
12
12
|
|
|
13
|
-
export const
|
|
14
|
-
? 'https://api.cresc.dev'
|
|
15
|
-
: 'https://update.reactnative.cn/api';
|
|
13
|
+
export const defaultEndpoints = IS_CRESC
|
|
14
|
+
? ['https://api.cresc.dev', 'https://api.cresc.app']
|
|
15
|
+
: ['https://update.reactnative.cn/api', 'https://update.react-native.cn/api'];
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { defaultEndpoints } from './constants';
|
|
2
|
+
|
|
3
|
+
// const baseUrl = `http://localhost:9000`;
|
|
4
|
+
// let baseUrl = SERVER.main[0];
|
|
5
|
+
// const baseUrl = `https://p.reactnative.cn/api`;
|
|
6
|
+
|
|
7
|
+
export function promiseAny<T>(promises: Promise<T>[]) {
|
|
8
|
+
return new Promise<T>((resolve, reject) => {
|
|
9
|
+
let count = 0;
|
|
10
|
+
|
|
11
|
+
for (const promise of promises) {
|
|
12
|
+
Promise.resolve(promise)
|
|
13
|
+
.then(resolve)
|
|
14
|
+
.catch(() => {
|
|
15
|
+
count++;
|
|
16
|
+
if (count === promises.length) {
|
|
17
|
+
reject(new Error('All promises were rejected'));
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const ping = async (url: string) => {
|
|
25
|
+
let pingFinished = false;
|
|
26
|
+
return Promise.race([
|
|
27
|
+
fetch(url, {
|
|
28
|
+
method: 'HEAD',
|
|
29
|
+
})
|
|
30
|
+
.then(({ status, statusText }) => {
|
|
31
|
+
pingFinished = true;
|
|
32
|
+
if (status === 200) {
|
|
33
|
+
// console.log('ping success', url);
|
|
34
|
+
return url;
|
|
35
|
+
}
|
|
36
|
+
// console.log('ping failed', url, status, statusText);
|
|
37
|
+
throw new Error('ping failed');
|
|
38
|
+
})
|
|
39
|
+
.catch((e) => {
|
|
40
|
+
pingFinished = true;
|
|
41
|
+
// console.log('ping error', url, e);
|
|
42
|
+
throw new Error('ping error');
|
|
43
|
+
}),
|
|
44
|
+
new Promise((_, reject) =>
|
|
45
|
+
setTimeout(() => {
|
|
46
|
+
reject(new Error('ping timeout'));
|
|
47
|
+
if (!pingFinished) {
|
|
48
|
+
// console.log('ping timeout', url);
|
|
49
|
+
}
|
|
50
|
+
}, 2000),
|
|
51
|
+
),
|
|
52
|
+
]) as Promise<string | null>;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const testUrls = async (urls?: string[]) => {
|
|
56
|
+
if (!urls?.length) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
const ret = await promiseAny(urls.map(ping));
|
|
60
|
+
if (ret) {
|
|
61
|
+
return ret;
|
|
62
|
+
}
|
|
63
|
+
// console.log('all ping failed, use first url:', urls[0]);
|
|
64
|
+
return urls[0];
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const getBaseUrl = (async () => {
|
|
68
|
+
const testEndpoint = process.env.PUSHY_REGISTRY || process.env.RNU_API;
|
|
69
|
+
if (testEndpoint) {
|
|
70
|
+
return testEndpoint;
|
|
71
|
+
}
|
|
72
|
+
return testUrls(defaultEndpoints.map((url) => `${url}/status`)).then(
|
|
73
|
+
(ret) => {
|
|
74
|
+
let baseUrl = defaultEndpoints[0];
|
|
75
|
+
if (ret) {
|
|
76
|
+
// remove /status
|
|
77
|
+
baseUrl = ret.replace('/status', '');
|
|
78
|
+
}
|
|
79
|
+
// console.log('baseUrl', baseUrl);
|
|
80
|
+
return baseUrl;
|
|
81
|
+
},
|
|
82
|
+
);
|
|
83
|
+
})();
|