Skip to content

Commit

Permalink
Merge pull request #19 from appcircleio/feat/BE-3059
Browse files Browse the repository at this point in the history
add cli methods for publish
  • Loading branch information
Alnyli07 authored Apr 7, 2024
2 parents 57f6e99 + 438a9e3 commit 63c779a
Show file tree
Hide file tree
Showing 10 changed files with 745 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Below is the list of commands currently supported by Appcircle CLI:
| `appcircle config <subcommand> [argument] [options]` | View and edit Appcircle CLI properties |
| `appcircle login [--pat]` | Get an access token for the session |
| `appcircle organization <subcommand> [action] [options]` | Manage organization users, roles, and details |
`appcircle publish <subcommand> [options]` | Manage publish module actions |
| `appcircle listBuildProfiles` | Get the list of build profiles |
| `appcircle listDistributionProfiles` | Get the list of distribution profiles |
| `appcircle listBuildProfileWorkflows [--profileId]` | Get the list of workflows for the profile |
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@appcircle/cli",
"version": "1.2.0",
"version": "1.3.0-beta.1",
"description": "CLI tool for running Appcircle services from the command line",
"main": "bin/appcircle",
"bin": {
Expand Down
2 changes: 2 additions & 0 deletions src/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ export const PROGRAM_NAME = "appcircle";
export const UNKNOWN_PARAM_VALUE = '-'
export const CURRENT_PARAM_VALUE = 'current'

export let globalVariables : {[key:string]: string} = {}

140 changes: 139 additions & 1 deletion src/core/command-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ import {
getOrganizationUserinfo,
assignRolesToUserInOrganitaion,
getOrganizationUsersWithRoles,
createPublishProfile,
getPublishProfiles,
uploadAppVersion,
deleteAppVersion,
getAppVersionDownloadLink,
getPublishByAppVersion,
startExistingPublishFlow,
setAppVersionReleaseCandidateStatus,
switchPublishProfileAutoPublishSettings,
getPublishProfileDetailById,
getPublishVariableGroups,
getPublishVariableListByGroupId,
deletePublishProfile,
renamePublishProfile,
getAppVersions,
downloadAppVersion,
} from '../services';
import { commandWriter, configWriter } from './writer';
import { trustAppcircleCertificate } from '../security/trust-url-certificate';
Expand Down Expand Up @@ -201,6 +217,124 @@ const handleOrganizationCommand = async (command: ProgramCommand, params: any) =
}
};

