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