54e22423df
## Before <img width="1074" height="562" alt="image" src="https://github.com/user-attachments/assets/a2fbe902-d34e-40e4-87c9-f344a06fd6ae" /> ## After <img width="1107" height="605" alt="image" src="https://github.com/user-attachments/assets/af78276a-f4c7-42f9-9347-01d562b1a779" />
62 lines
1.5 KiB
TypeScript
62 lines
1.5 KiB
TypeScript
import fs from 'fs';
|
|
|
|
import { ApiService } from '@/cli/utilities/api/api-service';
|
|
import { ConfigService } from '@/cli/utilities/config/config-service';
|
|
import { runSafe } from '@/cli/utilities/run-safe';
|
|
import { APP_ERROR_CODES, type CommandResult } from '@/cli/types';
|
|
|
|
export type AppDeployOptions = {
|
|
tarballPath: string;
|
|
remote?: string;
|
|
serverUrl?: string;
|
|
token?: string;
|
|
onProgress?: (message: string) => void;
|
|
};
|
|
|
|
export type AppDeployResult = {
|
|
id: string;
|
|
name: string;
|
|
universalIdentifier: string;
|
|
};
|
|
|
|
const innerAppDeploy = async (
|
|
options: AppDeployOptions,
|
|
): Promise<CommandResult<AppDeployResult>> => {
|
|
const { tarballPath, onProgress } = options;
|
|
|
|
if (options.remote) {
|
|
ConfigService.setActiveRemote(options.remote);
|
|
}
|
|
|
|
onProgress?.(`Uploading ${tarballPath}...`);
|
|
|
|
const tarballBuffer = fs.readFileSync(tarballPath);
|
|
|
|
const apiService = new ApiService({
|
|
serverUrl: options.serverUrl,
|
|
token: options.token,
|
|
});
|
|
|
|
const uploadResult = await apiService.uploadAppTarball({ tarballBuffer });
|
|
|
|
if (!uploadResult.success) {
|
|
return {
|
|
success: false,
|
|
error: {
|
|
code: APP_ERROR_CODES.DEPLOY_FAILED,
|
|
message: `Upload failed: ${uploadResult.error}`,
|
|
},
|
|
};
|
|
}
|
|
|
|
return {
|
|
success: true,
|
|
data: uploadResult.data,
|
|
};
|
|
};
|
|
|
|
export const appDeploy = (
|
|
options: AppDeployOptions,
|
|
): Promise<CommandResult<AppDeployResult>> =>
|
|
runSafe(() => innerAppDeploy(options), APP_ERROR_CODES.DEPLOY_FAILED);
|