Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ reports
out
dist
docs
auth.json
auth.json
apkup.json
10 changes: 5 additions & 5 deletions src/actions/Upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,26 @@ export interface IReleaseNotes {
*/
export class Upload extends Edit {
private uploadParams: IUploadParams
private apk: string[]
private apks: string[]

private versionCodes: any[] = []

constructor (
client: JWT,
apk: string | string[],
apks: string[],
uploadParams: IUploadParams = {},
editParams: IEditParams
) {
super(client, editParams)

assert(apk, 'I require an APK file')
assert(apks, 'I require an APK file')
if (uploadParams.track) {
uploadParams.track = uploadParams.track.toLowerCase()

assert(checkTrack(uploadParams.track), 'Unknown track')
}

this.apk = typeof apk === 'string' ? [apk] : apk
this.apks = apks

this.uploadParams = uploadParams
this.uploadParams.track = uploadParams.track || 'internal'
Expand All @@ -64,7 +64,7 @@ export class Upload extends Edit {

private async uploadAPK () {
debug('> Uploading release')
const uploads = this.apk.map(async (apk) => {
const uploads = this.apks.map(async (apk) => {
const uploadJob = await this.publisher.edits.apks.upload({
editId: this.editId,
media: {
Expand Down
37 changes: 32 additions & 5 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import yargs from 'yargs'
import { promote } from './promote'
import { upload } from './upload'

const pkg = JSON.parse(
fs.readFileSync(path.join(__dirname, '../../package.json'), 'utf-8')
)
const readJson = (filePath: string) =>
JSON.parse(fs.readFileSync(filePath, 'utf-8'))

const pkg = readJson(path.join(__dirname, '../../package.json'))

const argv = yargs
.usage('Usage: $0 [options]')
Expand All @@ -23,11 +24,37 @@ const argv = yargs
describe: 'Path to the APK file',
type: 'array'
})
.option('packageName', {
alias: 'p',
describe: 'Name of the package (e.g. com.example.yourapp)',
type: 'string',
demandOption: true
})
.option('config', {
alias: 'c',
config: true
})
.default('config', 'apkup.json')
.config('config', 'Path to a JSON config file', (configPath: string) => {
const config = readJson(configPath)
if (config.key) {
config.auth = readJson(config.key)
}
return {
packageName: config.packageName,
p: config.packageName,
apk: config.apk,
a: config.apk,
key: config.key,
k: config.k,
auth: config.auth
}
})
.config(
'key',
'Path to a JSON file that contains the private key and client email (can be specified via APKUP_KEY env variable)',
(configPath) => {
return { auth: JSON.parse(fs.readFileSync(configPath, 'utf-8')) }
(configPath: string) => {
return { auth: readJson(configPath) }
}
)
.command(promote)
Expand Down
5 changes: 2 additions & 3 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ export interface IPackageManifest {
* @param apk Path to the APK file
*/
export const parseManifest = async (
apk: string | string[]
apk: string
): Promise<IPackageManifest> => {
debug('> Parsing manifest')
const apkFile = typeof apk !== 'string' ? apk[0] : apk
const reader = await ApkReader.open(apkFile)
const reader = await ApkReader.open(apk)
const manifest = await reader.readManifest()

debug(`> Detected package name ${manifest.package}`)
Expand Down
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ export class Apkup {

/**
* Upload an APK to the Google Play Developer Console.
* @param {string} apk The path to the APK.
* @param {string[]} apks The path to the APK.
* @param {object} uploadParams The params object will add additional information to this release.
*
* @returns An object with the response data.
*
* ```typescript
* const upload = await apkup.upload('./android-debug.apk', {
* const upload = await apkup.upload([ './android-debug.apk' ], {
* track: 'beta',
* releaseNotes: [
* {
Expand All @@ -64,17 +64,17 @@ export class Apkup {
* ```
*/
public async upload (
apk: string | string[],
apks: string[],
uploadParams?: IUploadParams
): Promise<IEditResponse> {
const apkPackage = await parseManifest(apk)
const apkPackage = await parseManifest(apks[0])

const editParams: IEditParams = {
packageName: apkPackage.packageName,
versionCode: apkPackage.versionCode
}

const upload = new Upload(this.client, apk, uploadParams, editParams)
const upload = new Upload(this.client, apks, uploadParams, editParams)
return upload.run()
}

Expand Down Expand Up @@ -108,7 +108,7 @@ export class Apkup {
*/
public async promote (
promoteParams: IPromoteParams,
apk?: string | string[],
apk?: string,
editParams?: IEditParams
) {
let edit: IEditParams
Expand Down