diff --git a/.gitignore b/.gitignore index 0242489..197f9cc 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ reports out dist docs -auth.json \ No newline at end of file +auth.json +apkup.json \ No newline at end of file diff --git a/src/actions/Upload.ts b/src/actions/Upload.ts index 180f0d4..02e4f3a 100644 --- a/src/actions/Upload.ts +++ b/src/actions/Upload.ts @@ -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' @@ -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: { diff --git a/src/cli/index.ts b/src/cli/index.ts index 200d49c..ea30db1 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -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]') @@ -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) diff --git a/src/helpers.ts b/src/helpers.ts index b229782..f35926f 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -15,11 +15,10 @@ export interface IPackageManifest { * @param apk Path to the APK file */ export const parseManifest = async ( - apk: string | string[] + apk: string ): Promise => { 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}`) diff --git a/src/index.ts b/src/index.ts index 83a7f0e..548fd5d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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: [ * { @@ -64,17 +64,17 @@ export class Apkup { * ``` */ public async upload ( - apk: string | string[], + apks: string[], uploadParams?: IUploadParams ): Promise { - 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() } @@ -108,7 +108,7 @@ export class Apkup { */ public async promote ( promoteParams: IPromoteParams, - apk?: string | string[], + apk?: string, editParams?: IEditParams ) { let edit: IEditParams