mirror of
https://gitcode.com/github-mirrors/react-native-update-cli.git
synced 2025-10-28 13:23:11 +08:00
add install command
This commit is contained in:
13
cli.json
13
cli.json
@@ -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": {
|
"hdiffFromApp": {
|
||||||
"description": "Create hdiff patch from a Harmony package(.app)",
|
"description": "Create hdiff patch from a Harmony package(.app)",
|
||||||
"options": {
|
"options": {
|
||||||
@@ -343,6 +334,10 @@
|
|||||||
"hasValue": true
|
"hasValue": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"install": {
|
||||||
|
"description": "Install optional dependencies to the CLI",
|
||||||
|
"options": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"globalOptions": {
|
"globalOptions": {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import os from 'os';
|
|||||||
const properties = require('properties');
|
const properties = require('properties');
|
||||||
import { addGitIgnore } from './utils/add-gitignore';
|
import { addGitIgnore } from './utils/add-gitignore';
|
||||||
import { checkLockFiles } from './utils/check-lockfile';
|
import { checkLockFiles } from './utils/check-lockfile';
|
||||||
import { tempDir } from './utils/constants';
|
import { scriptName, tempDir } from './utils/constants';
|
||||||
import { depVersions } from './utils/dep-versions';
|
import { depVersions } from './utils/dep-versions';
|
||||||
import { t } from './utils/i18n';
|
import { t } from './utils/i18n';
|
||||||
import { versionCommands } from './versions';
|
import { versionCommands } from './versions';
|
||||||
@@ -548,9 +548,7 @@ async function diffFromPPK(origin: string, next: string, output: string) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!originSource) {
|
if (!originSource) {
|
||||||
throw new Error(
|
throw new Error(t('bundleFileNotFound'));
|
||||||
'Bundle file not found! Please use default bundle file name and path.',
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const copies = {};
|
const copies = {};
|
||||||
@@ -700,9 +698,7 @@ async function diffFromPackage(
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!originSource) {
|
if (!originSource) {
|
||||||
throw new Error(
|
throw new Error(t('bundleFileNotFound'));
|
||||||
'Bundle file not found! Please use default bundle file name and path.',
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const copies = {};
|
const copies = {};
|
||||||
@@ -856,24 +852,21 @@ function diffArgsCheck(args: string[], options: any, diffFn: string) {
|
|||||||
|
|
||||||
if (diffFn.startsWith('hdiff')) {
|
if (diffFn.startsWith('hdiff')) {
|
||||||
if (!hdiff) {
|
if (!hdiff) {
|
||||||
console.error(
|
console.error(t('nodeHdiffpatchRequired', { scriptName }));
|
||||||
`This function needs "node-hdiffpatch".
|
|
||||||
Please run "npm i node-hdiffpatch" to install`,
|
|
||||||
);
|
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
diff = hdiff;
|
diff = hdiff;
|
||||||
} else {
|
} else {
|
||||||
if (!bsdiff) {
|
if (!bsdiff) {
|
||||||
console.error(
|
console.error(t('nodeBsdiffRequired', { scriptName }));
|
||||||
`This function needs "node-bsdiff".
|
|
||||||
Please run "npm i node-bsdiff" to install`,
|
|
||||||
);
|
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
diff = bsdiff;
|
diff = bsdiff;
|
||||||
}
|
}
|
||||||
const { output } = options;
|
const { output } = translateOptions({
|
||||||
|
...options,
|
||||||
|
tempDir,
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
origin,
|
origin,
|
||||||
@@ -1004,14 +997,14 @@ export const bundleCommands = {
|
|||||||
const { origin, next, realOutput } = diffArgsCheck(args, options, 'diff');
|
const { origin, next, realOutput } = diffArgsCheck(args, options, 'diff');
|
||||||
|
|
||||||
await diffFromPPK(origin, next, realOutput);
|
await diffFromPPK(origin, next, realOutput);
|
||||||
console.log(`${realOutput} generated.`);
|
console.log(t('diffPackageGenerated', { output: realOutput }));
|
||||||
},
|
},
|
||||||
|
|
||||||
async hdiff({ args, options }) {
|
async hdiff({ args, options }) {
|
||||||
const { origin, next, realOutput } = diffArgsCheck(args, options, 'hdiff');
|
const { origin, next, realOutput } = diffArgsCheck(args, options, 'hdiff');
|
||||||
|
|
||||||
await diffFromPPK(origin, next, realOutput);
|
await diffFromPPK(origin, next, realOutput);
|
||||||
console.log(`${realOutput} generated.`);
|
console.log(t('diffPackageGenerated', { output: realOutput }));
|
||||||
},
|
},
|
||||||
|
|
||||||
async diffFromApk({ args, options }) {
|
async diffFromApk({ args, options }) {
|
||||||
@@ -1027,7 +1020,7 @@ export const bundleCommands = {
|
|||||||
realOutput,
|
realOutput,
|
||||||
'assets/index.android.bundle',
|
'assets/index.android.bundle',
|
||||||
);
|
);
|
||||||
console.log(`${realOutput} generated.`);
|
console.log(t('diffPackageGenerated', { output: realOutput }));
|
||||||
},
|
},
|
||||||
|
|
||||||
async hdiffFromApk({ args, options }) {
|
async hdiffFromApk({ args, options }) {
|
||||||
@@ -1043,7 +1036,7 @@ export const bundleCommands = {
|
|||||||
realOutput,
|
realOutput,
|
||||||
'assets/index.android.bundle',
|
'assets/index.android.bundle',
|
||||||
);
|
);
|
||||||
console.log(`${realOutput} generated.`);
|
console.log(t('diffPackageGenerated', { output: realOutput }));
|
||||||
},
|
},
|
||||||
|
|
||||||
async diffFromApp({ args, options }) {
|
async diffFromApp({ args, options }) {
|
||||||
@@ -1058,7 +1051,7 @@ export const bundleCommands = {
|
|||||||
realOutput,
|
realOutput,
|
||||||
'resources/rawfile/bundle.harmony.js',
|
'resources/rawfile/bundle.harmony.js',
|
||||||
);
|
);
|
||||||
console.log(`${realOutput} generated.`);
|
console.log(t('diffPackageGenerated', { output: realOutput }));
|
||||||
},
|
},
|
||||||
|
|
||||||
async hdiffFromApp({ args, options }) {
|
async hdiffFromApp({ args, options }) {
|
||||||
@@ -1073,7 +1066,7 @@ export const bundleCommands = {
|
|||||||
realOutput,
|
realOutput,
|
||||||
'resources/rawfile/bundle.harmony.js',
|
'resources/rawfile/bundle.harmony.js',
|
||||||
);
|
);
|
||||||
console.log(`${realOutput} generated.`);
|
console.log(t('diffPackageGenerated', { output: realOutput }));
|
||||||
},
|
},
|
||||||
|
|
||||||
async diffFromIpa({ args, options }) {
|
async diffFromIpa({ args, options }) {
|
||||||
@@ -1088,7 +1081,7 @@ export const bundleCommands = {
|
|||||||
return m?.[1];
|
return m?.[1];
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`${realOutput} generated.`);
|
console.log(t('diffPackageGenerated', { output: realOutput }));
|
||||||
},
|
},
|
||||||
|
|
||||||
async hdiffFromIpa({ args, options }) {
|
async hdiffFromIpa({ args, options }) {
|
||||||
@@ -1103,6 +1096,6 @@ export const bundleCommands = {
|
|||||||
return m?.[1];
|
return m?.[1];
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`${realOutput} generated.`);
|
console.log(t('diffPackageGenerated', { output: realOutput }));
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
11
src/index.ts
11
src/index.ts
@@ -3,6 +3,7 @@
|
|||||||
import { loadSession } from './api';
|
import { loadSession } from './api';
|
||||||
import { appCommands } from './app';
|
import { appCommands } from './app';
|
||||||
import { bundleCommands } from './bundle';
|
import { bundleCommands } from './bundle';
|
||||||
|
import { installCommands } from './install';
|
||||||
import { moduleManager } from './module-manager';
|
import { moduleManager } from './module-manager';
|
||||||
import { builtinModules } from './modules';
|
import { builtinModules } from './modules';
|
||||||
import { packageCommands } from './package';
|
import { packageCommands } from './package';
|
||||||
@@ -26,15 +27,16 @@ function printUsage() {
|
|||||||
console.log('React Native Update CLI');
|
console.log('React Native Update CLI');
|
||||||
console.log('');
|
console.log('');
|
||||||
console.log('Traditional commands:');
|
console.log('Traditional commands:');
|
||||||
|
|
||||||
const legacyCommands = {
|
const legacyCommands = {
|
||||||
...userCommands,
|
...userCommands,
|
||||||
...bundleCommands,
|
...bundleCommands,
|
||||||
...appCommands,
|
...appCommands,
|
||||||
...packageCommands,
|
...packageCommands,
|
||||||
...versionCommands,
|
...versionCommands,
|
||||||
|
...installCommands,
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const [name, handler] of Object.entries(legacyCommands)) {
|
for (const [name, handler] of Object.entries(legacyCommands)) {
|
||||||
console.log(` ${name}: Legacy command`);
|
console.log(` ${name}: Legacy command`);
|
||||||
}
|
}
|
||||||
@@ -62,7 +64,7 @@ function printUsage() {
|
|||||||
console.log(' list: List all available commands and workflows');
|
console.log(' list: List all available commands and workflows');
|
||||||
console.log(' workflow <name>: Execute a specific workflow');
|
console.log(' workflow <name>: Execute a specific workflow');
|
||||||
console.log(' help: Show this help message');
|
console.log(' help: Show this help message');
|
||||||
|
|
||||||
console.log('');
|
console.log('');
|
||||||
console.log(
|
console.log(
|
||||||
'Visit `https://github.com/reactnativecn/react-native-update` for document.',
|
'Visit `https://github.com/reactnativecn/react-native-update` for document.',
|
||||||
@@ -76,6 +78,7 @@ const legacyCommands = {
|
|||||||
...appCommands,
|
...appCommands,
|
||||||
...packageCommands,
|
...packageCommands,
|
||||||
...versionCommands,
|
...versionCommands,
|
||||||
|
...installCommands,
|
||||||
help: printUsage,
|
help: printUsage,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -118,7 +121,7 @@ async function run() {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
console.log('Workflow completed successfully:', result.data);
|
console.log('Workflow completed successfully:', result.data);
|
||||||
}
|
}
|
||||||
// Try legacy commands first for backward compatibility
|
// Try legacy commands first for backward compatibility
|
||||||
else if (legacyCommands[argv.command]) {
|
else if (legacyCommands[argv.command]) {
|
||||||
await legacyCommands[argv.command](argv);
|
await legacyCommands[argv.command](argv);
|
||||||
|
|||||||
19
src/install.ts
Normal file
19
src/install.ts
Normal 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,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -137,4 +137,11 @@ This can reduce the risk of inconsistent dependencies and supply chain attacks.
|
|||||||
deletePackageError:
|
deletePackageError:
|
||||||
'Failed to delete native package {{packageId}}: {{error}}',
|
'Failed to delete native package {{packageId}}: {{error}}',
|
||||||
usageDeletePackage: 'Usage: cresc deletePackage [packageId] --appId [appId]',
|
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',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -129,4 +129,10 @@ export default {
|
|||||||
deletePackageError: '删除原生包 {{packageId}} 失败: {{error}}',
|
deletePackageError: '删除原生包 {{packageId}} 失败: {{error}}',
|
||||||
usageDeletePackage:
|
usageDeletePackage:
|
||||||
'使用方法: pushy deletePackage [packageId] --appId [appId]',
|
'使用方法: pushy deletePackage [packageId] --appId [appId]',
|
||||||
|
bundleFileNotFound: '未找到 bundle 文件!请使用默认的 bundle 文件名和路径。',
|
||||||
|
diffPackageGenerated: '{{- output}} 已生成。',
|
||||||
|
nodeBsdiffRequired:
|
||||||
|
'此功能需要 "node-bsdiff"。请运行 "{{scriptName}} install node-bsdiff" 来安装',
|
||||||
|
nodeHdiffpatchRequired:
|
||||||
|
'此功能需要 "node-hdiffpatch"。请运行 "{{scriptName}} install node-hdiffpatch" 来安装',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import path from 'path';
|
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 IS_CRESC = scriptName === 'cresc';
|
||||||
|
|
||||||
export const credentialFile = IS_CRESC ? '.cresc.token' : '.update';
|
export const credentialFile = IS_CRESC ? '.cresc.token' : '.update';
|
||||||
|
|||||||
Reference in New Issue
Block a user