|
| 1 | +///<reference path="../.d.ts"/> |
| 2 | +"use strict"; |
| 3 | + |
| 4 | +import {StringCommandParameter} from "../common/command-params"; |
| 5 | + |
| 6 | +export class PublishIOS implements ICommand { |
| 7 | + constructor(private $errors: IErrors, |
| 8 | + private $injector: IInjector, |
| 9 | + private $itmsTransporterService: IITMSTransporterService, |
| 10 | + private $logger: ILogger, |
| 11 | + private $options: IOptions, |
| 12 | + private $projectData: IProjectData, |
| 13 | + private $prompter: IPrompter, |
| 14 | + private $stringParameterBuilder: IStringParameterBuilder) { } |
| 15 | + |
| 16 | + public allowedParameters: ICommandParameter[] = [new StringCommandParameter(this.$injector), new StringCommandParameter(this.$injector), |
| 17 | + new StringCommandParameter(this.$injector), new StringCommandParameter(this.$injector)]; |
| 18 | + |
| 19 | + public execute(args: string[]): IFuture<void> { |
| 20 | + return (() => { |
| 21 | + let username = args[0], |
| 22 | + password = args[1], |
| 23 | + mobileProvisionIdentifier = args[2], |
| 24 | + codeSignIdentity = args[3], |
| 25 | + ipaFilePath = this.$options.ipa; |
| 26 | + |
| 27 | + if(!username) { |
| 28 | + username = this.$prompter.getString("Apple ID", { allowEmpty: false }).wait(); |
| 29 | + } |
| 30 | + |
| 31 | + if(!password) { |
| 32 | + password = this.$prompter.getPassword("Apple ID password").wait(); |
| 33 | + } |
| 34 | + |
| 35 | + let iOSApplications = this.$itmsTransporterService.getiOSApplications(username, password).wait(); |
| 36 | + if (!iOSApplications || !iOSApplications.length) { |
| 37 | + this.$errors.failWithoutHelp("You don't have any applications registered at iTunes Connect."); |
| 38 | + } |
| 39 | + |
| 40 | + let iosApplication = _.find(iOSApplications, app => app.bundleId === this.$projectData.projectId); |
| 41 | + |
| 42 | + if (!iosApplication) { |
| 43 | + this.$errors.failWithoutHelp(`No application found on iTunes Connect that matches identifier ${this.$projectData.projectId}`); |
| 44 | + } |
| 45 | + |
| 46 | + if(!mobileProvisionIdentifier) { |
| 47 | + this.$logger.warn("Mobile Provision identifier not set - a default one will be used. You can set one in App_Resources/iOS/build.xcconfig"); |
| 48 | + } |
| 49 | + |
| 50 | + if(!codeSignIdentity) { |
| 51 | + this.$logger.warn("Code Sign Identity not set - a default one will be used. You can set one in App_Resources/iOS/build.xcconfig"); |
| 52 | + } |
| 53 | + |
| 54 | + this.$options.release = true; |
| 55 | + this.$itmsTransporterService.upload({ |
| 56 | + appId: iosApplication.bundleId, |
| 57 | + username, |
| 58 | + password, |
| 59 | + mobileProvisionIdentifier, |
| 60 | + codeSignIdentity, |
| 61 | + ipaFilePath |
| 62 | + }).wait(); |
| 63 | + }).future<void>()(); |
| 64 | + } |
| 65 | +} |
| 66 | +$injector.registerCommand("publish|ios", PublishIOS); |
| 67 | +$injector.registerCommand("appstore|upload", PublishIOS); |
0 commit comments