Skip to content

Commit 603e2ad

Browse files
committed
add install command
1 parent 317975c commit 603e2ad

File tree

7 files changed

+61
-38
lines changed

7 files changed

+61
-38
lines changed

cli.json

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -299,15 +299,6 @@
299299
}
300300
}
301301
},
302-
"hdiffFromPPK": {
303-
"description": "Create hdiff patch from a Prepare package(.ppk)",
304-
"options": {
305-
"output": {
306-
"default": "${tempDir}/output/hdiff-${time}.ppk-patch",
307-
"hasValue": true
308-
}
309-
}
310-
},
311302
"hdiffFromApp": {
312303
"description": "Create hdiff patch from a Harmony package(.app)",
313304
"options": {
@@ -343,6 +334,10 @@
343334
"hasValue": true
344335
}
345336
}
337+
},
338+
"install": {
339+
"description": "Install optional dependencies to the CLI",
340+
"options": {}
346341
}
347342
},
348343
"globalOptions": {

src/bundle.ts

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import os from 'os';
1616
const properties = require('properties');
1717
import { addGitIgnore } from './utils/add-gitignore';
1818
import { checkLockFiles } from './utils/check-lockfile';
19-
import { tempDir } from './utils/constants';
19+
import { scriptName, tempDir } from './utils/constants';
2020
import { depVersions } from './utils/dep-versions';
2121
import { t } from './utils/i18n';
2222
import { versionCommands } from './versions';
@@ -548,9 +548,7 @@ async function diffFromPPK(origin: string, next: string, output: string) {
548548
});
549549

550550
if (!originSource) {
551-
throw new Error(
552-
'Bundle file not found! Please use default bundle file name and path.',
553-
);
551+
throw new Error(t('bundleFileNotFound'));
554552
}
555553

556554
const copies = {};
@@ -700,9 +698,7 @@ async function diffFromPackage(
700698
});
701699

702700
if (!originSource) {
703-
throw new Error(
704-
'Bundle file not found! Please use default bundle file name and path.',
705-
);
701+
throw new Error(t('bundleFileNotFound'));
706702
}
707703

708704
const copies = {};
@@ -856,24 +852,21 @@ function diffArgsCheck(args: string[], options: any, diffFn: string) {
856852

857853
if (diffFn.startsWith('hdiff')) {
858854
if (!hdiff) {
859-
console.error(
860-
`This function needs "node-hdiffpatch".
861-
Please run "npm i node-hdiffpatch" to install`,
862-
);
855+
console.error(t('nodeHdiffpatchRequired', { scriptName }));
863856
process.exit(1);
864857
}
865858
diff = hdiff;
866859
} else {
867860
if (!bsdiff) {
868-
console.error(
869-
`This function needs "node-bsdiff".
870-
Please run "npm i node-bsdiff" to install`,
871-
);
861+
console.error(t('nodeBsdiffRequired', { scriptName }));
872862
process.exit(1);
873863
}
874864
diff = bsdiff;
875865
}
876-
const { output } = options;
866+
const { output } = translateOptions({
867+
...options,
868+
tempDir,
869+
});
877870

878871
return {
879872
origin,
@@ -1004,14 +997,14 @@ export const bundleCommands = {
1004997
const { origin, next, realOutput } = diffArgsCheck(args, options, 'diff');
1005998

1006999
await diffFromPPK(origin, next, realOutput);
1007-
console.log(`${realOutput} generated.`);
1000+
console.log(t('diffPackageGenerated', { output: realOutput }));
10081001
},
10091002

10101003
async hdiff({ args, options }) {
10111004
const { origin, next, realOutput } = diffArgsCheck(args, options, 'hdiff');
10121005

10131006
await diffFromPPK(origin, next, realOutput);
1014-
console.log(`${realOutput} generated.`);
1007+
console.log(t('diffPackageGenerated', { output: realOutput }));
10151008
},
10161009

10171010
async diffFromApk({ args, options }) {
@@ -1027,7 +1020,7 @@ export const bundleCommands = {
10271020
realOutput,
10281021
'assets/index.android.bundle',
10291022
);
1030-
console.log(`${realOutput} generated.`);
1023+
console.log(t('diffPackageGenerated', { output: realOutput }));
10311024
},
10321025

10331026
async hdiffFromApk({ args, options }) {
@@ -1043,7 +1036,7 @@ export const bundleCommands = {
10431036
realOutput,
10441037
'assets/index.android.bundle',
10451038
);
1046-
console.log(`${realOutput} generated.`);
1039+
console.log(t('diffPackageGenerated', { output: realOutput }));
10471040
},
10481041

10491042
async diffFromApp({ args, options }) {
@@ -1058,7 +1051,7 @@ export const bundleCommands = {
10581051
realOutput,
10591052
'resources/rawfile/bundle.harmony.js',
10601053
);
1061-
console.log(`${realOutput} generated.`);
1054+
console.log(t('diffPackageGenerated', { output: realOutput }));
10621055
},
10631056

10641057
async hdiffFromApp({ args, options }) {
@@ -1073,7 +1066,7 @@ export const bundleCommands = {
10731066
realOutput,
10741067
'resources/rawfile/bundle.harmony.js',
10751068
);
1076-
console.log(`${realOutput} generated.`);
1069+
console.log(t('diffPackageGenerated', { output: realOutput }));
10771070
},
10781071

10791072
async diffFromIpa({ args, options }) {
@@ -1088,7 +1081,7 @@ export const bundleCommands = {
10881081
return m?.[1];
10891082
});
10901083

1091-
console.log(`${realOutput} generated.`);
1084+
console.log(t('diffPackageGenerated', { output: realOutput }));
10921085
},
10931086

10941087
async hdiffFromIpa({ args, options }) {
@@ -1103,6 +1096,6 @@ export const bundleCommands = {
11031096
return m?.[1];
11041097
});
11051098

1106-
console.log(`${realOutput} generated.`);
1099+
console.log(t('diffPackageGenerated', { output: realOutput }));
11071100
},
11081101
};

