react-native-update-cli 1.41.0-beta.0 → 1.41.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 CHANGED
@@ -50,7 +50,6 @@ const _tcpping = /*#__PURE__*/ _interop_require_default(require("tcp-ping"));
50
50
  const _filesizeparser = /*#__PURE__*/ _interop_require_default(require("filesize-parser"));
51
51
  const _constants = require("./utils/constants");
52
52
  const _formdata = /*#__PURE__*/ _interop_require_default(require("form-data"));
53
- const _constants1 = require("utils/constants");
54
53
  function _interop_require_default(obj) {
55
54
  return obj && obj.__esModule ? obj : {
56
55
  default: obj
@@ -59,20 +58,20 @@ function _interop_require_default(obj) {
59
58
  const tcpPing = _nodeutil.default.promisify(_tcpping.default.ping);
60
59
  let session;
61
60
  let savedSession;
62
- const defaultEndpoint = global.IS_CRESC ? 'https://api.cresc.dev' : 'https://update.reactnative.cn/api';
63
- let host = process.env.PUSHY_REGISTRY || defaultEndpoint;
61
+ const defaultEndpoint = _constants.IS_CRESC ? 'https://api.cresc.dev' : 'https://update.reactnative.cn/api';
62
+ const host = process.env.PUSHY_REGISTRY || process.env.RNU_API || defaultEndpoint;
64
63
  const userAgent = `react-native-update-cli/${_packagejson.default.version}`;
65
64
  const getSession = ()=>session;
66
65
  const replaceSession = (newSession)=>{
67
66
  session = newSession;
68
67
  };
69
68
  const loadSession = async ()=>{
70
- if (_nodefs.default.existsSync(_constants1.credentialFile)) {
69
+ if (_nodefs.default.existsSync(_constants.credentialFile)) {
71
70
  try {
72
- replaceSession(JSON.parse(_nodefs.default.readFileSync(_constants1.credentialFile, 'utf8')));
71
+ replaceSession(JSON.parse(_nodefs.default.readFileSync(_constants.credentialFile, 'utf8')));
73
72
  savedSession = session;
74
73
  } catch (e) {
75
- console.error(`Failed to parse file ${_constants1.credentialFile}. Try to remove it manually.`);
74
+ console.error(`Failed to parse file ${_constants.credentialFile}. Try to remove it manually.`);
76
75
  throw e;
77
76
  }
78
77
  }
@@ -82,17 +81,16 @@ const saveSession = ()=>{
82
81
  if (session !== savedSession) {
83
82
  const current = session;
84
83
  const data = JSON.stringify(current, null, 4);
85
- _nodefs.default.writeFileSync(_constants1.credentialFile, data, 'utf8');
84
+ _nodefs.default.writeFileSync(_constants.credentialFile, data, 'utf8');
86
85
  savedSession = current;
87
86
  }
88
87
  };
89
88
  const closeSession = ()=>{
90
- if (_nodefs.default.existsSync(_constants1.credentialFile)) {
91
- _nodefs.default.unlinkSync(_constants1.credentialFile);
89
+ if (_nodefs.default.existsSync(_constants.credentialFile)) {
90
+ _nodefs.default.unlinkSync(_constants.credentialFile);
92
91
  savedSession = undefined;
93
92
  }
94
93
  session = undefined;
95
- host = process.env.PUSHY_REGISTRY || defaultEndpoint;
96
94
  };
97
95
  async function query(url, options) {
98
96
  const resp = await (0, _nodefetch.default)(url, options);
package/lib/index.js CHANGED
@@ -7,19 +7,17 @@ const _api = require("./api");
7
7
  const _updatenotifier = /*#__PURE__*/ _interop_require_default(require("update-notifier"));
8
8
  const _utils = require("./utils");
9
9
  const _packagejson = /*#__PURE__*/ _interop_require_default(require("../package.json"));
10
- const _nodepath = /*#__PURE__*/ _interop_require_default(require("node:path"));
11
10
  const _i18next = /*#__PURE__*/ _interop_require_default(require("i18next"));
12
11
  const _en = /*#__PURE__*/ _interop_require_default(require("./locales/en"));
13
12
  const _zh = /*#__PURE__*/ _interop_require_default(require("./locales/zh"));
13
+ const _constants = require("./utils/constants");
14
14
  function _interop_require_default(obj) {
15
15
  return obj && obj.__esModule ? obj : {
16
16
  default: obj
17
17
  };
18
18
  }
19
- const scriptName = _nodepath.default.basename(process.argv[1]);
20
- global.IS_CRESC = scriptName === 'cresc';
21
19
  _i18next.default.init({
22
- lng: global.IS_CRESC ? 'en' : 'zh',
20
+ lng: _constants.IS_CRESC ? 'en' : 'zh',
23
21
  // debug: process.env.NODE_ENV !== 'production',
24
22
  resources: {
25
23
  en: _en.default,
@@ -54,7 +52,7 @@ async function run() {
54
52
  }
55
53
  const argv = require('cli-arguments').parse(require('../cli.json'));
56
54
  global.NO_INTERACTIVE = argv.options['no-interactive'];
57
- global.USE_ACC_OSS = argv.options['acc'];
55
+ global.USE_ACC_OSS = argv.options.acc;
58
56
  (0, _api.loadSession)().then(()=>commands[argv.command](argv)).catch((err)=>{
59
57
  if (err.status === 401) {
60
58
  console.log('尚未登录。\n请在项目目录中运行`pushy login`命令来登录');
@@ -9,6 +9,9 @@ function _export(target, all) {
9
9
  });
10
10
  }
11
11
  _export(exports, {
12
+ IS_CRESC: function() {
13
+ return IS_CRESC;
14
+ },
12
15
  credentialFile: function() {
13
16
  return credentialFile;
14
17
  },
@@ -22,7 +25,15 @@ _export(exports, {
22
25
  return updateJson;
23
26
  }
24
27
  });
25
- const credentialFile = global.IS_CRESC ? '.cresc.token' : '.update';
26
- const updateJson = global.IS_CRESC ? 'cresc.config.json' : 'update.json';
27
- const tempDir = global.IS_CRESC ? '.cresc.temp' : '.pushy';
28
- const pricingPageUrl = global.IS_CRESC ? 'https://cresc.dev/pricing' : 'https://pushy.reactnative.cn/pricing.html';
28
+ const _nodepath = /*#__PURE__*/ _interop_require_default(require("node:path"));
29
+ function _interop_require_default(obj) {
30
+ return obj && obj.__esModule ? obj : {
31
+ default: obj
32
+ };
33
+ }
34
+ const scriptName = _nodepath.default.basename(process.argv[1]);
35
+ const IS_CRESC = scriptName === 'cresc';
36
+ const credentialFile = IS_CRESC ? '.cresc.token' : '.update';
37
+ const updateJson = IS_CRESC ? 'cresc.config.json' : 'update.json';
38
+ const tempDir = IS_CRESC ? '.cresc.temp' : '.pushy';
39
+ const pricingPageUrl = IS_CRESC ? 'https://cresc.dev/pricing' : 'https://pushy.reactnative.cn/pricing.html';
@@ -80,13 +80,12 @@ function getRNVersion() {
80
80
  paths: [
81
81
  process.cwd()
82
82
  ]
83
- }))).version;
84
- // We only care about major and minor version.
85
- const match = /^(\d+)\.(\d+)\./.exec(version);
83
+ })).toString()).version;
84
+ const [, major, minor] = /^(\d+)\.(\d+)\./.exec(version) || [];
86
85
  return {
87
86
  version,
88
- major: match[1] | 0,
89
- minor: match[2] | 0
87
+ major: Number(major),
88
+ minor: Number(minor)
90
89
  };
91
90
  }
92
91
  async function getApkInfo(fn) {
@@ -183,14 +182,19 @@ function saveToLocal(originPath, destName) {
183
182
  // fs.ensureDirSync(path.dirname(destPath));
184
183
  // fs.copyFileSync(originPath, destPath);
185
184
  }
186
- async function getLatestVersion(pkgName) {
187
- return Promise.race([
188
- (0, _latestversion.default)(pkgName).then((p)=>p.latest).catch(()=>''),
189
- new Promise((resolve)=>setTimeout(()=>resolve(''), 2000))
190
- ]);
185
+ async function getLatestVersion(pkgNames) {
186
+ return (0, _latestversion.default)(pkgNames, {
187
+ useCache: true,
188
+ requestOptions: {
189
+ timeout: 2000
190
+ }
191
+ }).then((pkgs)=>pkgs.map((pkg)=>pkg.latest)).catch(()=>[]);
191
192
  }
192
193
  async function printVersionCommand() {
193
- let latestPushyCliVersion = await getLatestVersion('react-native-update-cli');
194
+ let [latestPushyCliVersion, latestPushyVersion] = await getLatestVersion([
195
+ 'react-native-update-cli',
196
+ 'react-native-update'
197
+ ]);
194
198
  latestPushyCliVersion = latestPushyCliVersion ? ` (最新:${_chalk.default.green(latestPushyCliVersion)})` : '';
195
199
  console.log(`react-native-update-cli: ${_packagejson.default.version}${latestPushyCliVersion}`);
196
200
  let pushyVersion = '';
@@ -201,7 +205,6 @@ async function printVersionCommand() {
201
205
  ]
202
206
  });
203
207
  pushyVersion = require(PACKAGE_JSON_PATH).version;
204
- let latestPushyVersion = await getLatestVersion('react-native-update');
205
208
  latestPushyVersion = latestPushyVersion ? ` (最新:${_chalk.default.green(latestPushyVersion)})` : '';
206
209
  console.log(`react-native-update: ${pushyVersion}${latestPushyVersion}`);
207
210
  } catch (e) {
package/lib/versions.js CHANGED
@@ -23,7 +23,7 @@ async function showVersion(appId, offset) {
23
23
  packageInfo += `...and ${count - 3} more`;
24
24
  }
25
25
  if (count === 0) {
26
- packageInfo = `(no package)`;
26
+ packageInfo = 'no package';
27
27
  } else {
28
28
  packageInfo = `[${packageInfo}]`;
29
29
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update-cli",
3
- "version": "1.41.0-beta.0",
3
+ "version": "1.41.0",
4
4
  "description": "Command tools for javaScript updater with `pushy` service for react native apps.",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -68,8 +68,16 @@
68
68
  "@biomejs/biome": "^1.9.4",
69
69
  "@swc/cli": "^0.5.1",
70
70
  "@swc/core": "^1.9.3",
71
+ "@types/filesize-parser": "^1.5.3",
72
+ "@types/fs-extra": "^11.0.4",
71
73
  "@types/node": "^22.9.3",
74
+ "@types/node-fetch": "^2.6.12",
75
+ "@types/progress": "^2.0.7",
76
+ "@types/semver": "^7.5.8",
77
+ "@types/tcp-ping": "^0.1.6",
78
+ "@types/update-notifier": "^6.0.8",
79
+ "@types/yauzl": "^2.10.3",
80
+ "@types/yazl": "^2.4.6",
72
81
  "typescript": "^5.7.2"
73
- },
74
- "packageManager": "yarn@1.22.21+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72"
82
+ }
75
83
  }
package/src/api.ts CHANGED
@@ -6,20 +6,21 @@ import ProgressBar from 'progress';
6
6
  import packageJson from '../package.json';
7
7
  import tcpp from 'tcp-ping';
8
8
  import filesizeParser from 'filesize-parser';
9
- import { pricingPageUrl } from './utils/constants';
9
+ import { pricingPageUrl, credentialFile, IS_CRESC } from './utils/constants';
10
10
  import type { Session } from 'types';
11
11
  import FormData from 'form-data';
12
- import { credentialFile } from 'utils/constants';
13
12
 
14
13
  const tcpPing = util.promisify(tcpp.ping);
15
14
 
16
15
  let session: Session | undefined;
17
16
  let savedSession: Session | undefined;
18
17
 
19
- const defaultEndpoint = global.IS_CRESC
18
+ const defaultEndpoint = IS_CRESC
20
19
  ? 'https://api.cresc.dev'
21
20
  : 'https://update.reactnative.cn/api';
22
- let host = process.env.PUSHY_REGISTRY || defaultEndpoint;
21
+
22
+ const host =
23
+ process.env.PUSHY_REGISTRY || process.env.RNU_API || defaultEndpoint;
23
24
 
24
25
  const userAgent = `react-native-update-cli/${packageJson.version}`;
25
26
 
@@ -29,8 +30,6 @@ export const replaceSession = (newSession: { token: string }) => {
29
30
  session = newSession;
30
31
  };
31
32
 
32
-
33
-
34
33
  export const loadSession = async () => {
35
34
  if (fs.existsSync(credentialFile)) {
36
35
  try {
@@ -61,7 +60,6 @@ export const closeSession = () => {
61
60
  savedSession = undefined;
62
61
  }
63
62
  session = undefined;
64
- host = process.env.PUSHY_REGISTRY || defaultEndpoint;
65
63
  };
66
64
 
67
65
  async function query(url: string, options: fetch.RequestInit) {
package/src/index.ts CHANGED
@@ -4,18 +4,13 @@ import { loadSession } from './api';
4
4
  import updateNotifier from 'update-notifier';
5
5
  import { printVersionCommand } from './utils';
6
6
  import pkg from '../package.json';
7
- import path from 'node:path';
8
7
  import i18next from 'i18next';
9
8
  import en from './locales/en';
10
9
  import zh from './locales/zh';
11
-
12
- const scriptName: 'cresc' | 'pushy' = path.basename(process.argv[1]) as
13
- | 'cresc'
14
- | 'pushy';
15
- global.IS_CRESC = scriptName === 'cresc';
10
+ import { IS_CRESC } from './utils/constants';
16
11
 
17
12
  i18next.init({
18
- lng: global.IS_CRESC ? 'en' : 'zh',
13
+ lng: IS_CRESC ? 'en' : 'zh',
19
14
  // debug: process.env.NODE_ENV !== 'production',
20
15
  resources: {
21
16
  en,
@@ -57,7 +52,7 @@ async function run() {
57
52
 
58
53
  const argv = require('cli-arguments').parse(require('../cli.json'));
59
54
  global.NO_INTERACTIVE = argv.options['no-interactive'];
60
- global.USE_ACC_OSS = argv.options['acc'];
55
+ global.USE_ACC_OSS = argv.options.acc;
61
56
 
62
57
  loadSession()
63
58
  .then(() => commands[argv.command](argv))
package/src/types.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  declare global {
2
2
  var NO_INTERACTIVE: boolean;
3
3
  var USE_ACC_OSS: boolean;
4
- var IS_CRESC: boolean;
5
4
  }
6
5
 
7
6
  export interface Session {
@@ -1,6 +1,13 @@
1
- export const credentialFile = global.IS_CRESC ? '.cresc.token' : '.update';
2
- export const updateJson = global.IS_CRESC ? 'cresc.config.json' : 'update.json';
3
- export const tempDir = global.IS_CRESC ? '.cresc.temp' : '.pushy';
4
- export const pricingPageUrl = global.IS_CRESC
1
+ import path from 'node:path';
2
+
3
+ const scriptName: 'cresc' | 'pushy' = path.basename(process.argv[1]) as
4
+ | 'cresc'
5
+ | 'pushy';
6
+ export const IS_CRESC = scriptName === 'cresc';
7
+
8
+ export const credentialFile = IS_CRESC ? '.cresc.token' : '.update';
9
+ export const updateJson = IS_CRESC ? 'cresc.config.json' : 'update.json';
10
+ export const tempDir = IS_CRESC ? '.cresc.temp' : '.pushy';
11
+ export const pricingPageUrl = IS_CRESC
5
12
  ? 'https://cresc.dev/pricing'
6
13
  : 'https://pushy.reactnative.cn/pricing.html';
@@ -11,7 +11,7 @@ import { checkPlugins } from './check-plugin';
11
11
  import { read } from 'read';
12
12
  import { tempDir } from './constants';
13
13
 
14
- export async function question(query: string, password: boolean) {
14
+ export async function question(query: string, password?: boolean) {
15
15
  if (NO_INTERACTIVE) {
16
16
  return '';
17
17
  }
@@ -23,7 +23,7 @@ export async function question(query: string, password: boolean) {
23
23
  }
24
24
 
25
25
  export function translateOptions(options: Record<string, string>) {
26
- const ret = {};
26
+ const ret: Record<string, string> = {};
27
27
  for (const key in options) {
28
28
  const v = options[key];
29
29
  if (typeof v === 'string') {
@@ -40,19 +40,21 @@ export function translateOptions(options: Record<string, string>) {
40
40
 
41
41
  export function getRNVersion() {
42
42
  const version = JSON.parse(
43
- fs.readFileSync(
44
- require.resolve('react-native/package.json', {
45
- paths: [process.cwd()],
46
- }),
47
- ),
43
+ fs
44
+ .readFileSync(
45
+ require.resolve('react-native/package.json', {
46
+ paths: [process.cwd()],
47
+ }),
48
+ )
49
+ .toString(),
48
50
  ).version;
49
51
 
50
- // We only care about major and minor version.
51
- const match = /^(\d+)\.(\d+)\./.exec(version);
52
+ const [, major, minor] = /^(\d+)\.(\d+)\./.exec(version) || [];
53
+
52
54
  return {
53
55
  version,
54
- major: match[1] | 0,
55
- minor: match[2] | 0,
56
+ major: Number(major),
57
+ minor: Number(minor),
56
58
  };
57
59
  }
58
60
 
@@ -173,17 +175,22 @@ export function saveToLocal(originPath: string, destName: string) {
173
175
  // fs.copyFileSync(originPath, destPath);
174
176
  }
175
177
 
176
- async function getLatestVersion(pkgName: string) {
177
- return Promise.race([
178
- latestVersion(pkgName)
179
- .then((p) => p.latest)
180
- .catch(() => ''),
181
- new Promise((resolve) => setTimeout(() => resolve(''), 2000)),
182
- ]);
178
+ async function getLatestVersion(pkgNames: string[]) {
179
+ return latestVersion(pkgNames, {
180
+ useCache: true,
181
+ requestOptions: {
182
+ timeout: 2000,
183
+ },
184
+ })
185
+ .then((pkgs) => pkgs.map((pkg) => pkg.latest))
186
+ .catch(() => []);
183
187
  }
184
188
 
185
189
  export async function printVersionCommand() {
186
- let latestPushyCliVersion = await getLatestVersion('react-native-update-cli');
190
+ let [latestPushyCliVersion, latestPushyVersion] = await getLatestVersion([
191
+ 'react-native-update-cli',
192
+ 'react-native-update',
193
+ ]);
187
194
  latestPushyCliVersion = latestPushyCliVersion
188
195
  ? ` (最新:${chalk.green(latestPushyCliVersion)})`
189
196
  : '';
@@ -199,7 +206,6 @@ export async function printVersionCommand() {
199
206
  },
200
207
  );
201
208
  pushyVersion = require(PACKAGE_JSON_PATH).version;
202
- let latestPushyVersion = await getLatestVersion('react-native-update');
203
209
  latestPushyVersion = latestPushyVersion
204
210
  ? ` (最新:${chalk.green(latestPushyVersion)})`
205
211
  : '';
@@ -226,6 +232,4 @@ export async function printVersionCommand() {
226
232
  }
227
233
  }
228
234
 
229
-
230
-
231
235
  export { checkPlugins };
@@ -5,7 +5,7 @@ import { checkPlatform, getSelectedApp } from './app';
5
5
  import { choosePackage } from './package';
6
6
  import { compare } from 'compare-versions';
7
7
 
8
- async function showVersion(appId, offset) {
8
+ async function showVersion(appId: string, offset: number) {
9
9
  const { data, count } = await get(`/app/${appId}/version/list`);
10
10
  console.log(`Offset ${offset}`);
11
11
  for (const version of data) {
@@ -18,7 +18,7 @@ async function showVersion(appId, offset) {
18
18
  packageInfo += `...and ${count - 3} more`;
19
19
  }
20
20
  if (count === 0) {
21
- packageInfo = `(no package)`;
21
+ packageInfo = 'no package';
22
22
  } else {
23
23
  packageInfo = `[${packageInfo}]`;
24
24
  }
package/src/.DS_Store DELETED
Binary file
Binary file