Skip to content

Commit

Permalink
Merge pull request #568 from pattern-lab/features/logs
Browse files Browse the repository at this point in the history
Features/logs
  • Loading branch information
bmuenzenmeyer authored Nov 26, 2016
2 parents 2ee1090 + 1e54af0 commit 53f877f
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 141 deletions.
16 changes: 8 additions & 8 deletions core/lib/pattern_assembler.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var pattern_assembler = function () {
return patternlab.patterns[i];
}
}
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.');
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.');
return undefined;
}

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

if (displayDeprecatedWarning) {
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.");
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.");
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.");
}

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

Expand Down
34 changes: 20 additions & 14 deletions core/lib/patternlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ var diveSync = require('diveSync'),
packageInfo = require('../../package.json'),
plutils = require('./utilities');

//register our log events
plutils.log.on('error', msg => console.log(msg));
plutils.log.on('debug', msg => console.log(msg));
plutils.log.on('warning', msg => console.log(msg));
plutils.log.on('info', msg => console.log(msg));

console.log(
chalk.bold('\n====[ Pattern Lab / Node'),
`- v${packageInfo.version}`,
Expand Down Expand Up @@ -80,9 +86,9 @@ function checkConfiguration(patternlab) {
};

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

console.log('|=======================================|');
plutils.logGreen(' Pattern Lab Node Help v' + patternlab.package.version);
plutils.debug(' Pattern Lab Node Help v' + patternlab.package.version);
console.log('|=======================================|');

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

plutils.logGreen(' patternlab:build');
plutils.debug(' patternlab:build');
console.log(' > Compiles the patterns and frontend, outputting to config.paths.public');
console.log('');

plutils.logGreen(' patternlab:patternsonly');
plutils.debug(' patternlab:patternsonly');
console.log(' > Compiles the patterns only, outputting to config.paths.public');
console.log('');

plutils.logGreen(' patternlab:version');
plutils.debug(' patternlab:version');
console.log(' > Return the version of patternlab-node you have installed');
console.log('');

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

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

plutils.logGreen(' patternlab:loadstarterkit');
plutils.debug(' patternlab:loadstarterkit');
console.log(' > Load a starterkit into config.paths.source/*');
console.log(' > NOTE: Overwrites existing content, and only cleans out existing directory if --clean=true argument is passed.');
console.log(' > NOTE: In most cases, `npm install starterkit-name` will precede this call.');
Expand Down Expand Up @@ -274,7 +280,7 @@ var patternlab_engine = function (config) {
patternlab.userHead = headPattern.extendedTemplate;
}
catch (ex) {
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');
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');
if (patternlab.config.debug) { console.log(ex); }
process.exit(1);
}
Expand All @@ -294,7 +300,7 @@ var patternlab_engine = function (config) {
patternlab.userFoot = footPattern.extendedTemplate;
}
catch (ex) {
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');
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');
if (patternlab.config.debug) { console.log(ex); }
process.exit(1);
}
Expand Down Expand Up @@ -338,13 +344,13 @@ var patternlab_engine = function (config) {
try {
patternlab.data = buildPatternData(paths.source.data, fs);
} catch (ex) {
plutils.logRed('missing or malformed' + paths.source.data + 'data.json Pattern Lab may not work without this file.');
plutils.error('missing or malformed' + paths.source.data + 'data.json Pattern Lab may not work without this file.');
patternlab.data = {};
}
try {
patternlab.listitems = fs.readJSONSync(path.resolve(paths.source.data, 'listitems.json'));
} catch (ex) {
plutils.logOrange('WARNING: missing or malformed ' + paths.source.data + 'listitems.json file. Pattern Lab may not work without this file.');
plutils.warning('WARNING: missing or malformed ' + paths.source.data + 'listitems.json file. Pattern Lab may not work without this file.');
patternlab.listitems = {};
}
try {
Expand All @@ -355,7 +361,7 @@ var patternlab_engine = function (config) {
patternlab.viewAll = fs.readFileSync(path.resolve(paths.source.patternlabFiles, 'viewall.mustache'), 'utf8');
} catch (ex) {
console.log(ex);
plutils.logRed('\nERROR: missing an essential file from ' + paths.source.patternlabFiles + '. Pattern Lab won\'t work without this file.\n');
plutils.error('\nERROR: missing an essential file from ' + paths.source.patternlabFiles + '. Pattern Lab won\'t work without this file.\n');
process.exit(1);
}
patternlab.patterns = [];
Expand Down
6 changes: 3 additions & 3 deletions core/lib/plugin_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ var plugin_manager = function (config, configPath) {
try {
var pluginDirStats = fs.statSync(pluginPath);
} catch (ex) {
util.logRed(pluginName + ' not found, please use npm to install it first.');
util.logRed(pluginName + ' not loaded.');
util.error(pluginName + ' not found, please use npm to install it first.');
util.error(pluginName + ' not loaded.');
return;
}
var pluginPathDirExists = pluginDirStats.isDirectory();
Expand All @@ -50,7 +50,7 @@ var plugin_manager = function (config, configPath) {
//write config entry back
fs.outputFileSync(path.resolve(configPath), JSON.stringify(diskConfig, null, 2));

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

//todo, tell them how to uninstall or disable

Expand Down
8 changes: 4 additions & 4 deletions core/lib/starterkit_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var starterkit_manager = function (config) {
paths = config.paths;

/**
* Loads npm module identified by the starterkitName parameter.
* Loads npm module identified by the starterkitName parameter.
*
* @param starterkitName {string} Kit name
* @param clean {boolean} Indicates if the directory should be cleaned before loading
Expand All @@ -22,8 +22,8 @@ var starterkit_manager = function (config) {
try {
var kitDirStats = fs.statSync(kitPath);
} catch (ex) {
util.logRed(starterkitName + ' not found, please use npm to install it first.');
util.logRed(starterkitName + ' not loaded.');
util.error(starterkitName + ' not found, please use npm to install it first.');
util.error(starterkitName + ' not loaded.');
return;
}
var kitPathDirExists = kitDirStats.isDirectory();
Expand All @@ -40,7 +40,7 @@ var starterkit_manager = function (config) {
if (ex) {
console.error(ex);
}
util.logGreen('starterkit ' + starterkitName + ' loaded successfully.');
util.debug('starterkit ' + starterkitName + ' loaded successfully.');
});
}
} catch (ex) {
Expand Down
6 changes: 3 additions & 3 deletions core/lib/ui_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ var ui_builder = function () {
var patternType = _.find(patternlab.patternTypes, ['patternType', pattern.patternType]);

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

if (!patternSubType) {
plutils.logRed('Could not find patternType ' + pattern.patternType + '-' + pattern.patternType + '. This is a critical error.');
plutils.error('Could not find patternType ' + pattern.patternType + '-' + pattern.patternType + '. This is a critical error.');
console.trace();
process.exit(1);
}
Expand Down Expand Up @@ -274,7 +274,7 @@ var ui_builder = function () {
function addPatternItem(patternlab, pattern, isViewAllVariant) {
var patternType = getPatternType(patternlab, pattern);
if (!patternType) {
plutils.logRed('Could not find patternType' + pattern.patternType + '. This is a critical error.');
plutils.error('Could not find patternType' + pattern.patternType + '. This is a critical error.');
console.trace();
process.exit(1);
}
Expand Down
Loading

0 comments on commit 53f877f

Please sign in to comment.