mirror of
https://gitcode.com/github-mirrors/react-native-update-cli.git
synced 2025-09-16 01:41:37 +08:00

* add logic to support SENTRY_PROPERTIES parameter * remove update.json and meta.json files in ppk * udpapte * refactor modles * update * add package-module file * update * update readme file * modifu cli.json file * fix command issues * improve version workflow logic * udpate * update * update * update * udpate * udpate * add example * update readme file * udpate version * change logic to use pushy command uniformly
150 lines
4.0 KiB
TypeScript
150 lines
4.0 KiB
TypeScript
import type {
|
|
CLIModule,
|
|
CLIProvider,
|
|
CommandContext,
|
|
CommandResult,
|
|
} from '../../src/types';
|
|
|
|
/**
|
|
* 分析统计模块示例
|
|
* 演示一个简单的分析统计功能模块
|
|
*/
|
|
export const analyticsModule: CLIModule = {
|
|
name: 'analytics',
|
|
version: '1.0.0',
|
|
commands: [
|
|
{
|
|
name: 'track-deployment',
|
|
description: '记录部署统计信息',
|
|
handler: async (context: CommandContext): Promise<CommandResult> => {
|
|
console.log('📊 记录部署统计信息...');
|
|
|
|
const { platform, environment, version } = context.options;
|
|
|
|
const deploymentData = {
|
|
timestamp: new Date().toISOString(),
|
|
platform: platform || 'unknown',
|
|
environment: environment || 'unknown',
|
|
version: version || 'unknown',
|
|
success: true,
|
|
duration: Math.floor(Math.random() * 1000) + 500, // 模拟部署时长
|
|
};
|
|
|
|
console.log('✅ 部署统计已记录:');
|
|
console.log(JSON.stringify(deploymentData, null, 2));
|
|
|
|
return {
|
|
success: true,
|
|
data: deploymentData,
|
|
};
|
|
},
|
|
options: {
|
|
platform: {
|
|
hasValue: true,
|
|
description: '平台',
|
|
},
|
|
environment: {
|
|
hasValue: true,
|
|
description: '环境',
|
|
},
|
|
version: {
|
|
hasValue: true,
|
|
description: '版本',
|
|
},
|
|
},
|
|
},
|
|
|
|
{
|
|
name: 'deployment-report',
|
|
description: '生成部署报告',
|
|
handler: async (context: CommandContext): Promise<CommandResult> => {
|
|
console.log('📈 生成部署报告...');
|
|
|
|
const { days = 7 } = context.options;
|
|
|
|
// 模拟生成报告数据
|
|
const report = {
|
|
period: `最近 ${days} 天`,
|
|
totalDeployments: Math.floor(Math.random() * 50) + 10,
|
|
successRate: 95.5,
|
|
averageDuration: '2.3分钟',
|
|
platformBreakdown: {
|
|
ios: 45,
|
|
android: 38,
|
|
harmony: 12,
|
|
},
|
|
environmentBreakdown: {
|
|
development: 60,
|
|
staging: 25,
|
|
production: 15,
|
|
},
|
|
};
|
|
|
|
console.log('📊 部署报告:');
|
|
console.log(JSON.stringify(report, null, 2));
|
|
|
|
return {
|
|
success: true,
|
|
data: report,
|
|
};
|
|
},
|
|
options: {
|
|
days: {
|
|
hasValue: true,
|
|
default: 7,
|
|
description: '报告天数',
|
|
},
|
|
},
|
|
},
|
|
],
|
|
|
|
workflows: [
|
|
{
|
|
name: 'deploy-with-analytics',
|
|
description: '带统计的部署流程',
|
|
steps: [
|
|
{
|
|
name: 'pre-deployment',
|
|
description: '部署前准备',
|
|
execute: async (context: CommandContext) => {
|
|
console.log('📋 部署前准备...');
|
|
return { startTime: Date.now() };
|
|
},
|
|
},
|
|
{
|
|
name: 'deployment',
|
|
description: '执行部署',
|
|
execute: async (context: CommandContext, previousResult: any) => {
|
|
console.log('🚀 执行部署...');
|
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
return { ...previousResult, deploymentCompleted: true };
|
|
},
|
|
},
|
|
{
|
|
name: 'record-analytics',
|
|
description: '记录统计信息',
|
|
execute: async (context: CommandContext, previousResult: any) => {
|
|
console.log('📊 记录统计信息...');
|
|
const duration = Date.now() - previousResult.startTime;
|
|
const analytics = {
|
|
duration,
|
|
timestamp: new Date().toISOString(),
|
|
success: true,
|
|
};
|
|
console.log(`✅ 部署完成,耗时 ${duration}ms`);
|
|
return { ...previousResult, analytics };
|
|
},
|
|
},
|
|
],
|
|
},
|
|
],
|
|
|
|
init: (provider: CLIProvider) => {
|
|
console.log('📊 分析统计模块已初始化');
|
|
},
|
|
|
|
cleanup: () => {
|
|
console.log('🧹 分析统计模块清理完成');
|
|
},
|
|
};
|