Skip to content

Commit

Permalink
Add debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmlnc committed Jul 29, 2017
1 parent bd59471 commit 7a6d2d8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -25,6 +25,7 @@
"out"
],
"devDependencies": {
"@types/debug": "0.0.29",
"@types/extend": "^2.0.30",
"@types/mocha": "^2.2.41",
"@types/node": "^8.0.17",
Expand All @@ -37,6 +38,7 @@
"typescript": "^2.4.2"
},
"dependencies": {
"debug": "^2.6.8",
"extend": "^3.0.1",
"locate-path": "^2.0.0",
"parse-json": "^2.2.0",
Expand Down
9 changes: 8 additions & 1 deletion src/managers/config.ts
@@ -1,9 +1,12 @@
'use strict';

import * as extend from 'extend';
import * as debuglog from 'debug';

import { ConfigType, IConfig, IResult, IOptions } from '../types';

const debug = debuglog('config-profiler:managers:config');

export function prepare(type: ConfigType, path: string, ctime: number, config: object): IConfig {
return { type, path, ctime, config };
}
Expand All @@ -23,5 +26,9 @@ export function build(type: ConfigType, path: string, config: object, options: I
config = extend(true, config, options.extendBuildedConfig);
}

return options.transform({ from, config });
const buildedConfig = options.transform({ from, config });

debug(`Builded config: %o`, buildedConfig);

return buildedConfig;
}
7 changes: 7 additions & 0 deletions src/services/parser.ts
@@ -1,9 +1,13 @@
'use strict';

import * as debuglog from 'debug';

import * as configManager from '../managers/config';

import { ConfigType, IConfig, IOptions } from '../types';

const debug = debuglog('config-profiler:services:parser');

function isPackageFile(filepath: string, config: object, options: IOptions): boolean {
return config && options.props.package && filepath.endsWith('package.json');
}
Expand All @@ -30,6 +34,9 @@ export function parse(content: string, filepath: string, ctime: number, options:

try {
config = item.parser(content);

debug(`Founded config was parsed by parser #${i} with the follow pattern: %o`, item.pattern);

break;
} catch (err) {
errors.push(err.toString());
Expand Down
15 changes: 15 additions & 0 deletions src/services/scanner.ts
@@ -1,6 +1,7 @@
'use strict';

import * as locatePath from 'locate-path';
import * as debuglog from 'debug';

import * as io from '../utils/io';

Expand All @@ -10,6 +11,8 @@ import * as configService from '../services/config';

import { Cache, ConfigType, IOptions, IResult } from '../types';

const debug = debuglog('config-profiler:services:scanner');

function isString(arg: any): arg is string {
return typeof arg === 'string';
}
Expand Down Expand Up @@ -42,12 +45,16 @@ export async function scan(cache: Cache, cwd: string, filepath: string, options:
// Try to use config from editor settings
const settings = options.settings;
if (settings && isObject(settings) && !isEmptyObject(settings)) {
debug('Returns config from editor settings.');

return configManager.build(ConfigType.Settings, null, settings, options);
}

// Try to use predefined config
const predefinedConfigs = options.predefinedConfigs;
if (settings && isString(settings) && isPredefinedConfig(predefinedConfigs, settings)) {
debug(`Returns config from predefined configs by name: "${settings}".`);

return configManager.build(ConfigType.Predefined, null, predefinedConfigs[settings], options);
}

Expand All @@ -56,6 +63,8 @@ export async function scan(cache: Cache, cwd: string, filepath: string, options:
const configPath = pathManager.resolve(cwd, settings);
const config = await configService.include(cache, configPath, options);
if (config) {
debug(`Returns config from settings by path: "${configPath}".`);

return configManager.build(ConfigType.File, configPath, config, options);
}
}
Expand All @@ -65,6 +74,8 @@ export async function scan(cache: Cache, cwd: string, filepath: string, options:
const configPath = getEnvVariable(options);
const config = await configService.include(cache, configPath, options);
if (config) {
debug(`Returns config from "${options.envVariableName}" variable by path: "${configPath}".`);

return configManager.build(ConfigType.File, configPath, config, options);
}
}
Expand All @@ -78,9 +89,13 @@ export async function scan(cache: Cache, cwd: string, filepath: string, options:
if (findedConfigPath) {
const config = await configService.include(cache, findedConfigPath, options);
if (config) {
debug(`Returns config by path: "${findedConfigPath}".`);

return configManager.build(ConfigType.File, findedConfigPath, config, options);
}
}

debug(`Config is not founded.`);

return null;
}

0 comments on commit 7a6d2d8

Please sign in to comment.