Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
protected loadReporters(): this {
if (this.initialized) {
return this;
}
if (isEmpty(this.config)) {
throw new Error(this.msg('errors:configNotLoaded', { name: 'reporters' }));
}
const reporters = this.plugins.reporter!;
const { loader } = this.pluginTypes.reporter!;
// Use a special reporter when in a CI
// istanbul ignore next
if (this.isCI() && !env('ENV')) {
loader.debug('CI environment detected, using %s CI reporter', color.moduleName('boost'));
this.addPlugin('reporter', new CIReporter());
// Use default reporter
} else if (
reporters.size === 0 ||
(reporters.size === 1 && instanceOf(Array.from(reporters)[0], ErrorReporter))
) {
loader.debug('Using default %s reporter', color.moduleName('boost'));
this.addPlugin('reporter', new BoostReporter());
}
return this;
}
header: string(),
root: string(process.cwd()),
scoped: bool(),
settingsBlueprint: object(),
workspaceRoot: string(),
},
{
name: this.constructor.name,
},
);
this.appPath = Path.resolve(this.options.appPath);
this.rootPath = Path.resolve(this.options.root);
// Set environment variables
env('DEBUG_GLOBAL_NAMESPACE', this.options.appName);
// Core debugger, logger, and translator for the entire tool
this.debug = createDebugger('core');
this.log = createLogger();
this.msg = createTranslator(
['app', 'errors'],
[
new Path(__dirname, '../res'),
this.appPath.append('res'),
// TODO Remove in 2.0
this.appPath.append('resources'),
],
{
// TODO Change to yaml in 2.0
export default function createDebugger(namespace: string | string[]): Debugger {
const globalNamespace = env('DEBUG_GLOBAL_NAMESPACE');
const namespaces = toArray(namespace);
if (globalNamespace) {
namespaces.unshift(globalNamespace);
}
const mainNamespace = namespaces.join(':');
debug(
'New debugger created: %s %s',
mainNamespace,
env('DEBUG_VERBOSE') ? '(verbose enabled)' : '',
);
const logger = coreDebug(mainNamespace) as Debugger;
// `debug` doesn't support this on an individual namespace basis,
// so we have to manually support it using this hacky regex.
logger.disable = () => {
debug('Debugger %s disabled', mainNamespace);
process.env.DEBUG = (process.env.DEBUG || '')
.replace(new RegExp(`${logger.namespace}(:\\*)?`, 'u'), '')
.replace(/(^,)|(,$)/u, '')
.replace(',,', ',');
};
logger.enable = () => {
export default function createLogger({
labels = {},
stderr = process.stderr,
stdout = process.stdout,
}: LoggerOptions = {}): Logger {
let silent = false;
{
const defaultLevel = env('LOG_DEFAULT_LEVEL');
const maxLevel = env('LOG_MAX_LEVEL');
debug(
'New logger created: %s %s',
defaultLevel ? `${defaultLevel} level` : 'all levels',
maxLevel ? `(max ${maxLevel})` : '',
);
}
function logger(message: string, ...args: any[]) {
const self = logger as Logger;
const defaultLevel: LogLevel | undefined = env('LOG_DEFAULT_LEVEL');
if (defaultLevel && self[defaultLevel]) {
self[defaultLevel](message, ...args);
} else {
export default function createLogger({
labels = {},
stderr = process.stderr,
stdout = process.stdout,
}: LoggerOptions = {}): Logger {
let silent = false;
{
const defaultLevel = env('LOG_DEFAULT_LEVEL');
const maxLevel = env('LOG_MAX_LEVEL');
debug(
'New logger created: %s %s',
defaultLevel ? `${defaultLevel} level` : 'all levels',
maxLevel ? `(max ${maxLevel})` : '',
);
}
function logger(message: string, ...args: any[]) {
const self = logger as Logger;
const defaultLevel: LogLevel | undefined = env('LOG_DEFAULT_LEVEL');
if (defaultLevel && self[defaultLevel]) {
self[defaultLevel](message, ...args);
} else {
self.log(message, ...args);
function logger(message: string, ...args: any[]) {
const self = logger as Logger;
const defaultLevel: LogLevel | undefined = env('LOG_DEFAULT_LEVEL');
if (defaultLevel && self[defaultLevel]) {
self[defaultLevel](message, ...args);
} else {
self.log(message, ...args);
}
}
logger.verbose = (message, ...args) => {
if (env('DEBUG_VERBOSE')) {
logger(message, ...args);
}
};
value: function log(message: string, ...args: any[]) {
const maxLevel: LogLevel | undefined = env('LOG_MAX_LEVEL');
if (!silent && isAllowedLogLevel(level, maxLevel)) {
const output = util.format(message, ...args);
stream.write(level === 'log' ? `${output}\n` : `${label} ${output}\n`);
}
},
});
export default function createDebugger(namespace: string | string[]): Debugger {
const globalNamespace = env('DEBUG_GLOBAL_NAMESPACE');
const namespaces = toArray(namespace);
if (globalNamespace) {
namespaces.unshift(globalNamespace);
}
const mainNamespace = namespaces.join(':');
debug(
'New debugger created: %s %s',
mainNamespace,
env('DEBUG_VERBOSE') ? '(verbose enabled)' : '',
);
const logger = coreDebug(mainNamespace) as Debugger;