"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const schematics_1 = require("@angular-devkit/schematics");
const cordova_1 = require("../../lib/cordova");
const utility_1 = require("../../lib/utility");
const angular_utility_1 = require("../../lib/angular-utility");
/**
 * https://github.com/bamlab/fastlane-plugin-cordova
 * https://ionic.zone/fastlane/build-your-project-with-cordova-plugin
 * @param _options
 */
function default_1(_options) {
    return schematics_1.chain([
        angular_utility_1.toPromiseRule(async (tree, _context) => {
            let newVersion = _options.version;
            await utility_1.updatePackageFile(tree, (data) => {
                data.version = newVersion;
                return data;
            });
            cordova_1.updateCordovaConfig(tree, (data) => {
                if (newVersion) {
                    data.set('widget.#.version', newVersion);
                    let versionCode = data.get("widget.#.android-versionCode");
                    let versionCodeInt;
                    try {
                        if (!versionCode) {
                            versionCodeInt = 0;
                        }
                        else {
                            versionCodeInt = parseInt(versionCode);
                        }
                        if (isNaN(versionCodeInt)) {
                            throw new Error('widget.android-versionCode has an invalid value that cannot be parsed as a number. Please fix in confix.xml');
                        }
                        data.set("widget.#.android-versionCode", versionCodeInt + 1);
                    }
                    catch (err) {
                        _context.logger.warn(`Cannot increment 'widget.android-versionCode': ${err.message}`);
                    }
                }
            });
        })
    ]);
}
exports.default = default_1;
//# sourceMappingURL=index.js.map