Skip to content

Commit 626df04

Browse files
committed
change logic to use pushy command uniformly
1 parent 0439620 commit 626df04

File tree

10 files changed

+146
-778
lines changed

10 files changed

+146
-778
lines changed

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
# React Native Update CLI - Modular Version
1+
# React Native Update CLI
22

33
[中文文档](./README.zh-CN.md) | [Chinese Documentation](./README.zh-CN.md)
44

5-
This is a refactored React Native Update CLI that supports modular architecture and custom publishing workflows.
5+
A unified React Native Update CLI that supports both traditional commands and modular architecture with custom publishing workflows.
66

7-
## 🚀 New Features
7+
## 🚀 Features
88

9+
- **Unified CLI**: Single `pushy` command for all functionality
10+
- **Backward Compatibility**: All existing commands work as before
911
- **Modular Architecture**: Split CLI functionality into independent modules
1012
- **Custom Workflows**: Support for creating custom publishing workflows
1113
- **Extensibility**: Users can import and register custom modules
1214
- **Type Safety**: Complete TypeScript type support
13-
- **Backward Compatibility**: Maintains compatibility with existing CLI
1415

1516
## 📦 Installation
1617

@@ -23,17 +24,17 @@ npm install react-native-update-cli
2324
### Basic Usage
2425

2526
```bash
26-
# Use modular CLI
27-
npx pushy-modular help
27+
# Use unified CLI
28+
npx pushy help
2829

2930
# List all available commands and workflows
30-
npx pushy-modular list
31+
npx pushy list
3132

3233
# Execute built-in workflow
33-
npx pushy-modular workflow setup-app
34+
npx pushy workflow setup-app
3435

3536
# Execute custom workflow
36-
npx pushy-modular workflow custom-publish
37+
npx pushy workflow custom-publish
3738
```
3839

3940
### Programmatic Usage

README.zh-CN.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
# React Native Update CLI - 模块化版本
1+
# React Native Update CLI
22

3-
这是一个重构后的React Native Update CLI,支持模块化架构和自定义发布流程
3+
这是一个统一的React Native Update CLI,同时支持传统命令和模块化架构以及自定义发布流程
44

5-
## 🚀 新特性
5+
## 🚀 特性
66

7+
- **统一CLI**: 使用单个`pushy`命令提供所有功能
8+
- **向后兼容**: 所有现有命令都能正常工作
79
- **模块化架构**: 将CLI功能拆分为独立的模块
810
- **自定义工作流**: 支持创建自定义的发布流程
911
- **可扩展性**: 用户可以导入和注册自定义模块
1012
- **类型安全**: 完整的TypeScript类型支持
11-
- **向后兼容**: 保持与现有CLI的兼容性
1213

1314
## 📦 安装
1415

@@ -21,17 +22,17 @@ npm install react-native-update-cli
2122
### 基本使用
2223

2324
```bash
24-
# 使用模块化CLI
25-
npx pushy-modular help
25+
# 使用统一CLI
26+
npx pushy help
2627

2728
# 列出所有可用命令和工作流
28-
npx pushy-modular list
29+
npx pushy list
2930

3031
# 执行内置的工作流
31-
npx pushy-modular workflow setup-app
32+
npx pushy workflow setup-app
3233

3334
# 执行自定义工作流
34-
npx pushy-modular workflow custom-publish
35+
npx pushy workflow custom-publish
3536
```
3637

