"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const schematics_1 = require("@angular-devkit/schematics");
const lib_1 = require("../../lib");
const definitions_1 = require("../../lib/definitions");
const cordova_1 = require("../../lib/cordova");
const angular_utility_1 = require("../../lib/angular-utility");
function default_1(_options) {
    return schematics_1.chain([
        (tree, _context) => {
            if (!tree.exists('config.xml') || _options.overwrite) {
                let project = lib_1.loadProject(tree, _context);
                return angular_utility_1.applyWithOverwriteRule(schematics_1.url('./files'), [
                    schematics_1.template({
                        useNFC: project.hasProtocol(definitions_1.AppProtocol.NFC),
                        appId: project.appConfigSchema.app.id,
                        nfcHost: project.appConfigSchema.app.domain
                    })
                ]);
            }
            else {
                return schematics_1.noop();
            }
        },
        (tree, _context) => {
            let project = lib_1.loadProject(tree, _context);
            let appConfig = project.appConfigSchema;
            // addCordovaPlugins(tree, appConfig);
            cordova_1.updateCordovaConfig(tree, (editor) => {
                if (!appConfig.app.id) {
                    throw new lib_1.MissingAppConfigKey(`app.id`);
                }
                if (!appConfig.app.name) {
                    throw new lib_1.MissingAppConfigKey(`app.name`);
                }
                editor.set('widget.name', appConfig.app.name);
                editor.set('widget.description', appConfig.app.description || 'An awesome Ionic/Cordova app to communicate with iotize devices');
                editor.set('widget.#.id', appConfig.app.id);
            });
            // Don't need this as ionic will automatically add missing plugins
            // await addCordovaPlugins(tree, appConfig);
            // updateAppConfig(tree, (data: TapAppGeneratorSchema) => {
            //     data.app.integrations = data.app.platforms.browser || {};
            //     data.app.integrations!.cordova = true;
            // });
        }
    ]);
}
exports.default = default_1;
//# sourceMappingURL=index.js.map