<commit_before>/**
 * Copyright (C) <NAME> 2017.
 * Distributed under the MIT License (license terms are at http://opensource.org/licenses/MIT).
 */

import * as fs from 'fs-extra';
import * as path from 'path';

import { FileUtils } from './file-utils';
import { ScaffsConfig } from '../contracts/scaffs-config';

const SCAFFS_CONFIG_FILE = '.scaffs-config.json';

export module ScaffsConfigLoader {

    /**
     * Loads a .scaffs-config.json
     *
     * @param path - absolute path to the directory containing .scaffs-config.json
     */
    export function loadConfig(projectRoot: string): Promise<ScaffsConfig> {
        return new Promise((resolve, reject) => {
            try {
                let config = fs.readJsonSync(path.join(projectRoot, SCAFFS_CONFIG_FILE));
                if (!config.baseConfigPath) {
                    config.baseConfigPath = projectRoot;
                }
                resolve(config);

            } catch (e) {
                reject(e);
            }
        });
    }

    /**
     * Populates the absolute paths of all available scaffolds
     *
     * @param param0 - a scaffs config object
     */
    export function resolveScaffolds(scaffsConfig: ScaffsConfig): Promise<ScaffsConfig> {
        return new Promise((resolve, reject) => {
            let absoluteScaffPaths: { [key: string]: string } = {};
            const { scaffs, baseConfigPath, scaffsPaths } = scaffsConfig;

            for (let key in scaffs) {
                if (scaffs.hasOwnProperty(key)) {
                    const absoluteScaffoldPath = path.resolve(baseConfigPath, scaffs[key]);

                    // only directories are scaffs
                    if (!FileUtils.directoryExistsSync(absoluteScaffoldPath)) {
                        if(FileUtils.existsSync(absoluteScaffoldPath)) {
                            reject(`Scaffold ${absoluteScaffoldPath} is not a directory.`);
                        } else {
                            reject(`Scaffold not found - ${absoluteScaffoldPath}`);
                        }
                        return;
                    }<commit_msg>fix lint error<commit_after>/**
 * Copyright (C) <NAME> 2017.
 * Distributed under the MIT License (license terms are at http://opensource.org/licenses/MIT).
 */

import * as fs from 'fs-extra';
import * as path from 'path';

import { FileUtils } from './file-utils';
import { ScaffsConfig } from '../contracts/scaffs-config';

const SCAFFS_CONFIG_FILE = '.scaffs-config.json';

export module ScaffsConfigLoader {

    /**
     * Loads a .scaffs-config.json
     *
     * @param path - absolute path to the directory containing .scaffs-config.json
     */
    export function loadConfig(projectRoot: string): Promise<ScaffsConfig> {
        return new Promise((resolve, reject) => {
            try {
                let config = fs.readJsonSync(path.join(projectRoot, SCAFFS_CONFIG_FILE));
                if (!config.baseConfigPath) {
                    config.baseConfigPath = projectRoot;
                }
                resolve(config);

            } catch (e) {
                reject(e);
            }
        });
    }

    /**
     * Populates the absolute paths of all available scaffolds
     *
     * @param param0 - a scaffs config object
     */
    export function resolveScaffolds(scaffsConfig: ScaffsConfig): Promise<ScaffsConfig> {
        return new Promise((resolve, reject) => {
            let absoluteScaffPaths: { [key: string]: string } = {};
            const { scaffs, baseConfigPath, scaffsPaths } = scaffsConfig;

            for (let key in scaffs) {
                if (scaffs.hasOwnProperty(key)) {
                    const absoluteScaffoldPath = path.resolve(baseConfigPath, scaffs[key]);

                    // only directories are scaffs
                    if (!FileUtils.directoryExistsSync(absoluteScaffoldPath)) {
                        if (FileUtils.existsSync(absoluteScaffoldPath)) {
                            reject(`Scaffold ${absoluteScaffoldPath} is not a directory.`);
                        } else {
                            reject(`Scaffold not found - ${absoluteScaffoldPath}`);
                        }
                        return;
                    }
{'fraction_non_alphanumeric': 0.10330188679245284, 'fraction_numerical': 0.0023584905660377358, 'mean_word_length': 1.8086092715231787, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6590161', 'n_tokens_mistral': 1166, 'n_tokens_neox': 1100, 'n_words': 275}