3738
### 编程方式使用

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
"main": "index.js",
66
"bin": {
77
"pushy": "lib/index.js",
8-
"cresc": "lib/index.js",
9-
"pushy-modular": "lib/modular-index.js"
8+
"cresc": "lib/index.js"
109
},
1110
"files": ["lib", "src", "cli.json"],
1211
"scripts": {

src/index.ts

Lines changed: 115 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,74 @@
33
import { loadSession } from './api';
44
import { appCommands } from './app';
55
import { bundleCommands } from './bundle';
6+
import { moduleManager } from './module-manager';
7+
import { builtinModules } from './modules';
68
import { packageCommands } from './package';
9+
import type { CommandContext } from './types';
710
import { userCommands } from './user';
811
import { printVersionCommand } from './utils';
912
import { t } from './utils/i18n';
1013
import { versionCommands } from './versions';
1114

15+
function registerBuiltinModules() {
16+
for (const module of builtinModules) {
17+
try {
18+
moduleManager.registerModule(module);
19+
} catch (error) {
20+
console.error(`Failed to register module ${module.name}:`, error);
21+
}
22+
}
23+
}
24+
1225
function printUsage() {
26+
console.log('React Native Update CLI');
27+
console.log('');
28+
console.log('Traditional commands:');
29+
30+
const legacyCommands = {
31+
...userCommands,
32+
...bundleCommands,
33+
...appCommands,
34+
...packageCommands,
35+
...versionCommands,
36+
};
37+
38+
for (const [name, handler] of Object.entries(legacyCommands)) {
39+
console.log(` ${name}: Legacy command`);
40+
}
41+
42+
console.log('');
43+
console.log('Modular commands:');
44+
const commands = moduleManager.getRegisteredCommands();
45+
for (const command of commands) {
46+
console.log(
47+
` ${command.name}: ${command.description || 'No description'}`,
48+
);
49+
}
50+
51+
console.log('');
52+
console.log('Available workflows:');
53+
const workflows = moduleManager.getRegisteredWorkflows();
54+
for (const workflow of workflows) {
55+
console.log(
56+
` ${workflow.name}: ${workflow.description || 'No description'}`,
57+
);
58+
}
59+
60+
console.log('');
61+
console.log('Special commands:');
62+
console.log(' list: List all available commands and workflows');
63+
console.log(' workflow <name>: Execute a specific workflow');
64+
console.log(' help: Show this help message');
65+
66+
console.log('');
1367
console.log(
1468
'Visit `https://github.com/reactnativecn/react-native-update` for document.',
1569
);
1670
process.exit(1);
1771
}
1872

19-
const commands = {
73+
const legacyCommands = {
2074
...userCommands,
2175
...bundleCommands,
2276
...appCommands,
@@ -31,20 +85,71 @@ async function run() {
3185
process.exit();
3286
}
3387

88+
// Register builtin modules for modular functionality
89+
registerBuiltinModules();
90+
3491
const argv = require('cli-arguments').parse(require('../cli.json'));
3592
global.NO_INTERACTIVE = argv.options['no-interactive'];
3693
global.USE_ACC_OSS = argv.options.acc;
3794

38-
loadSession()
39-
.then(() => commands[argv.command](argv))
40-
.catch((err) => {
41-
if (err.status === 401) {
42-
console.log(t('loginFirst'));
43-
return;
95+
const context: CommandContext = {
96+
args: argv.args || [],
97+
options: argv.options || {},
98+
};
99+
100+
try {
101+
await loadSession();
102+
context.session = require('./api').getSession();
103+
104+
// Handle special modular commands first
105+
if (argv.command === 'help') {
106+
printUsage();
107+
} else if (argv.command === 'list') {
108+
moduleManager.listAll();
109+
} else if (argv.command === 'workflow') {
110+
const workflowName = argv.args[0];
111+
if (!workflowName) {
112+
console.error('Workflow name is required');
113+
process.exit(1);
44114
}
45-
console.error(err.stack);
46-
process.exit(-1);
47-
});
115+
const result = await moduleManager.executeWorkflow(workflowName, context);
116+
if (!result.success) {
117+
console.error('Workflow execution failed:', result.error);
118+
process.exit(1);
119+
}
120+
console.log('Workflow completed successfully:', result.data);
121+
}
122+
// Try legacy commands first for backward compatibility
123+
else if (legacyCommands[argv.command]) {
124+
await legacyCommands[argv.command](argv);
125+
}
126+
// Fall back to modular commands
127+
else {
128+
const result = await moduleManager.executeCommand(argv.command, context);
129+
if (!result.success) {
130+
console.error('Command execution failed:', result.error);
131+
process.exit(1);
132+
}
133+
console.log('Command completed successfully:', result.data);
134+
}
135+
} catch (err: any) {
136+
if (err.status === 401) {
137+
console.log(t('loginFirst'));
138+
return;
139+
}
140+
console.error(err.stack);
141+
process.exit(-1);
142+
}
48143
}
49144

145+
export { moduleManager };
146+
export { CLIProviderImpl } from './provider';
147+
export type {
148+
CLIProvider,
149+
CLIModule,
150+
CommandDefinition,
151+
CustomWorkflow,
152+
WorkflowStep,
153+
} from './types';
154+
50155
run();

src/modular-index.ts

Lines changed: 0 additions & 114 deletions
This file was deleted.

0 commit comments

Comments
 (0)