const handlePublishCommand = async (command: ProgramCommand, params: any) => {
if(params.platform && !['ios','android'].includes(params.platform)){
throw new ProgramError(`Invalid platform(${params.platform}). Supported platforms: ios, android`);
}
if (command.fullCommandName === `${PROGRAM_NAME}-publish-profile-create`) {
const profileRes = await createPublishProfile({ platform: params.platform, name: params.name });
commandWriter(CommandTypes.PUBLISH, {
fullCommandName: command.fullCommandName,
data: profileRes,
});
} else if (command.fullCommandName === `${PROGRAM_NAME}-publish-profile-list`) {
const profiles = await getPublishProfiles({ platform: params.platform });
commandWriter(CommandTypes.PUBLISH, {
fullCommandName: command.fullCommandName,
data: profiles,
});
} else if (command.fullCommandName === `${PROGRAM_NAME}-publish-profile-delete`) {
const response = await deletePublishProfile(params);
commandWriter(CommandTypes.PUBLISH, {
fullCommandName: command.fullCommandName,
data: response,
});
}
else if (command.fullCommandName === `${PROGRAM_NAME}-publish-profile-rename`) {
const response = await renamePublishProfile(params);
commandWriter(CommandTypes.PUBLISH, {
fullCommandName: command.fullCommandName,
data: response,
});
}
else if (command.fullCommandName === `${PROGRAM_NAME}-publish-profile-version-upload`) {
const spinner = createOra('Try to upload the app version').start();
try {
const responseData = await uploadAppVersion(params);
commandWriter(CommandTypes.PUBLISH, responseData);
spinner.text = `App version uploaded successfully.\n\nTaskId: ${responseData.taskId}`;
spinner.succeed();
} catch (e: any) {
spinner.fail('Upload failed');
throw e;
}
} else if (command.fullCommandName === `${PROGRAM_NAME}-publish-profile-version-delete`) {
const spinner = createOra('Try to remove the app version').start();
try {
const responseData = await deleteAppVersion(params);
commandWriter(CommandTypes.PUBLISH, responseData);
spinner.text = `App version removed successfully.\n\nTaskId: ${responseData.taskId}`;
spinner.succeed();
} catch (e: any) {
spinner.fail('Remove failed');
throw e;
}
} else if (command.fullCommandName === `${PROGRAM_NAME}-publish-start`) {
const spinner = createOra('Publish flow starting').start();
const publish = await getPublishByAppVersion(params);
const firstStep = publish.steps[0];
const startResponse = await startExistingPublishFlow({ ...params, publishId: firstStep.publishId });
commandWriter(CommandTypes.PUBLISH, startResponse);
spinner.text = `Publish started successfully.`;
spinner.succeed();
} else if (command.fullCommandName === `${PROGRAM_NAME}-publish-profile-version-download`) {
let spinner = createOra('Fetching app version download link').start();
try {
let downloadPath = path.resolve((params.path || '').replace('~', `${os.homedir}`));
const responseData = await getAppVersionDownloadLink(params);
const appVersions = await getAppVersions(params);
const appVersion = appVersions.find((appVersion: any) => appVersion.id === params.appVersionId);
if (!appVersion) {
spinner.fail();
throw new Error('App version not found');
}
spinner.text = `App version download link fetched successfully.`;
spinner.text = `Try to download the app version.`;
downloadPath = path.join(downloadPath, appVersion.fileName);
await downloadAppVersion({ url: responseData, path:downloadPath });
spinner.text = `App version downloaded successfully.\n\nDownload Path: ${downloadPath}`;
spinner.succeed();
} catch (e: any) {
spinner.fail('Process failed');
throw e;
}
} else if (command.fullCommandName === `${PROGRAM_NAME}-publish-profile-version-markAsRC`) {
const response = await setAppVersionReleaseCandidateStatus({...params, releaseCandidate: true });
commandWriter(CommandTypes.PUBLISH, {
fullCommandName: command.fullCommandName,
data: response,
});
} else if (command.fullCommandName === `${PROGRAM_NAME}-publish-profile-version-unmarkAsRC`) {
const response = await setAppVersionReleaseCandidateStatus({...params, releaseCandidate: false });
commandWriter(CommandTypes.PUBLISH, {
fullCommandName: command.fullCommandName,
data: response,
});
} else if (command.fullCommandName === `${PROGRAM_NAME}-publish-profile-settings-autopublish`) {
const publishProfileDetails = await getPublishProfileDetailById(params);
const response = await switchPublishProfileAutoPublishSettings({ ...params, currentProfileSettings: publishProfileDetails.profileSettings });
commandWriter(CommandTypes.PUBLISH, {
fullCommandName: command.fullCommandName,
data: response,
});
} else if (command.fullCommandName === `${PROGRAM_NAME}-publish-variable-group-list`) {
const variableGroups = await getPublishVariableGroups();
commandWriter(CommandTypes.PUBLISH, {
fullCommandName: command.fullCommandName,
data: variableGroups,
});
} else if (command.fullCommandName === `${PROGRAM_NAME}-publish-variable-group-view`) {
const variables = await getPublishVariableListByGroupId(params);
commandWriter(CommandTypes.PUBLISH, {
fullCommandName: command.fullCommandName,
data: variables.variables,
});
} else {
const beutufiyCommandName = command.fullCommandName.split('-').join(' ');
console.error(`"${beutufiyCommandName} ..." command not found \nRun "${beutufiyCommandName} --help" for more information`);
}
};

export const runCommand = async (command: ProgramCommand) => {
const params = command.opts() as any;
const commandName = command.name();
Expand All @@ -209,7 +343,7 @@ export const runCommand = async (command: ProgramCommand) => {
//console.log('Full-Command-Name: ', command.fullCommandName, params);

//In interactive mode, if any parameters have errors, we can't continue execution.
if(params.isError){
if (params.isError) {
process.exit(1);
}

Expand All @@ -222,6 +356,10 @@ export const runCommand = async (command: ProgramCommand) => {
return handleOrganizationCommand(command, params);
}

if (command.isGroupCommand(CommandTypes.PUBLISH)) {
return handlePublishCommand(command, params);
}

switch (commandName) {
case CommandTypes.LOGIN: {
responseData = await getToken(params);
Expand Down
Loading

0 comments on commit 63c779a

Please sign in to comment.