Skip to content

Commit cdeaf8a

Browse files
committed
update
1 parent 33a6073 commit cdeaf8a

11 files changed

Lines changed: 14 additions & 75 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ npx pushy-modular help
2727
# 列出所有可用命令和工作流
2828
npx pushy-modular list
2929

30+
# 执行内置的工作流
31+
npx pushy-modular workflow setup-app
32+
3033
# 执行自定义工作流
3134
npx pushy-modular workflow production-release --environment=production --confirm
3235
```

src/exports.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
// 导出模块化CLI的核心功能
21
export { moduleManager } from './module-manager';
32
export { CLIProviderImpl } from './provider';
43

5-
// 导出类型定义
64
export type {
75
CLIProvider,
86
CLIModule,
@@ -20,15 +18,13 @@ export type {
2018
Package
2119
} from './types';
2220

23-
// 导出内置模块
2421
export { builtinModules } from './modules';
2522
export { bundleModule } from './modules/bundle-module';
2623
export { versionModule } from './modules/version-module';
2724
export { appModule } from './modules/app-module';
2825
export { userModule } from './modules/user-module';
2926
export { packageModule } from './modules/package-module';
3027

31-
// 导出工具函数
3228
export { loadSession, getSession } from './api';
3329
export { getPlatform, getSelectedApp } from './app';
3430
export { question, saveToLocal } from './utils';

src/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ import { appCommands } from './app';
1010
import { packageCommands } from './package';
1111

1212
function printUsage() {
13-
// const commandName = args[0];
14-
// TODO: print usage of commandName, or print global usage.
15-
1613
console.log(
1714
'Visit `https://github.com/reactnativecn/react-native-update` for document.',
1815
);

