appstore-cli
Version:
A command-line interface (CLI) to interact with the Apple App Store Connect API.
149 lines (120 loc) • 4.4 kB
text/typescript
/**
* Represents the settings needed to build an iOS app using Fastlane.
*/
export interface BuildConfiguration {
/**
* The Xcode build scheme to use
*/
scheme: string;
/**
* Path to the Xcode workspace file
* Either workspace or project must be provided, but not both
*/
workspace?: string;
/**
* Path to the Xcode project file (if no workspace)
* Either workspace or project must be provided, but not both
*/
project?: string;
/**
* Build configuration (Debug, Release, etc.)
*/
configuration: string;
/**
* Target SDK (iphoneos, iphonesimulator, etc.)
*/
sdk?: string;
/**
* Build destination specifier
*/
destination?: string;
/**
* Custom derived data path
*/
derivedDataPath?: string;
/**
* Custom archive path
*/
archivePath?: string;
/**
* Custom variables to be passed to the build process
*/
customVariables?: Record<string, string>;
}
/**
* Validates a BuildConfiguration object
* @param config The BuildConfiguration to validate
* @returns Array of validation errors, empty if valid
*/
export function validateBuildConfiguration(config: BuildConfiguration): string[] {
const errors: string[] = [];
// Validate required fields
if (!config.scheme || config.scheme.trim() === '') {
errors.push('Scheme is required');
}
if (!config.configuration || config.configuration.trim() === '') {
errors.push('Configuration is required');
}
// Validate that either workspace or project is provided, but not both
const hasWorkspace = !!config.workspace && config.workspace.trim() !== '';
const hasProject = !!config.project && config.project.trim() !== '';
if (!hasWorkspace && !hasProject) {
errors.push('Either workspace or project must be provided');
}
if (hasWorkspace && hasProject) {
errors.push('Only one of workspace or project should be provided, not both');
}
// Validate file paths
if (hasWorkspace && !config.workspace?.endsWith('.xcworkspace')) {
errors.push('Workspace file must have .xcworkspace extension');
}
if (hasProject && !config.project?.endsWith('.xcodeproj')) {
errors.push('Project file must have .xcodeproj extension');
}
// Validate configuration values
const validConfigurations = ['Debug', 'Release', 'AdHoc', 'AppStore'];
if (config.configuration && !validConfigurations.includes(config.configuration) && config.configuration.trim() !== '') {
// This is just a warning, not an error, as custom configurations are allowed
}
// Validate SDK if provided
if (config.sdk && config.sdk.trim() !== '') {
const validSdks = ['iphoneos', 'iphonesimulator', 'macosx', 'appletvos', 'watchos'];
if (!validSdks.includes(config.sdk)) {
// Note: We're not strictly enforcing this as projects may have custom SDKs
// But we can log a warning
}
}
return errors;
}
/**
* Validates CLI arguments for build configuration
* @param argv The CLI arguments to validate
* @returns Array of validation errors, empty if valid
*/
export function validateBuildConfigurationArgs(argv: any): string[] {
const errors: string[] = [];
// Validate required fields
if (!argv.scheme || (typeof argv.scheme === 'string' && argv.scheme.trim() === '')) {
errors.push('Scheme is required');
}
if (!argv.configuration || (typeof argv.configuration === 'string' && argv.configuration.trim() === '')) {
errors.push('Configuration is required');
}
// Validate that either workspace or project is provided, but not both
const hasWorkspace = !!argv.workspace && (typeof argv.workspace === 'string') && argv.workspace.trim() !== '';
const hasProject = !!argv.project && (typeof argv.project === 'string') && argv.project.trim() !== '';
if (!hasWorkspace && !hasProject) {
errors.push('Either --workspace or --project must be provided');
}
if (hasWorkspace && hasProject) {
errors.push('Only one of --workspace or --project should be provided, not both');
}
// Validate file paths
if (hasWorkspace && typeof argv.workspace === 'string' && !argv.workspace.endsWith('.xcworkspace')) {
errors.push('Workspace file must have .xcworkspace extension');
}
if (hasProject && typeof argv.project === 'string' && !argv.project.endsWith('.xcodeproj')) {
errors.push('Project file must have .xcodeproj extension');
}
return errors;
}