"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const command_1 = require("../utils/command");
exports.CORDOVA_INTENT = 'CORDOVA';
/**
 * Filter and gather arguments from command line to be passed to Cordova
 */
function filterArgumentsForCordova(metadata, inputs, options) {
    const results = command_1.filterOptionsByIntent(metadata, options, exports.CORDOVA_INTENT);
    const args = command_1.minimistOptionsToArray(results, { useEquals: false, allowCamelCase: true });
    let unparsedCdvArgs = [];
    const indexOfSep = inputs.indexOf('--');
    if (indexOfSep >= 0) {
        unparsedCdvArgs = inputs.splice(indexOfSep);
    }
    return [metadata.name].concat(inputs, args, unparsedCdvArgs);
}
exports.filterArgumentsForCordova = filterArgumentsForCordova;
/**
 * Start the app scripts server for emulator or device
 */
function generateBuildOptions(metadata, options) {
    const results = command_1.filterOptionsByIntent(metadata, options);
    // Serve specific options not related to the actual run or emulate code
    return Object.assign({}, results, { iscordovaserve: true, nobrowser: true });
}
exports.generateBuildOptions = generateBuildOptions;
function getCordovaCLIVersion() {
    return tslib_1.__awaiter(this, void 0, void 0, function* () {
        const { getCommandInfo } = yield Promise.resolve().then(function () { return require('../utils/shell'); });
        return getCommandInfo('cordova', ['-v', '--no-telemetry']);
    });
}
exports.getCordovaCLIVersion = getCordovaCLIVersion;
function getCordovaPlatformVersions() {
    return tslib_1.__awaiter(this, void 0, void 0, function* () {
        const { getCommandInfo } = yield Promise.resolve().then(function () { return require('../utils/shell'); });
        let cordovaPlatforms = yield getCommandInfo('cordova', ['platform', 'ls', '--no-telemetry']);
        if (cordovaPlatforms) {
            cordovaPlatforms = cordovaPlatforms.replace(/\s+/g, ' ');
            cordovaPlatforms = cordovaPlatforms.replace('Installed platforms:', '');
            cordovaPlatforms = cordovaPlatforms.replace(/Available platforms.+/, '');
            cordovaPlatforms = cordovaPlatforms.trim();
        }
        return cordovaPlatforms;
    });
}
exports.getCordovaPlatformVersions = getCordovaPlatformVersions;
