"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const schematics_1 = require("@angular-devkit/schematics");
const utility_1 = require("../../lib/utility");
function updateDep(baseDir, overwrite) {
    return (data) => {
        // console.log('Data: ', data);
        if (!data.compilerOptions) {
            data.compilerOptions = {};
        }
        ;
        if (!data.compilerOptions.baseUrl) {
            data.compilerOptions.baseUrl = './';
        }
        ;
        if (!data.compilerOptions.paths) {
            data.compilerOptions.paths = {};
        }
        ;
        if (overwrite || !data.compilerOptions.paths['@iotize/ionic']) {
            data.compilerOptions.paths['@iotize/ionic'] = [
                `${baseDir}/public-api`
            ];
        }
        if (overwrite || !data.compilerOptions.paths['@iotize/ionic/*']) {
            data.compilerOptions.paths['@iotize/ionic/*'] = [
                `${baseDir}/*`
            ];
        }
    };
}
// You don't have to export the function as default. You can also have more than one rule factory
// per file.
// This is the factory function 
function default_1(_options) {
    // Here we returns the rule
    // The tree is then virtual representation of every file in the workspace. 
    // Using a virtual tree instead of manipulating files directly comes with a couple of big advantages.
    return (tree, _context) => {
        let tsConfigApp = utility_1.getTsPathConfigFromProject(tree);
        if (!tree.exists(tsConfigApp)) {
            throw new schematics_1.SchematicsException(`tsconfig file ${tsConfigApp} does not exist`);
        }
        const baseDir = _options.baseDir || 'F:/iotize-projects/mobile-app/packages/tap-studio.ionic/out-tsc/@iotize-angular';
        utility_1.updateJsonFile(tree, tsConfigApp, updateDep(baseDir, _options.overwrite));
        utility_1.updateJsonFile(tree, 'tsconfig.json', updateDep(baseDir, _options.overwrite));
    };
}
exports.default = default_1;
//# sourceMappingURL=index.js.map