src/modular-index.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,15 @@ function printUsage() {
4242
async function run() {
4343
await printVersionCommand();
4444

45-
// 检查版本参数
4645
if (process.argv.indexOf('-v') >= 0 || process.argv[2] === 'version') {
4746
process.exit();
4847
}
49-
50-
// 注册内置模块
5148
registerBuiltinModules();
5249

53-
// 解析命令行参数
5450
const argv = require('cli-arguments').parse(require('../cli.json'));
5551
global.NO_INTERACTIVE = argv.options['no-interactive'];
5652
global.USE_ACC_OSS = argv.options.acc;
5753

58-
// 创建命令上下文
5954
const context: CommandContext = {
6055
args: argv.args || [],
6156
options: argv.options || {},

src/module-manager.ts

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,62 +11,50 @@ export class ModuleManager {
1111
this.provider = new CLIProviderImpl();
1212
}
1313

14-
/**
15-
* 注册一个CLI模块
16-
*/
1714
registerModule(module: CLIModule): void {
1815
if (this.modules.has(module.name)) {
1916
throw new Error(`Module '${module.name}' is already registered`);
2017
}
2118

2219
this.modules.set(module.name, module);
2320

24-
// 注册模块的命令
2521
if (module.commands) {
2622
for (const command of module.commands) {
2723
this.registerCommand(command);
2824
}
2925
}
3026

31-
// 注册模块的工作流
3227
if (module.workflows) {
3328
for (const workflow of module.workflows) {
3429
this.registerWorkflow(workflow);
3530
}
3631
}
3732

38-
// 初始化模块
3933
if (module.init) {
4034
module.init(this.provider);
4135
}
4236

4337
console.log(`Module '${module.name}' (v${module.version}) registered successfully`);
4438
}
4539

46-
/**
47-
* 注销一个CLI模块
48-
*/
4940
unregisterModule(moduleName: string): void {
5041
const module = this.modules.get(moduleName);
5142
if (!module) {
5243
throw new Error(`Module '${moduleName}' is not registered`);
5344
}
5445

55-
// 清理模块的命令
5646
if (module.commands) {
5747
for (const command of module.commands) {
5848
this.commands.delete(command.name);
5949
}
6050
}
6151

62-
// 清理模块的工作流
6352
if (module.workflows) {
6453
for (const workflow of module.workflows) {
6554
this.workflows.delete(workflow.name);
6655
}
6756
}
6857

69-
// 清理模块
7058
if (module.cleanup) {
7159
module.cleanup();
7260
}
@@ -75,19 +63,15 @@ export class ModuleManager {
7563
console.log(`Module '${moduleName}' unregistered successfully`);
7664
}
7765

78-
/**
79-
* 注册单个命令
80-
*/
66+
8167
registerCommand(command: CommandDefinition): void {
8268
if (this.commands.has(command.name)) {
8369
throw new Error(`Command '${command.name}' is already registered`);
8470
}
8571
this.commands.set(command.name, command);
8672
}
8773

88-
/**
89-
* 注册单个工作流
90-
*/
74+
9175
registerWorkflow(workflow: CustomWorkflow): void {
9276
if (this.workflows.has(workflow.name)) {
9377
throw new Error(`Workflow '${workflow.name}' is already registered`);
@@ -96,30 +80,22 @@ export class ModuleManager {
9680
this.provider.registerWorkflow(workflow);
9781
}
9882

99-
/**
100-
* 获取所有注册的命令
101-
*/
83+
10284
getRegisteredCommands(): CommandDefinition[] {
10385
return Array.from(this.commands.values());
10486
}
10587

106-
/**
107-
* 获取所有注册的工作流
108-
*/
88+
10989
getRegisteredWorkflows(): CustomWorkflow[] {
11090
return Array.from(this.workflows.values());
11191
}
11292

113-
/**
114-
* 获取所有注册的模块
115-
*/
93+
11694
getRegisteredModules(): CLIModule[] {
11795
return Array.from(this.modules.values());
11896
}
11997

120-
/**
121-
* 执行命令
122-
*/
98+
12399
async executeCommand(commandName: string, context: any): Promise<any> {
124100
const command = this.commands.get(commandName);
125101
if (!command) {
@@ -129,23 +105,17 @@ export class ModuleManager {
129105
return await command.handler(context);
130106
}
131107

132-
/**
133-
* 执行工作流
134-
*/
108+
135109
async executeWorkflow(workflowName: string, context: any): Promise<any> {
136110
return await this.provider.executeWorkflow(workflowName, context);
137111
}
138112

139-
/**
140-
* 获取CLI提供者实例
141-
*/
113+
142114
getProvider(): CLIProvider {
143115
return this.provider;
144116
}
145117

146-
/**
147-
* 列出所有可用的命令和工作流
148-
*/
118+
149119
listAll(): void {
150120
console.log('\n=== Registered Commands ===');
151121
for (const command of this.commands.values()) {
@@ -164,5 +134,4 @@ export class ModuleManager {
164134
}
165135
}
166136

167-
// 创建全局模块管理器实例
168137
export const moduleManager = new ModuleManager();

src/modules/app-module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CLIModule, CommandDefinition, CustomWorkflow, CommandContext, CommandResult } from '../types';
1+
import type { CLIModule, CommandContext, CommandResult } from '../types';
22
import { appCommands } from '../app';
33

44
export const appModule: CLIModule = {

src/modules/bundle-module.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { CLIModule, CommandContext, CommandResult } from '../types';
22
import { bundleCommands } from '../bundle';
3-
import { versionCommands } from '../versions';
43

54
export const bundleModule: CLIModule = {
65
name: 'bundle',
@@ -12,7 +11,6 @@ export const bundleModule: CLIModule = {
1211
description: 'Bundle javascript code and optionally publish',
1312
handler: async (context: CommandContext): Promise<CommandResult> => {
1413
try {
15-
console.log('😁bundle', context);
1614
await bundleCommands.bundle(context);
1715
return {
1816
success: true,

src/modules/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export { appModule } from './app-module';
1010
export { userModule } from './user-module';
1111
export { packageModule } from './package-module';
1212

13-
// 导出所有内置模块的数组,方便批量注册
1413
export const builtinModules = [
1514
bundleModule,
1615
versionModule,

src/modules/package-module.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { CLIModule, CommandContext, CommandResult } from '../types';
22
import { packageCommands } from '../package';
3-
import { versionCommands } from '../versions';
43

54
export const packageModule: CLIModule = {
65
name: 'package',

src/provider.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { loadSession, getSession } from './api';
22
import { getPlatform, getSelectedApp } from './app';
3-
import { question, saveToLocal } from './utils';
4-
import { t } from './utils/i18n';
53
import type {
64
CLIProvider,
75
CommandContext,
@@ -32,7 +30,6 @@ export class CLIProviderImpl implements CLIProvider {
3230
}
3331
}
3432

35-
// 核心功能实现
3633
async bundle(options: BundleOptions): Promise<CommandResult> {
3734
try {
3835
const context: CommandContext = {
@@ -51,7 +48,6 @@ export class CLIProviderImpl implements CLIProvider {
5148
}
5249
};
5350

54-
// 调用实际的bundle命令
5551
const { bundleCommands } = await import('./bundle');
5652
await bundleCommands.bundle(context);
5753

@@ -69,7 +65,6 @@ export class CLIProviderImpl implements CLIProvider {
6965

7066
async publish(options: PublishOptions): Promise<CommandResult> {
7167
try {
72-
// 将PublishOptions转换为CommandContext格式
7368
const context: CommandContext = {
7469
args: [],
7570
options: {
@@ -86,7 +81,6 @@ export class CLIProviderImpl implements CLIProvider {
8681
}
8782
};
8883

89-
// 调用实际的publish命令
9084
const { versionCommands } = await import('./versions');
9185
await versionCommands.publish(context);
9286

@@ -107,7 +101,6 @@ export class CLIProviderImpl implements CLIProvider {
107101
const platform = await this.getPlatform(options.platform);
108102
const { appId } = await this.getSelectedApp(platform);
109103

110-
// 根据文件类型选择上传命令
111104
const filePath = options.filePath;
112105
const fileType = filePath.split('.').pop()?.toLowerCase();
113106

@@ -144,7 +137,6 @@ export class CLIProviderImpl implements CLIProvider {
144137
}
145138
}
146139

147-
// 应用管理
148140
async getSelectedApp(platform?: Platform): Promise<{ appId: string; platform: Platform }> {
149141
const resolvedPlatform = await this.getPlatform(platform);
150142
return getSelectedApp(resolvedPlatform);
@@ -191,7 +183,7 @@ export class CLIProviderImpl implements CLIProvider {
191183
}
192184
}
193185

194-
// 版本管理(核心)
186+
195187
async listVersions(appId: string): Promise<CommandResult> {
196188
try {
197189
const context: CommandContext = {
@@ -239,7 +231,6 @@ export class CLIProviderImpl implements CLIProvider {
239231
}
240232
}
241233

242-
// 工具函数(核心)
243234
async getPlatform(platform?: Platform): Promise<Platform> {
244235
return getPlatform(platform);
245236
}
@@ -254,8 +245,6 @@ export class CLIProviderImpl implements CLIProvider {
254245
}
255246

256247

257-
258-
// 工作流管理
259248
registerWorkflow(workflow: CustomWorkflow): void {
260249
this.workflows.set(workflow.name, workflow);
261250
}

0 commit comments

Comments
 (0)