Skip to content

Commit 53f877f

Browse files
Merge pull request #568 from pattern-lab/features/logs
Features/logs
2 parents 2ee1090 + 1e54af0 commit 53f877f

File tree

7 files changed

+171
-141
lines changed

7 files changed

+171
-141
lines changed

core/lib/pattern_assembler.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var pattern_assembler = function () {
4545
return patternlab.patterns[i];
4646
}
4747
}
48-
plutils.logOrange('Could not find pattern referenced with partial syntax ' + partialName + '. This can occur when a pattern was renamed, moved, or no longer exists but it still called within a different template somewhere.');
48+
plutils.warning('Could not find pattern referenced with partial syntax ' + partialName + '. This can occur when a pattern was renamed, moved, or no longer exists but it still called within a different template somewhere.');
4949
return undefined;
5050
}
5151

@@ -81,7 +81,7 @@ var pattern_assembler = function () {
8181
if (patternlab.config.patternStates && patternlab.config.patternStates[pattern.patternPartial]) {
8282

8383
if (displayDeprecatedWarning) {
84-
plutils.logRed("Deprecation Warning: Using patternlab-config.json patternStates object will be deprecated in favor of the state frontmatter key associated with individual pattern markdown files.");
84+
plutils.error("Deprecation Warning: Using patternlab-config.json patternStates object will be deprecated in favor of the state frontmatter key associated with individual pattern markdown files.");
8585
console.log("This feature will still work in it's current form this release (but still be overridden by the new parsing method), and will be removed in the future.");
8686
}
8787

@@ -245,13 +245,13 @@ var pattern_assembler = function () {
245245
var relativeDepth = (relPath.match(/\w(?=\\)|\w(?=\/)/g) || []).length;
246246
if (relativeDepth > 2) {
247247
console.log('');
248-
plutils.logOrange('Warning:');
249-
plutils.logOrange('A pattern file: ' + relPath + ' was found greater than 2 levels deep from ' + patternlab.config.paths.source.patterns + '.');
250-
plutils.logOrange('It\'s strongly suggested to not deviate from the following structure under _patterns/');
251-
plutils.logOrange('[patternType]/[patternSubtype]/[patternName].[patternExtension]');
248+
plutils.warning('Warning:');
249+
plutils.warning('A pattern file: ' + relPath + ' was found greater than 2 levels deep from ' + patternlab.config.paths.source.patterns + '.');
250+
plutils.warning('It\'s strongly suggested to not deviate from the following structure under _patterns/');
251+
plutils.warning('[patternType]/[patternSubtype]/[patternName].[patternExtension]');
252252
console.log('');
253-
plutils.logOrange('While Pattern Lab may still function, assets may 404 and frontend links may break. Consider yourself warned. ');
254-
plutils.logOrange('Read More: http://patternlab.io/docs/pattern-organization.html');
253+
plutils.warning('While Pattern Lab may still function, assets may 404 and frontend links may break. Consider yourself warned. ');
254+
plutils.warning('Read More: http://patternlab.io/docs/pattern-organization.html');
255255
console.log('');
256256
}
257257

core/lib/patternlab.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ var diveSync = require('diveSync'),
2222
packageInfo = require('../../package.json'),
2323
plutils = require('./utilities');
2424

25+
//register our log events
26+
plutils.log.on('error', msg => console.log(msg));
27+
plutils.log.on('debug', msg => console.log(msg));
28+
plutils.log.on('warning', msg => console.log(msg));
29+
plutils.log.on('info', msg => console.log(msg));
30+
2531
console.log(
2632
chalk.bold('\n====[ Pattern Lab / Node'),
2733
`- v${packageInfo.version}`,
@@ -80,9 +86,9 @@ function checkConfiguration(patternlab) {
8086
};
8187

8288
if (!patternlab.config.outputFileSuffixes) {
83-
plutils.logOrange('Configuration Object "outputFileSuffixes" not found, and defaulted to the following:');
89+
plutils.warning('Configuration Object "outputFileSuffixes" not found, and defaulted to the following:');
8490
console.log(outputFileSuffixes);
85-
plutils.logOrange('Since Pattern Lab Core 2.3.0 this configuration option is required. Suggest you add it to your patternlab-config.json file.');
91+
plutils.warning('Since Pattern Lab Core 2.3.0 this configuration option is required. Suggest you add it to your patternlab-config.json file.');
8692
console.log();
8793
}
8894
patternlab.config.outputFileSuffixes = _.extend(outputFileSuffixes, patternlab.config.outputFileSuffixes);
@@ -171,34 +177,34 @@ var patternlab_engine = function (config) {
171177
console.log('');
172178

173179
console.log('|=======================================|');
174-
plutils.logGreen(' Pattern Lab Node Help v' + patternlab.package.version);
180+
plutils.debug(' Pattern Lab Node Help v' + patternlab.package.version);
175181
console.log('|=======================================|');
176182

177183
console.log('');
178184
console.log('Command Line Interface - usually consumed by an edition');
179185
console.log('');
180186

181-
plutils.logGreen(' patternlab:build');
187+
plutils.debug(' patternlab:build');
182188
console.log(' > Compiles the patterns and frontend, outputting to config.paths.public');
183189
console.log('');
184190

185-
plutils.logGreen(' patternlab:patternsonly');
191+
plutils.debug(' patternlab:patternsonly');
186192
console.log(' > Compiles the patterns only, outputting to config.paths.public');
187193
console.log('');
188194

189-
plutils.logGreen(' patternlab:version');
195+
plutils.debug(' patternlab:version');
190196
console.log(' > Return the version of patternlab-node you have installed');
191197
console.log('');
192198

193-
plutils.logGreen(' patternlab:help');
199+
plutils.debug(' patternlab:help');
194200
console.log(' > Get more information about patternlab-node, pattern lab in general, and where to report issues.');
195201
console.log('');
196202

197-
plutils.logGreen(' patternlab:liststarterkits');
203+
plutils.debug(' patternlab:liststarterkits');
198204
console.log(' > Returns a url with the list of available starterkits hosted on the Pattern Lab organization Github account');
199205
console.log('');
200206

201-
plutils.logGreen(' patternlab:loadstarterkit');
207+
plutils.debug(' patternlab:loadstarterkit');
202208
console.log(' > Load a starterkit into config.paths.source/*');
203209
console.log(' > NOTE: Overwrites existing content, and only cleans out existing directory if --clean=true argument is passed.');
204210
console.log(' > NOTE: In most cases, `npm install starterkit-name` will precede this call.');
@@ -274,7 +280,7 @@ var patternlab_engine = function (config) {
274280
patternlab.userHead = headPattern.extendedTemplate;
275281
}
276282
catch (ex) {
277-
plutils.logRed('\nWARNING: Could not find the user-editable header template, currently configured to be at ' + path.join(config.paths.source.meta, '_00-head.mustache') + '. Your configured path may be incorrect (check 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');
283+
plutils.error('\nWARNING: Could not find the user-editable header template, currently configured to be at ' + path.join(config.paths.source.meta, '_00-head.mustache') + '. Your configured path may be incorrect (check 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');
278284
if (patternlab.config.debug) { console.log(ex); }
279285
process.exit(1);
280286
}
@@ -294,7 +300,7 @@ var patternlab_engine = function (config) {
294300
patternlab.userFoot = footPattern.extendedTemplate;
295301
}
296302
catch (ex) {
297-
plutils.logRed('\nWARNING: Could not find the user-editable footer template, currently configured to be at ' + path.join(config.paths.source.meta, '_01-foot.mustache') + '. Your configured path may be incorrect (check 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');
303+
plutils.error('\nWARNING: Could not find the user-editable footer template, currently configured to be at ' + path.join(config.paths.source.meta, '_01-foot.mustache') + '. Your configured path may be incorrect (check 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');
298304
if (patternlab.config.debug) { console.log(ex); }
299305
process.exit(1);
300306
}
@@ -338,13 +344,13 @@ var patternlab_engine = function (config) {
338344
try {
339345
patternlab.data = buildPatternData(paths.source.data, fs);
340346
} catch (ex) {
341-
plutils.logRed('missing or malformed' + paths.source.data + 'data.json Pattern Lab may not work without this file.');
347+
plutils.error('missing or malformed' + paths.source.data + 'data.json Pattern Lab may not work without this file.');
342348
patternlab.data = {};
343349
}
344350
try {
345351
patternlab.listitems = fs.readJSONSync(path.resolve(paths.source.data, 'listitems.json'));
346352
} catch (ex) {
347-
plutils.logOrange('WARNING: missing or malformed ' + paths.source.data + 'listitems.json file. Pattern Lab may not work without this file.');
353+
plutils.warning('WARNING: missing or malformed ' + paths.source.data + 'listitems.json file. Pattern Lab may not work without this file.');
348354
patternlab.listitems = {};
349355
}
350356
try {
@@ -355,7 +361,7 @@ var patternlab_engine = function (config) {
355361
patternlab.viewAll = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'viewall.mustache'), 'utf8');
356362
} catch (ex) {
357363
console.log(ex);
358-
plutils.logRed('\nERROR: missing an essential file from ' + paths.source.patternlabFiles + '. Pattern Lab won\'t work without this file.\n');
364+
plutils.error('\nERROR: missing an essential file from ' + paths.source.patternlabFiles + '. Pattern Lab won\'t work without this file.\n');
359365
process.exit(1);
360366
}
361367
patternlab.patterns = [];

core/lib/plugin_manager.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ var plugin_manager = function (config, configPath) {
2929
try {
3030
var pluginDirStats = fs.statSync(pluginPath);
3131
} catch (ex) {
32-
util.logRed(pluginName + ' not found, please use npm to install it first.');
33-
util.logRed(pluginName + ' not loaded.');
32+
util.error(pluginName + ' not found, please use npm to install it first.');
33+
util.error(pluginName + ' not loaded.');
3434
return;
3535
}
3636
var pluginPathDirExists = pluginDirStats.isDirectory();
@@ -50,7 +50,7 @@ var plugin_manager = function (config, configPath) {
5050
//write config entry back
5151
fs.outputFileSync(path.resolve(configPath), JSON.stringify(diskConfig, null, 2));
5252

53-
util.logGreen('Plugin ' + pluginName + ' installed.');
53+
util.debug('Plugin ' + pluginName + ' installed.');
5454

5555
//todo, tell them how to uninstall or disable
5656

core/lib/starterkit_manager.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var starterkit_manager = function (config) {
88
paths = config.paths;
99

1010
/**
11-
* Loads npm module identified by the starterkitName parameter.
11+
* Loads npm module identified by the starterkitName parameter.
1212
*
1313
* @param starterkitName {string} Kit name
1414
* @param clean {boolean} Indicates if the directory should be cleaned before loading
@@ -22,8 +22,8 @@ var starterkit_manager = function (config) {
2222
try {
2323
var kitDirStats = fs.statSync(kitPath);
2424
} catch (ex) {
25-
util.logRed(starterkitName + ' not found, please use npm to install it first.');
26-
util.logRed(starterkitName + ' not loaded.');
25+
util.error(starterkitName + ' not found, please use npm to install it first.');
26+
util.error(starterkitName + ' not loaded.');
2727
return;
2828
}
2929
var kitPathDirExists = kitDirStats.isDirectory();
@@ -40,7 +40,7 @@ var starterkit_manager = function (config) {
4040
if (ex) {
4141
console.error(ex);
4242
}
43-
util.logGreen('starterkit ' + starterkitName + ' loaded successfully.');
43+
util.debug('starterkit ' + starterkitName + ' loaded successfully.');
4444
});
4545
}
4646
} catch (ex) {

core/lib/ui_builder.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ var ui_builder = function () {
167167
var patternType = _.find(patternlab.patternTypes, ['patternType', pattern.patternType]);
168168

169169
if (!patternType) {
170-
plutils.logRed('Could not find patternType' + pattern.patternType + '. This is a critical error.');
170+
plutils.error('Could not find patternType' + pattern.patternType + '. This is a critical error.');
171171
console.trace();
172172
process.exit(1);
173173
}
@@ -186,7 +186,7 @@ var ui_builder = function () {
186186
var patternSubType = _.find(patternType.patternTypeItems, ['patternSubtype', pattern.patternSubType]);
187187

188188
if (!patternSubType) {
189-
plutils.logRed('Could not find patternType ' + pattern.patternType + '-' + pattern.patternType + '. This is a critical error.');
189+
plutils.error('Could not find patternType ' + pattern.patternType + '-' + pattern.patternType + '. This is a critical error.');
190190
console.trace();
191191
process.exit(1);
192192
}
@@ -274,7 +274,7 @@ var ui_builder = function () {
274274
function addPatternItem(patternlab, pattern, isViewAllVariant) {
275275
var patternType = getPatternType(patternlab, pattern);
276276
if (!patternType) {
277-
plutils.logRed('Could not find patternType' + pattern.patternType + '. This is a critical error.');
277+
plutils.error('Could not find patternType' + pattern.patternType + '. This is a critical error.');
278278
console.trace();
279279
process.exit(1);
280280
}

0 commit comments

Comments
 (0)