1
0
mirror of https://gitcode.com/github-mirrors/react-native-update-cli.git synced 2025-10-28 05:23:09 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

add install command

This commit is contained in:
sunnylqm
2025-10-25 15:49:35 +08:00
parent 317975cdba
commit 603e2adf47
7 changed files with 61 additions and 38 deletions

View File

@@ -299,15 +299,6 @@
}
}
},
"hdiffFromPPK": {
"description": "Create hdiff patch from a Prepare package(.ppk)",
"options": {
"output": {
"default": "${tempDir}/output/hdiff-${time}.ppk-patch",
"hasValue": true
}
}
},
"hdiffFromApp": {
"description": "Create hdiff patch from a Harmony package(.app)",
"options": {
@@ -343,6 +334,10 @@
"hasValue": true
}
}
},
"install": {
"description": "Install optional dependencies to the CLI",
"options": {}
}
},
"globalOptions": {

View File

@@ -16,7 +16,7 @@ import os from 'os';
const properties = require('properties');
import { addGitIgnore } from './utils/add-gitignore';
import { checkLockFiles } from './utils/check-lockfile';
import { tempDir } from './utils/constants';
import { scriptName, tempDir } from './utils/constants';
import { depVersions } from './utils/dep-versions';
import { t } from './utils/i18n';
import { versionCommands } from './versions';
@@ -548,9 +548,7 @@ async function diffFromPPK(origin: string, next: string, output: string) {
});
if (!originSource) {
throw new Error(
'Bundle file not found! Please use default bundle file name and path.',
);
throw new Error(t('bundleFileNotFound'));
}
const copies = {};
@@ -700,9 +698,7 @@ async function diffFromPackage(
});
if (!originSource) {
throw new Error(
'Bundle file not found! Please use default bundle file name and path.',
);
throw new Error(t('bundleFileNotFound'));
}
const copies = {};
@@ -856,24 +852,21 @@ function diffArgsCheck(args: string[], options: any, diffFn: string) {
if (diffFn.startsWith('hdiff')) {
if (!hdiff) {
console.error(
`This function needs "node-hdiffpatch".
Please run "npm i node-hdiffpatch" to install`,
);
console.error(t('nodeHdiffpatchRequired', { scriptName }));
process.exit(1);
}
diff = hdiff;
} else {
if (!bsdiff) {
console.error(
`This function needs "node-bsdiff".
Please run "npm i node-bsdiff" to install`,
);
console.error(t('nodeBsdiffRequired', { scriptName }));
process.exit(1);
}
diff = bsdiff;
}
const { output } = options;
const { output } = translateOptions({
...options,
tempDir,
});
return {
origin,
@@ -1004,14 +997,14 @@ export const bundleCommands = {
const { origin, next, realOutput } = diffArgsCheck(args, options, 'diff');
await diffFromPPK(origin, next, realOutput);
console.log(`${realOutput} generated.`);
console.log(t('diffPackageGenerated', { output: realOutput }));
},
async hdiff({ args, options }) {
const { origin, next, realOutput } = diffArgsCheck(args, options, 'hdiff');
await diffFromPPK(origin, next, realOutput);
console.log(`${realOutput} generated.`);
console.log(t('diffPackageGenerated', { output: realOutput }));
},
async diffFromApk({ args, options }) {
@@ -1027,7 +1020,7 @@ export const bundleCommands = {
realOutput,
'assets/index.android.bundle',
);
console.log(`${realOutput} generated.`);
console.log(t('diffPackageGenerated', { output: realOutput }));
},
async hdiffFromApk({ args, options }) {
@@ -1043,7 +1036,7 @@ export const bundleCommands = {
realOutput,
'assets/index.android.bundle',
);
console.log(`${realOutput} generated.`);
console.log(t('diffPackageGenerated', { output: realOutput }));
},
async diffFromApp({ args, options }) {
@@ -1058,7 +1051,7 @@ export const bundleCommands = {
realOutput,
'resources/rawfile/bundle.harmony.js',
);
console.log(`${realOutput} generated.`);
console.log(t('diffPackageGenerated', { output: realOutput }));
},
async hdiffFromApp({ args, options }) {
@@ -1073,7 +1066,7 @@ export const bundleCommands = {
realOutput,
'resources/rawfile/bundle.harmony.js',
);
console.log(`${realOutput} generated.`);
console.log(t('diffPackageGenerated', { output: realOutput }));
},
async diffFromIpa({ args, options }) {
@@ -1088,7 +1081,7 @@ export const bundleCommands = {
return m?.[1];
});
console.log(`${realOutput} generated.`);
console.log(t('diffPackageGenerated', { output: realOutput }));
},
async hdiffFromIpa({ args, options }) {
@@ -1103,6 +1096,6 @@ export const bundleCommands = {
return m?.[1];
});
console.log(`${realOutput} generated.`);
console.log(t('diffPackageGenerated', { output: realOutput }));
},
};

