"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const CONFIG_PATH = 'angular.json';
function readConfig(host) {
    const sourceText = host.read(CONFIG_PATH).toString('utf-8');
    return JSON.parse(sourceText);
}
exports.readConfig = readConfig;
function writeConfig(host, config) {
    host.overwrite(CONFIG_PATH, JSON.stringify(config, null, 2));
}
exports.writeConfig = writeConfig;
function isAngularBrowserProject(projectConfig) {
    if (projectConfig.projectType === 'application') {
        const buildConfig = projectConfig.architect.build;
        return buildConfig.builder === '@angular-devkit/build-angular:browser';
    }
    return false;
}
function getAngularAppName(config) {
    const projects = config.projects;
    const projectNames = Object.keys(projects);
    for (let projectName of projectNames) {
        const projectConfig = projects[projectName];
        if (isAngularBrowserProject(projectConfig)) {
            return projectName;
        }
    }
    return null;
}
exports.getAngularAppName = getAngularAppName;
function getAngularAppConfig(config) {
    const projects = config.projects;
    const projectNames = Object.keys(projects);
    for (let projectName of projectNames) {
        const projectConfig = projects[projectName];
        if (isAngularBrowserProject(projectConfig)) {
            return projectConfig;
        }
    }
    return null;
}
exports.getAngularAppConfig = getAngularAppConfig;
function addStyle(host, stylePath) {
    const config = readConfig(host);
    const appConfig = getAngularAppConfig(config);
    if (appConfig) {
        appConfig.architect.build.options.styles.push({
            input: stylePath
        });
        writeConfig(host, config);
    }
    else {
        console.log("Can't find an app.");
    }
}
exports.addStyle = addStyle;
function hasBootstrap(host) {
    const config = readConfig(host);
    const appConfig = getAngularAppConfig(config);
    let _hasBootstrap = false;
    if (appConfig) {
        const styles = appConfig.architect.build.options.styles;
        if (styles) {
            for (let style in styles) {
                if (styles[style].input && typeof (styles[style].input) === "string") {
                    if (styles[style].input.includes('bootstrap')) {
                        console.log("Bootstrap is already used.");
                        _hasBootstrap = true;
                    }
                }
                else if (styles[style] && typeof (styles[style]) === "string") {
                    if (styles[style].includes('bootstrap')) {
                        console.log("Bootstrap is already used.");
                        _hasBootstrap = true;
                    }
                }
            }
        }
        return _hasBootstrap;
    }
    else {
        console.log("This is not a Angular application.");
        return false;
    }
}
exports.hasBootstrap = hasBootstrap;
//# sourceMappingURL=config.js.map