"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const schematics_1 = require("@angular-devkit/schematics");
const enable_1 = require("ionic/commands/integrations/enable");
const utility_1 = require("../../lib/utility");
const ionic_1 = require("../../lib/ionic");
const angular_utility_1 = require("../../lib/angular-utility");
function default_1(_options) {
    return schematics_1.chain([
        angular_utility_1.toPromiseRule((tree, _context) => __awaiter(this, void 0, void 0, function* () {
            if (_options.overwrite) {
                if (tree.exists('config.xml')) {
                    tree.delete('config.xml');
                }
                ionic_1.updateIonicConfig(tree, (config) => {
                    if (config.integrations) {
                        console.info(`Deleting cordova integration from ionic config`);
                        delete config.integrations['cordova'];
                    }
                });
            }
            if (!tree.exists('config.xml')) {
                yield utility_1.runIonicCommand((namespace) => new enable_1.IntegrationsEnableCommand(namespace), [
                    'cordova'
                ]);
                // refreshTreeFromFile(tree, 'config.xml');
            }
        }))
    ]);
}
exports.default = default_1;
//# sourceMappingURL=index.js.map