Skip to content

Commit 573ab60

Browse files
committed
fix i18n
1 parent 4613da1 commit 573ab60

File tree

7 files changed

+272
-216
lines changed

7 files changed

+272
-216
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-update-cli",
3-
"version": "1.44.1",
3+
"version": "1.44.2",
44
"description": "command line tool for react-native-update (remote updates for react native)",
55
"main": "index.js",
66
"bin": {

src/bundle.ts

Lines changed: 46 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import path from 'node:path';
22
import { translateOptions } from './utils';
33
import * as fs from 'fs-extra';
4-
import { ZipFile } from 'yazl';
5-
import { open as openZipFile } from 'yauzl';
4+
import { ZipFile as YazlZipFile } from 'yazl';
5+
import {
6+
type Entry,
7+
open as openZipFile,
8+
type ZipFile as YauzlZipFile,
9+
} from 'yauzl';
610
import { question, checkPlugins } from './utils';
711
import { checkPlatform } from './app';
812
import { spawn, spawnSync } from 'node:child_process';
@@ -16,9 +20,11 @@ import { tempDir } from './utils/constants';
1620
import { checkLockFiles } from './utils/check-lockfile';
1721
import { addGitIgnore } from './utils/add-gitignore';
1822

19-
let bsdiff;
20-
let hdiff;
21-
let diff;
23+
type Diff = (oldSource?: Buffer, newSource?: Buffer) => Buffer;
24+
25+
let bsdiff: Diff;
26+
let hdiff: Diff;
27+
let diff: Diff;
2228
try {
2329
bsdiff = require('node-bsdiff').diff;
2430
} catch (e) {}
@@ -59,9 +65,7 @@ async function runReactNativeBundleCommand({
5965
if (platform === 'android') {
6066
gradleConfig = await checkGradleConfig();
6167
if (gradleConfig.crunchPngs !== false) {
62-
console.warn(
63-
'android 的 crunchPngs 选项似乎尚未禁用(如已禁用则请忽略此提示),这可能导致热更包体积异常增大,具体请参考 https://pushy.reactnative.cn/docs/getting-started.html#%E7%A6%81%E7%94%A8-android-%E7%9A%84-crunch-%E4%BC%98%E5%8C%96 \n',
64-
);
68+
console.warn(t('androidCrunchPngsWarning'));
6569
}
6670
}
6771

@@ -321,7 +325,7 @@ async function compileHermesByteCode(
321325
sourcemapOutput: string,
322326
shouldCleanSourcemap: boolean,
323327
) {
324-
console.log('Hermes enabled, now compiling to hermes bytecode:\n');
328+
console.log(t('hermesEnabledCompiling'));
325329
// >= rn 0.69
326330
const rnDir = path.dirname(
327331
require.resolve('react-native', {
@@ -351,7 +355,9 @@ async function compileHermesByteCode(
351355
);
352356
args.push('-output-source-map');
353357
}
354-
console.log(t('runningHermesc', { command: hermesCommand, args: args.join(' ') }));
358+
console.log(
359+
t('runningHermesc', { command: hermesCommand, args: args.join(' ') }),
360+
);
355361
spawnSync(hermesCommand, args, {
356362
stdio: 'ignore',
357363
});
@@ -387,7 +393,7 @@ async function copyDebugidForSentry(
387393
sourcemapOutput: string,
388394
) {
389395
if (sourcemapOutput) {
390-
let copyDebugidPath;
396+
let copyDebugidPath: string | undefined;
391397
try {
392398
copyDebugidPath = require.resolve(
393399
'@sentry/react-native/scripts/copy-debugid.js',
@@ -426,13 +432,13 @@ async function uploadSourcemapForSentry(
426432
version: string,
427433
) {
428434
if (sourcemapOutput) {
429-
let sentryCliPath;
435+
let sentryCliPath: string | undefined;
430436
try {
431437
sentryCliPath = require.resolve('@sentry/cli/bin/sentry-cli', {
432438
paths: [process.cwd()],
433439
});
434440
} catch (error) {
435-
console.error('无法找到 Sentry CLI 工具,请确保已正确安装 @sentry/cli');
441+
console.error(t('sentryCliNotFound'));
436442
return;
437443
}
438444

@@ -471,12 +477,12 @@ async function uploadSourcemapForSentry(
471477
}
472478

473479
const ignorePackingFileNames = ['.', '..', 'index.bundlejs.map'];
474-
const ignorePackingExtensions = ['DS_Store','txt.map'];
480+
const ignorePackingExtensions = ['DS_Store', 'txt.map'];
475481
async function pack(dir: string, output: string) {
476482
console.log(t('packing'));
477483
fs.ensureDirSync(path.dirname(output));
478484
await new Promise<void>((resolve, reject) => {
479-
const zipfile = new ZipFile();
485+
const zipfile = new YazlZipFile();
480486

481487
function addDirectory(root: string, rel: string) {
482488
if (rel) {
@@ -513,10 +519,13 @@ async function pack(dir: string, output: string) {
513519
console.log(t('fileGenerated', { file: output }));
514520
}
515521

516-
export function readEntire(entry: string, zipFile: ZipFile) {
522+
export function readEntry(
523+
entry: Entry,
524+
zipFile: YauzlZipFile,
525+
): Promise<Buffer> {
517526
const buffers: Buffer[] = [];
518527
return new Promise((resolve, reject) => {
519-
zipFile.openReadStream(entry, (err: any, stream: any) => {
528+
zipFile.openReadStream(entry, (err, stream) => {
520529
stream.pipe({
521530
write(chunk: Buffer) {
522531
buffers.push(chunk);
@@ -544,7 +553,7 @@ async function diffFromPPK(origin: string, next: string, output: string) {
544553
const originEntries = {};
545554
const originMap = {};
546555

547-
let originSource;
556+
let originSource: Buffer | undefined;
548557

549558
await enumZipEntries(origin, (entry, zipFile) => {
550559
originEntries[entry.fileName] = entry;
@@ -557,7 +566,7 @@ async function diffFromPPK(origin: string, next: string, output: string) {
557566
entry.fileName === 'bundle.harmony.js'
558567
) {
559568
// This is source.
560-
return readEntire(entry, zipFile).then((v) => (originSource = v));
569+
return readEntry(entry, zipFile).then((v) => (originSource = v));
561570
}
562571
}
563572
});
@@ -570,7 +579,7 @@ async function diffFromPPK(origin: string, next: string, output: string) {
570579

571580
const copies = {};
572581

573-
const zipfile = new ZipFile();
582+
const zipfile = new YazlZipFile();
574583

575584
const writePromise = new Promise((resolve, reject) => {
576585
zipfile.outputStream.on('error', (err) => {
@@ -607,7 +616,7 @@ async function diffFromPPK(origin: string, next: string, output: string) {
607616
}
608617
} else if (entry.fileName === 'index.bundlejs') {
609618
//console.log('Found bundle');
610-
return readEntire(entry, nextZipfile).then((newSource) => {
619+
return readEntry(entry, nextZipfile).then((newSource) => {
611620
//console.log('Begin diff');
612621
zipfile.addBuffer(
613622
diff(originSource, newSource),
@@ -617,7 +626,7 @@ async function diffFromPPK(origin: string, next: string, output: string) {
617626
});
618627
} else if (entry.fileName === 'bundle.harmony.js') {
619628
//console.log('Found bundle');
620-
return readEntire(entry, nextZipfile).then((newSource) => {
629+
return readEntry(entry, nextZipfile).then((newSource) => {
621630
//console.log('Begin diff');
622631
zipfile.addBuffer(
623632
diff(originSource, newSource),
@@ -691,9 +700,9 @@ async function diffFromPackage(
691700
const originEntries = {};
692701
const originMap = {};
693702

694-
let originSource;
703+
let originSource: Buffer | undefined;
695704

696-
await enumZipEntries(origin, (entry: any, zipFile: any) => {
705+
await enumZipEntries(origin, (entry, zipFile) => {
697706
if (!/\/$/.test(entry.fileName)) {
698707
const fn = transformPackagePath(entry.fileName);
699708
if (!fn) {
@@ -707,7 +716,7 @@ async function diffFromPackage(
707716

708717
if (fn === originBundleName) {
709718
// This is source.
710-
return readEntire(entry, zipFile).then((v) => (originSource = v));
719+
return readEntry(entry, zipFile).then((v) => (originSource = v));
711720
}
712721
}
713722
});
@@ -720,7 +729,7 @@ async function diffFromPackage(
720729

721730
const copies = {};
722731

723-
const zipfile = new ZipFile();
732+
const zipfile = new YazlZipFile();
724733

725734
const writePromise = new Promise((resolve, reject) => {
726735
zipfile.outputStream.on('error', (err) => {
@@ -737,7 +746,7 @@ async function diffFromPackage(
737746
zipfile.addEmptyDirectory(entry.fileName);
738747
} else if (entry.fileName === 'index.bundlejs') {
739748
//console.log('Found bundle');
740-
return readEntire(entry, nextZipfile).then((newSource) => {
749+
return readEntry(entry, nextZipfile).then((newSource) => {
741750
//console.log('Begin diff');
742751
zipfile.addBuffer(
743752
diff(originSource, newSource),
@@ -747,7 +756,7 @@ async function diffFromPackage(
747756
});
748757
} else if (entry.fileName === 'bundle.harmony.js') {
749758
//console.log('Found bundle');
750-
return readEntire(entry, nextZipfile).then((newSource) => {
759+
return readEntry(entry, nextZipfile).then((newSource) => {
751760
//console.log('Begin diff');
752761
zipfile.addBuffer(
753762
diff(originSource, newSource),
@@ -789,14 +798,18 @@ async function diffFromPackage(
789798

790799
export async function enumZipEntries(
791800
zipFn: string,
792-
callback: (entry: any, zipFile: any) => void,
801+
callback: (
802+
entry: Entry,
803+
zipFile: YauzlZipFile,
804+
nestedPath?: string,
805+
) => Promise<any>,
793806
nestedPath = '',
794807
) {
795808
return new Promise((resolve, reject) => {
796809
openZipFile(
797810
zipFn,
798811
{ lazyEntries: true },
799-
async (err: any, zipfile: ZipFile) => {
812+
async (err: any, zipfile: YauzlZipFile) => {
800813
if (err) {
801814
return reject(err);
802815
}
@@ -850,7 +863,7 @@ export async function enumZipEntries(
850863
});
851864
}
852865

853-
function diffArgsCheck(args, options, diffFn) {
866+
function diffArgsCheck(args: string[], options: any, diffFn: string) {
854867
const [origin, next] = args;
855868

856869
if (!origin || !next) {
@@ -889,7 +902,7 @@ function diffArgsCheck(args, options, diffFn) {
889902
export const commands = {
890903
bundle: async function ({ options }) {
891904
const platform = checkPlatform(
892-
options.platform || (await question('平台(ios/android/harmony):')),
905+
options.platform || (await question(t('platformPrompt'))),
893906
);
894907

895908
const {
@@ -943,7 +956,7 @@ export const commands = {
943956

944957
await pack(path.resolve(intermediaDir), realOutput);
945958

946-
const v = await question('是否现在上传此热更包?(Y/N)');
959+
const v = await question(t('uploadBundlePrompt'));
947960
if (v.toLowerCase() === 'y') {
948961
const versionName = await this.publish({
949962
args: [realOutput],

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ function printUsage() {
88
// const commandName = args[0];
99
// TODO: print usage of commandName, or print global usage.
1010

11-
console.log('Usage is under development now.');
1211
console.log(
1312
'Visit `https://github.com/reactnativecn/react-native-update` for document.',
1413
);

0 commit comments

Comments
 (0)