View File

@@ -3,6 +3,7 @@
import { loadSession } from './api';
import { appCommands } from './app';
import { bundleCommands } from './bundle';
import { installCommands } from './install';
import { moduleManager } from './module-manager';
import { builtinModules } from './modules';
import { packageCommands } from './package';
@@ -26,15 +27,16 @@ function printUsage() {
console.log('React Native Update CLI');
console.log('');
console.log('Traditional commands:');
const legacyCommands = {
...userCommands,
...bundleCommands,
...appCommands,
...packageCommands,
...versionCommands,
...installCommands,
};
for (const [name, handler] of Object.entries(legacyCommands)) {
console.log(` ${name}: Legacy command`);
}
@@ -62,7 +64,7 @@ function printUsage() {
console.log(' list: List all available commands and workflows');
console.log(' workflow <name>: Execute a specific workflow');
console.log(' help: Show this help message');
console.log('');
console.log(
'Visit `https://github.com/reactnativecn/react-native-update` for document.',
@@ -76,6 +78,7 @@ const legacyCommands = {
...appCommands,
...packageCommands,
...versionCommands,
...installCommands,
help: printUsage,
};
@@ -118,7 +121,7 @@ async function run() {
process.exit(1);
}
console.log('Workflow completed successfully:', result.data);
}
}
// Try legacy commands first for backward compatibility
else if (legacyCommands[argv.command]) {
await legacyCommands[argv.command](argv);

19
src/install.ts Normal file
View File

@@ -0,0 +1,19 @@
import { spawnSync } from 'child_process';
import path from 'path';
import type { CommandContext } from './types';
export const installCommands = {
install: async ({ args }: CommandContext) => {
if (args.length === 0) {
return;
}
const cliDir = path.resolve(__dirname, '..');
spawnSync('npm', ['install', ...args], {
cwd: cliDir,
stdio: 'inherit',
shell: true,
});
},
};

View File

@@ -137,4 +137,11 @@ This can reduce the risk of inconsistent dependencies and supply chain attacks.
deletePackageError:
'Failed to delete native package {{packageId}}: {{error}}',
usageDeletePackage: 'Usage: cresc deletePackage [packageId] --appId [appId]',
bundleFileNotFound:
'Bundle file not found! Please use default bundle file name and path.',
diffPackageGenerated: '{{- output}} generated.',
nodeBsdiffRequired:
'This function needs "node-bsdiff". Please run "{{scriptName}} install node-bsdiff" to install',
nodeHdiffpatchRequired:
'This function needs "node-hdiffpatch". Please run "{{scriptName}} install node-hdiffpatch" to install',
};

View File

@@ -129,4 +129,10 @@ export default {
deletePackageError: '删除原生包 {{packageId}} 失败: {{error}}',
usageDeletePackage:
'使用方法: pushy deletePackage [packageId] --appId [appId]',
bundleFileNotFound: '未找到 bundle 文件!请使用默认的 bundle 文件名和路径。',
diffPackageGenerated: '{{- output}} 已生成。',
nodeBsdiffRequired:
'此功能需要 "node-bsdiff"。请运行 "{{scriptName}} install node-bsdiff" 来安装',
nodeHdiffpatchRequired:
'此功能需要 "node-hdiffpatch"。请运行 "{{scriptName}} install node-hdiffpatch" 来安装',
};

View File

@@ -1,6 +1,6 @@
import path from 'path';
const scriptName = path.basename(process.argv[1]) as 'cresc' | 'pushy';
export const scriptName = path.basename(process.argv[1]) as 'cresc' | 'pushy';
export const IS_CRESC = scriptName === 'cresc';
export const credentialFile = IS_CRESC ? '.cresc.token' : '.update';