Skip to content

Commit 2e821fe

Browse files
committed
feat(feat(logs): Rename utilities variable to logger
1 parent d127296 commit 2e821fe

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed

core/lib/patternlab.js

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const inherits = require('util').inherits;
2020
const pm = require('./plugin_manager');
2121
const packageInfo = require('../../package.json');
2222
const dataLoader = require('./data_loader')();
23-
const plutils = require('./utilities');
23+
const logger = require('./utilities');
2424
const jsonCopy = require('./json_copy');
2525
const PatternGraph = require('./pattern_graph').PatternGraph;
2626
const pa = require('./pattern_assembler');
@@ -85,14 +85,14 @@ class PatternLab {
8585
try {
8686
this.data = buildPatternData(paths.source.data, fs);
8787
} catch (ex) {
88-
plutils.error('missing or malformed' + paths.source.data + 'data.json Pattern Lab may not work without this file.');
88+
logger.error('missing or malformed' + paths.source.data + 'data.json Pattern Lab may not work without this file.');
8989
this.data = {};
9090
}
9191
// listitems.json
9292
try {
9393
this.listitems = fs.readJSONSync(path.resolve(paths.source.data, 'listitems.json'));
9494
} catch (ex) {
95-
plutils.warning('WARNING: missing or malformed ' + paths.source.data + 'listitems.json file. Pattern Lab may not work without this file.');
95+
logger.warning('WARNING: missing or malformed ' + paths.source.data + 'listitems.json file. Pattern Lab may not work without this file.');
9696
this.listitems = {};
9797
}
9898
// load up all the necessary files from pattern lab that apply to every template
@@ -104,7 +104,7 @@ class PatternLab {
104104
this.viewAll = fs.readFileSync(path.resolve(paths.source.patternlabFiles.viewall), 'utf8');
105105
} catch (ex) {
106106
console.log(ex);
107-
plutils.error('\nERROR: missing an essential file from ' + paths.source.patternlabFiles + '. Pattern Lab won\'t work without this file.\n');
107+
logger.error('\nERROR: missing an essential file from ' + paths.source.patternlabFiles + '. Pattern Lab won\'t work without this file.\n');
108108

109109
// GTP: it seems increasingly naughty as we refactor to just unilaterally do this here,
110110
// but whatever. For now.
@@ -168,7 +168,7 @@ class PatternLab {
168168
this.userHead = headPattern.extendedTemplate;
169169
}
170170
catch (ex) {
171-
plutils.error('\nWARNING: Could not find the user-editable header template, currently configured to be at ' + path.join(this.config.paths.source.meta, '_00-head.mustache') + '. Your configured path may be incorrect (check this.config.paths.source.meta in your config file), the file may have been deleted, or it may have been left in the wrong place during a migration or update.\n');
171+
logger.error('\nWARNING: Could not find the user-editable header template, currently configured to be at ' + path.join(this.config.paths.source.meta, '_00-head.mustache') + '. Your configured path may be incorrect (check this.config.paths.source.meta in your config file), the file may have been deleted, or it may have been left in the wrong place during a migration or update.\n');
172172
if (this.config.debug) { console.log(ex); }
173173

174174
// GTP: it seems increasingly naughty as we refactor to just unilaterally do this here,
@@ -191,7 +191,7 @@ class PatternLab {
191191
this.userFoot = footPattern.extendedTemplate;
192192
}
193193
catch (ex) {
194-
plutils.error('\nWARNING: Could not find the user-editable footer template, currently configured to be at ' + path.join(this.config.paths.source.meta, '_01-foot.mustache') + '. Your configured path may be incorrect (check this.config.paths.source.meta in your config file), the file may have been deleted, or it may have been left in the wrong place during a migration or update.\n');
194+
logger.error('\nWARNING: Could not find the user-editable footer template, currently configured to be at ' + path.join(this.config.paths.source.meta, '_01-foot.mustache') + '. Your configured path may be incorrect (check this.config.paths.source.meta in your config file), the file may have been deleted, or it may have been left in the wrong place during a migration or update.\n');
195195
if (this.config.debug) { console.log(ex); }
196196

197197
// GTP: it seems increasingly naughty as we refactor to just unilaterally do this here,
@@ -258,22 +258,22 @@ class PatternLab {
258258
// handle the legacy value, which is boolean
259259
if (typeof logLevel === 'boolean') {
260260
if (logLevel) {
261-
plutils.log.on('debug', msg => console.log(msg));
261+
logger.log.on('debug', msg => console.log(msg));
262262
}
263-
plutils.log.on('info', msg => console.log(msg));
264-
plutils.log.on('warning', msg => console.log(msg));
265-
plutils.log.on('error', msg => console.log(msg));
263+
logger.log.on('info', msg => console.log(msg));
264+
logger.log.on('warning', msg => console.log(msg));
265+
logger.log.on('error', msg => console.log(msg));
266266
} else {
267267
if ( logLevel === 'quiet') { return; }
268268
switch (logLevel) {
269269
case 'debug':
270-
plutils.log.on('debug', msg => console.log(msg));
270+
logger.log.on('debug', msg => console.log(msg));
271271
case 'info':
272-
plutils.log.on('info', msg => console.log(msg));
272+
logger.log.on('info', msg => console.log(msg));
273273
case 'warning':
274-
plutils.log.on('warning', msg => console.log(msg));
274+
logger.log.on('warning', msg => console.log(msg));
275275
case 'error':
276-
plutils.log.on('error', msg => console.log(msg));
276+
logger.log.on('error', msg => console.log(msg));
277277
}
278278
}
279279
}
@@ -359,26 +359,26 @@ function checkConfiguration(patternlab) {
359359
};
360360

361361
if (!patternlab.config.outputFileSuffixes) {
362-
plutils.warning('');
363-
plutils.warning('Configuration key [outputFileSuffixes] not found, and defaulted to the following:');
362+
logger.warning('');
363+
logger.warning('Configuration key [outputFileSuffixes] not found, and defaulted to the following:');
364364
console.log(outputFileSuffixes);
365-
plutils.warning('Since Pattern Lab Node Core 2.3.0 this configuration option is required. Suggest you add it to your patternlab-config.json file.');
366-
plutils.warning('');
365+
logger.warning('Since Pattern Lab Node Core 2.3.0 this configuration option is required. Suggest you add it to your patternlab-config.json file.');
366+
logger.warning('');
367367
}
368368
patternlab.config.outputFileSuffixes = _.extend(outputFileSuffixes, patternlab.config.outputFileSuffixes);
369369

370370
if (typeof patternlab.config.paths.source.patternlabFiles === 'string') {
371-
plutils.warning('');
372-
plutils.warning(`Configuration key [paths.source.patternlabFiles] inside patternlab-config.json was found as the string '${patternlab.config.paths.source.patternlabFiles}'`);
373-
plutils.warning('Since Pattern Lab Node Core 3.0.0 this key is an object. Suggest you update this key following this issue: https://github.com/pattern-lab/patternlab-node/issues/683.');
374-
plutils.warning('');
371+
logger.warning('');
372+
logger.warning(`Configuration key [paths.source.patternlabFiles] inside patternlab-config.json was found as the string '${patternlab.config.paths.source.patternlabFiles}'`);
373+
logger.warning('Since Pattern Lab Node Core 3.0.0 this key is an object. Suggest you update this key following this issue: https://github.com/pattern-lab/patternlab-node/issues/683.');
374+
logger.warning('');
375375
}
376376

377377
if (typeof patternlab.config.debug === 'boolean') {
378-
plutils.warning('');
379-
plutils.warning(`Configuration key [debug] inside patternlab-config.json was found as a boolean. As of Pattern Lab Node Core 3.0.0 this key is a string with possible values ['debug', 'info', 'warning', 'error', 'quiet'].`);
380-
plutils.warning(`Turning on 'info', 'warning', and 'error' levels by default`);
381-
plutils.warning('');
378+
logger.warning('');
379+
logger.warning(`Configuration key [debug] inside patternlab-config.json was found as a boolean. As of Pattern Lab Node Core 3.0.0 this key is a string with possible values ['debug', 'info', 'warning', 'error', 'quiet'].`);
380+
logger.warning(`Turning on 'info', 'warning', and 'error' levels by default`);
381+
logger.warning('');
382382
}
383383

384384
}
@@ -440,34 +440,34 @@ const patternlab_engine = function (config) {
440440
console.log('');
441441

442442
console.log('|=======================================|');
443-
plutils.debug(' Pattern Lab Node Help v' + patternlab.package.version);
443+
logger.debug(' Pattern Lab Node Help v' + patternlab.package.version);
444444
console.log('|=======================================|');
445445

446446
console.log('');
447447
console.log('Command Line Interface - usually consumed by an edition');
448448
console.log('');
449449

450-
plutils.debug(' patternlab:build');
450+
logger.debug(' patternlab:build');
451451
console.log(' > Compiles the patterns and frontend, outputting to config.paths.public');
452452
console.log('');
453453

454-
plutils.debug(' patternlab:patternsonly');
454+
logger.debug(' patternlab:patternsonly');
455455
console.log(' > Compiles the patterns only, outputting to config.paths.public');
456456
console.log('');
457457

458-
plutils.debug(' patternlab:version');
458+
logger.debug(' patternlab:version');
459459
console.log(' > Return the version of patternlab-node you have installed');
460460
console.log('');
461461

462-
plutils.debug(' patternlab:help');
462+
logger.debug(' patternlab:help');
463463
console.log(' > Get more information about patternlab-node, pattern lab in general, and where to report issues.');
464464
console.log('');
465465

466-
plutils.debug(' patternlab:liststarterkits');
466+
logger.debug(' patternlab:liststarterkits');
467467
console.log(' > Returns a url with the list of available starterkits hosted on the Pattern Lab organization Github account');
468468
console.log('');
469469

470-
plutils.debug(' patternlab:loadstarterkit');
470+
logger.debug(' patternlab:loadstarterkit');
471471
console.log(' > Load a starterkit into config.paths.source/*');
472472
console.log(' > NOTE: Overwrites existing content, and only cleans out existing directory if --clean=true argument is passed.');
473473
console.log(' > NOTE: In most cases, `npm install starterkit-name` will precede this call.');
@@ -587,7 +587,7 @@ const patternlab_engine = function (config) {
587587

588588
// Allows serializing the compile state
589589
patternlab.graph.node(pattern).compileState = pattern.compileState = CompileState.CLEAN;
590-
plutils.log.info("Built pattern: " + pattern.patternPartial);
590+
logger.log.info("Built pattern: " + pattern.patternPartial);
591591

592592
return Promise.resolve(true);
593593
}
@@ -613,7 +613,7 @@ const patternlab_engine = function (config) {
613613

614614
function cleanBuildDirectory(incrementalBuildsEnabled) {
615615
if (incrementalBuildsEnabled) {
616-
plutils.log.info("Incremental builds enabled.");
616+
logger.log.info("Incremental builds enabled.");
617617
} else {
618618
// needs to be done BEFORE processing patterns
619619
fs.removeSync(paths.public.patterns);
@@ -638,7 +638,7 @@ const patternlab_engine = function (config) {
638638
const graph = patternlab.graph = loadPatternGraph(deletePatternDir);
639639
const graphNeedsUpgrade = !PatternGraph.checkVersion(graph);
640640
if (graphNeedsUpgrade) {
641-
plutils.log.info("Due to an upgrade, a complete rebuild is required and the public/patterns directory was deleted. " +
641+
logger.log.info("Due to an upgrade, a complete rebuild is required and the public/patterns directory was deleted. " +
642642
"Incremental build is available again on the next successful run.");
643643

644644
// Ensure that the freshly built graph has the latest version again.
@@ -701,7 +701,7 @@ const patternlab_engine = function (config) {
701701
// When the graph was loaded from file, some patterns might have been moved/deleted between runs
702702
// so the graph data become out of sync
703703
patternlab.graph.sync().forEach(n => {
704-
plutils.log.info("[Deleted/Moved] " + n);
704+
logger.log.info("[Deleted/Moved] " + n);
705705
});
706706

707707
// TODO Find created or deleted files
@@ -726,7 +726,7 @@ const patternlab_engine = function (config) {
726726
PatternGraph.storeToFile(patternlab);
727727
if (patternlab.config.exportToGraphViz) {
728728
PatternGraph.exportToDot(patternlab, "dependencyGraph.dot");
729-
plutils.log.info(`Exported pattern graph to ${path.join(config.paths.public.root, "dependencyGraph.dot")}`);
729+
logger.log.info(`Exported pattern graph to ${path.join(config.paths.public.root, "dependencyGraph.dot")}`);
730730
}
731731

732732
//export patterns if necessary

0 commit comments

Comments
 (0)