refactor: clean up logging

This commit is contained in:
Igor Randjelovic
2020-11-22 13:19:23 +01:00
parent b2b06bade7
commit 573d936976
3 changed files with 44 additions and 22 deletions

View File

@ -1,8 +1,7 @@
import path from 'path';
import fs from 'fs';
import dedent from 'ts-dedent';
import * as lib from '../index';
import { error, info } from './log';
import { error, info, warn } from './log';
import { getAllDependencies, getDependencyPath } from './dependencies';
export function applyExternalConfigs() {
@ -17,17 +16,22 @@ export function applyExternalConfigs() {
const externalConfig = require(configPath);
if (typeof externalConfig === 'function') {
info('Applying external config...');
externalConfig(lib);
} else if (externalConfig) {
info('Merging external config...');
lib.mergeWebpack(externalConfig);
} else {
// todo: warn user
// todo: perhaps support exported objects to merge into config?
warn(
'Unsupported external config. The config must export a function or an object.'
);
}
} catch (err) {
error(
dedent`
Unable to apply config: ${configPath}.
Error is:
`,
`
Unable to apply config: ${configPath}.
Error is:
`,
err
);
}