src/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { loadSession } from './api';
44
import { appCommands } from './app';
55
import { bundleCommands } from './bundle';
6+
import { installCommands } from './install';
67
import { moduleManager } from './module-manager';
78
import { builtinModules } from './modules';
89
import { packageCommands } from './package';
@@ -26,15 +27,16 @@ function printUsage() {
2627
console.log('React Native Update CLI');
2728
console.log('');
2829
console.log('Traditional commands:');
29-
30+
3031
const legacyCommands = {
3132
...userCommands,
3233
...bundleCommands,
3334
...appCommands,
3435
...packageCommands,
3536
...versionCommands,
37+
...installCommands,
3638
};
37-
39+
3840
for (const [name, handler] of Object.entries(legacyCommands)) {
3941
console.log(` ${name}: Legacy command`);
4042
}
@@ -62,7 +64,7 @@ function printUsage() {
6264
console.log(' list: List all available commands and workflows');
6365
console.log(' workflow <name>: Execute a specific workflow');
6466
console.log(' help: Show this help message');
65-
67+
6668
console.log('');
6769
console.log(
6870
'Visit `https://github.com/reactnativecn/react-native-update` for document.',
@@ -76,6 +78,7 @@ const legacyCommands = {
7678
...appCommands,
7779
...packageCommands,
7880
...versionCommands,
81+
...installCommands,
7982
help: printUsage,
8083
};
8184

@@ -118,7 +121,7 @@ async function run() {
118121
process.exit(1);
119122
}
120123
console.log('Workflow completed successfully:', result.data);
121-
}
124+
}
122125
// Try legacy commands first for backward compatibility
123126
else if (legacyCommands[argv.command]) {
124127
await legacyCommands[argv.command](argv);

src/install.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { spawnSync } from 'child_process';
2+
import path from 'path';
3+
import type { CommandContext } from './types';
4+
5+
export const installCommands = {
6+
install: async ({ args }: CommandContext) => {
7+
if (args.length === 0) {
8+
return;
9+
}
10+
11+
const cliDir = path.resolve(__dirname, '..');
12+
13+
spawnSync('npm', ['install', ...args], {
14+
cwd: cliDir,
15+
stdio: 'inherit',
16+
shell: true,
17+
});
18+
},
19+
};

src/locales/en.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,11 @@ This can reduce the risk of inconsistent dependencies and supply chain attacks.
137137
deletePackageError:
138138
'Failed to delete native package {{packageId}}: {{error}}',
139139
usageDeletePackage: 'Usage: cresc deletePackage [packageId] --appId [appId]',
140+
bundleFileNotFound:
141+
'Bundle file not found! Please use default bundle file name and path.',
142+
diffPackageGenerated: '{{- output}} generated.',
143+
nodeBsdiffRequired:
144+
'This function needs "node-bsdiff". Please run "{{scriptName}} install node-bsdiff" to install',
145+
nodeHdiffpatchRequired:
146+
'This function needs "node-hdiffpatch". Please run "{{scriptName}} install node-hdiffpatch" to install',
140147
};

src/locales/zh.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,10 @@ export default {
129129
deletePackageError: '删除原生包 {{packageId}} 失败: {{error}}',
130130
usageDeletePackage:
131131
'使用方法: pushy deletePackage [packageId] --appId [appId]',
132+
bundleFileNotFound: '未找到 bundle 文件!请使用默认的 bundle 文件名和路径。',
133+
diffPackageGenerated: '{{- output}} 已生成。',
134+
nodeBsdiffRequired:
135+
'此功能需要 "node-bsdiff"。请运行 "{{scriptName}} install node-bsdiff" 来安装',
136+
nodeHdiffpatchRequired:
137+
'此功能需要 "node-hdiffpatch"。请运行 "{{scriptName}} install node-hdiffpatch" 来安装',
132138
};

src/utils/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'path';
22

3-
const scriptName = path.basename(process.argv[1]) as 'cresc' | 'pushy';
3+
export const scriptName = path.basename(process.argv[1]) as 'cresc' | 'pushy';
44
export const IS_CRESC = scriptName === 'cresc';
55

66
export const credentialFile = IS_CRESC ? '.cresc.token' : '.update';

0 commit comments

Comments
 (0)