diff --git a/core/lib/annotation_exporter.js b/core/lib/annotation_exporter.js index 4f4cb426a..fdeeb31bc 100644 --- a/core/lib/annotation_exporter.js +++ b/core/lib/annotation_exporter.js @@ -4,6 +4,7 @@ const glob = require('glob'); const fs = require('fs-extra'); const _ = require('lodash'); const mp = require('./markdown_parser'); +const logger = require('./log'); const annotations_exporter = function (pl) { @@ -18,9 +19,7 @@ const annotations_exporter = function (pl) { try { oldAnnotations = fs.readFileSync(path.resolve(paths.source.annotations, 'annotations.js'), 'utf8'); } catch (ex) { - if (pl.config.debug) { - console.log('annotations.js file missing from ' + paths.source.annotations + '. This may be expected.'); - } + logger.debug(`annotations.js file missing from ${paths.source.annotations}. This may be expected if you do not use annotations or are using markdown.`); return []; } @@ -31,8 +30,7 @@ const annotations_exporter = function (pl) { try { var oldAnnotationsJSON = JSON.parse(oldAnnotations); } catch (ex) { - console.log('There was an error parsing JSON for ' + paths.source.annotations + 'annotations.js'); - console.log(ex); + logger.error(`There was an error parsing JSON for ${paths.source.annotations}annotations.js`); return []; } return oldAnnotationsJSON.comments; diff --git a/core/lib/asset_copy.js b/core/lib/asset_copy.js index 9ac0d7a3c..1e512a96a 100644 --- a/core/lib/asset_copy.js +++ b/core/lib/asset_copy.js @@ -2,6 +2,7 @@ const _ = require('lodash'); const path = require('path'); const process = require('process'); +const logger = require('./log'); let copy = require('recursive-copy'); // eslint-disable-line prefer-const let chokidar = require('chokidar'); // eslint-disable-line prefer-const @@ -40,9 +41,7 @@ const asset_copier = () => { dest, options ).on(copy.events.COPY_FILE_COMPLETE, () => { - if (options.debug) { - console.log(`Moved ${p} to ${dest}`); - } + logger.debug(`Moved ${p} to ${dest}`); options.emitter.emit('patternlab-asset-change', { file: p, dest: dest @@ -70,9 +69,7 @@ const asset_copier = () => { //if we want to watch files, do so, otherwise just copy each file if (options.watch) { - if (patternlab.config.debug) { - console.log(`Pattern Lab is watching ${path.resolve(basePath, dir.source)} for changes`); - } + logger.info(`Pattern Lab is watching ${path.resolve(basePath, dir.source)} for changes`); if (patternlab.watchers[key]) { patternlab.watchers[key].close(); @@ -130,9 +127,7 @@ const asset_copier = () => { _.each(globalPaths, (globalPath) => { - if (patternlab.config.debug) { - console.log(`Pattern Lab is watching ${globalPath} for changes`); - } + logger.info(`Pattern Lab is watching ${globalPath} for changes`); if (patternlab.watchers[globalPath]) { patternlab.watchers[globalPath].close(); @@ -180,9 +175,8 @@ const asset_copier = () => { ) ); _.each(patternWatches, (patternWatchPath) => { - if (patternlab.config.debug) { - console.log(`Pattern Lab is watching ${patternWatchPath} for changes`); - } + + logger.info(`Pattern Lab is watching ${patternWatchPath} for changes`); const patternWatcher = chokidar.watch( path.resolve(patternWatchPath), diff --git a/core/lib/json_copy.js b/core/lib/json_copy.js index 84c9e249d..17bbd9af9 100644 --- a/core/lib/json_copy.js +++ b/core/lib/json_copy.js @@ -1,13 +1,13 @@ "use strict"; -const plutils = require('./utilities'); +const logger = require('./log'); const json_copy = (data, callee) => { try { return JSON.parse(JSON.stringify(data)); } catch (e) { //this is unlikely to be hit due to the passed in data already being loaded using JSON parsers - plutils.error(`JSON provided by ${callee} is invalid and cannot be copied`); - return {}; + logger.warning(`JSON provided by ${callee} is invalid and cannot be copied`); + throw (e); } }; diff --git a/core/lib/lineage_hunter.js b/core/lib/lineage_hunter.js index 7c61be98d..7bcd4a19f 100644 --- a/core/lib/lineage_hunter.js +++ b/core/lib/lineage_hunter.js @@ -1,5 +1,6 @@ 'use strict'; const extend = require("util")._extend; +const logger = require('./log'); const lineage_hunter = function () { @@ -119,9 +120,8 @@ const lineage_hunter = function () { const patternReverseStateIndex = patternStateCascade.indexOf(lineageRPattern.patternState); if (lineageRPattern.patternState === '' || (patternStateIndex < patternReverseStateIndex)) { - if (patternlab.config.debug) { - console.log('Found a lower common denominator pattern state: ' + pattern.patternState + ' on ' + pattern.patternPartial + '. Setting reverse lineage pattern ' + lineageRPattern.patternPartial + ' from ' + (lineageRPattern.patternState === '' ? '<>' : lineageRPattern.patternState)); - } + const oldState = lineageRPattern.patternState === '' ? '<>' : lineageRPattern.patternState; + logger.info(`Found a lower common denominator pattern state: ${pattern.patternState} on ${pattern.patternPartial}. Setting reverse lineage pattern ${lineageRPattern.patternPartial} from ${oldState}`); lineageRPattern.patternState = pattern.patternState; diff --git a/core/lib/list_item_hunter.js b/core/lib/list_item_hunter.js index 7ffe450de..846ecc7d8 100644 --- a/core/lib/list_item_hunter.js +++ b/core/lib/list_item_hunter.js @@ -7,6 +7,7 @@ const list_item_hunter = function () { const smh = require('./style_modifier_hunter'); const jsonCopy = require('./json_copy'); const Pattern = require('./object_factory').Pattern; + const logger = require('./log'); const pattern_assembler = new pa(); const style_modifier_hunter = new smh(); @@ -19,9 +20,7 @@ const list_item_hunter = function () { if (matches !== null) { matches.forEach(function (liMatch) { - if (patternlab.config.debug) { - console.log('found listItem of size ' + liMatch + ' inside ' + pattern.patternPartial); - } + logger.debug(`found listItem of size ${liMatch} inside ${pattern.patternPartial}`); //find the boundaries of the block const loopNumberString = liMatch.split('.')[1].split('}')[0].trim(); @@ -32,9 +31,8 @@ const list_item_hunter = function () { const repeatedBlockTemplate = []; let repeatedBlockHtml = ''; for (let i = 0; i < items.indexOf(loopNumberString); i++) { - if (patternlab.config.debug) { - console.log('list item(s) in pattern', pattern.patternPartial, 'adding', patternBlock, 'to repeatedBlockTemplate'); - } + + logger.debug(`list item(s) in pattern ${pattern.patternPartial}, adding ${patternBlock} to repeatedBlockTemplate`); repeatedBlockTemplate.push(patternBlock); } @@ -43,8 +41,8 @@ const list_item_hunter = function () { try { listData = jsonCopy(patternlab.listitems, 'config.paths.source.data listitems'); } catch (err) { - console.log('There was an error parsing JSON for ' + pattern.relPath); - console.log(err); + logger.warning(`There was an error parsing JSON for ${pattern.relPath}`); + logger.warning(err); } listData = _.merge(listData, pattern.listitems); @@ -64,8 +62,8 @@ const list_item_hunter = function () { globalData = jsonCopy(patternlab.data, 'config.paths.source.data global data'); localData = jsonCopy(pattern.jsonFileData, `${pattern.patternPartial} data`); } catch (err) { - console.log('There was an error parsing JSON for ' + pattern.relPath); - console.log(err); + logger.warning(`There was an error parsing JSON for ${pattern.relPath}`); + logger.warning(err); } let allData = _.merge(globalData, localData); @@ -89,8 +87,8 @@ const list_item_hunter = function () { cleanPartialPattern = JSON.parse(JSON.stringify(partialPattern)); cleanPartialPattern = jsonCopy(partialPattern, `partial pattern ${partialName}`); } catch (err) { - console.log('There was an error parsing JSON for ' + pattern.relPath); - console.log(err); + logger.warning(`There was an error parsing JSON for ${pattern.relPath}`); + logger.warning(err); } //if we retrieved a pattern we should make sure that its extendedTemplate is reset. looks to fix #356 diff --git a/core/lib/utilities.js b/core/lib/log.js similarity index 86% rename from core/lib/utilities.js rename to core/lib/log.js index 6c88dac90..661cf6a05 100644 --- a/core/lib/utilities.js +++ b/core/lib/log.js @@ -31,9 +31,17 @@ const log = Object.assign({ */ const debug = log.debug.bind(log); +/** + * @func info + * @desc Coloured info log + * @param {*} msg - The variadic messages to log out. + * @return {void} + */ +const info = log.info.bind(log); + /** * @func warning - * @desc Coloured error log + * @desc Coloured warning log * @param {*} e - The variadic messages to log out. * @return {void} */ @@ -62,6 +70,7 @@ const reportError = function (message) { module.exports = { debug, + info, warning, error, log, diff --git a/core/lib/markdown_parser.js b/core/lib/markdown_parser.js index 68fcfa68d..68ab4c42d 100644 --- a/core/lib/markdown_parser.js +++ b/core/lib/markdown_parser.js @@ -1,6 +1,7 @@ 'use strict'; const md = require('markdown-it')(); const yaml = require('js-yaml'); +const logger = require('./log'); const markdown_parser = function () { @@ -36,8 +37,8 @@ const markdown_parser = function () { returnObject.markdown = md.render(block); } } catch (ex) { - console.log(ex); - console.log('error parsing markdown block', block); + logger.warning(ex); + logger.warning(`error parsing markdown block ${block}`); return undefined; } diff --git a/core/lib/parameter_hunter.js b/core/lib/parameter_hunter.js index f236f5e31..f6e59e405 100644 --- a/core/lib/parameter_hunter.js +++ b/core/lib/parameter_hunter.js @@ -8,6 +8,7 @@ const parameter_hunter = function () { const smh = require('./style_modifier_hunter'); const style_modifier_hunter = new smh(); const pattern_assembler = new pa(); + const logger = require('./log'); /** * This function is really to accommodate the lax JSON-like syntax allowed by @@ -49,10 +50,9 @@ const parameter_hunter = function () { * * Return paramStringWellFormed. * * @param {string} pString - * @param {object} patternlab * @returns {string} paramStringWellFormed */ - function paramToJson(pString, patternlab) { + function paramToJson(pString) { let colonPos = -1; const keys = []; let paramString = pString; // to not reassign param @@ -67,10 +67,7 @@ const parameter_hunter = function () { paramStringWellFormed = JSON.stringify(JSON.parse(pString)); return paramStringWellFormed; } catch (err) { - //todo this might be a good candidate for a different log level, should we implement that someday - if (patternlab.config.debug) { - console.log(`Not valid JSON found for passed pattern parameter ${pString} will attempt to parse manually...`); - } + logger.debug(`Not valid JSON found for passed pattern parameter ${pString} will attempt to parse manually...`); } //replace all escaped double-quotes with escaped unicode @@ -256,15 +253,13 @@ const parameter_hunter = function () { //if we retrieved a pattern we should make sure that its extendedTemplate is reset. looks to fix #190 partialPattern.extendedTemplate = partialPattern.template; - if (patternlab.config.debug) { - console.log('found patternParameters for ' + partialName); - } + logger.debug(`found patternParameters for ${partialName}`); //strip out the additional data, convert string to JSON. const leftParen = pMatch.indexOf('('); const rightParen = pMatch.lastIndexOf(')'); const paramString = '{' + pMatch.substring(leftParen + 1, rightParen) + '}'; - const paramStringWellFormed = paramToJson(paramString, patternlab); + const paramStringWellFormed = paramToJson(paramString); let paramData = {}; let globalData = {}; @@ -275,8 +270,8 @@ const parameter_hunter = function () { globalData = jsonCopy(patternlab.data, 'config.paths.source.data global data'); localData = jsonCopy(pattern.jsonFileData || {}, `pattern ${pattern.patternPartial} data`); } catch (err) { - console.log('There was an error parsing JSON for ' + pattern.relPath); - console.log(err); + logger.warning(`There was an error parsing JSON for ${pattern.relPath}`); + logger.warning(err); } // resolve any pattern links that might be present diff --git a/core/lib/pattern_assembler.js b/core/lib/pattern_assembler.js index 701ef908d..ff9f36295 100644 --- a/core/lib/pattern_assembler.js +++ b/core/lib/pattern_assembler.js @@ -6,7 +6,7 @@ const Pattern = require('./object_factory').Pattern; const CompileState = require('./object_factory').CompileState; const pph = require('./pseudopattern_hunter'); const mp = require('./markdown_parser'); -const plutils = require('./utilities'); +const logger = require('./log'); const patternEngines = require('./pattern_engines'); const lh = require('./lineage_hunter'); const lih = require('./list_item_hunter'); @@ -52,7 +52,7 @@ const pattern_assembler = function () { return patternlab.patterns[i]; } } - 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.'); + logger.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; } @@ -103,9 +103,7 @@ const pattern_assembler = function () { // if the pattern is new, we must register it with various data structures! if (isNew) { - if (patternlab.config.debug) { - console.log('found new pattern ' + pattern.patternPartial); - } + logger.debug(`found new pattern ${pattern.patternPartial}`); // do global registration if (pattern.isPattern) { @@ -182,20 +180,15 @@ const pattern_assembler = function () { currentPattern.links = markdownObject.links; } } else { - if (patternlab.config.debug) { - console.log('error processing markdown for ' + currentPattern.patternPartial); - } - } - - if (patternlab.config.debug) { - console.log('found pattern-specific markdown for ' + currentPattern.patternPartial); + logger.warning(`error processing markdown for ${currentPattern.patternPartial}`); } + logger.debug(`found pattern-specific markdown for ${currentPattern.patternPartial}`); } catch (err) { // do nothing when file not found if (err.code !== 'ENOENT') { - console.log('there was an error setting pattern keys after markdown parsing of the companion file for pattern ' + currentPattern.patternPartial); - console.log(err); + logger.warning(`'there was an error setting pattern keys after markdown parsing of the companion file for pattern ${currentPattern.patternPartial}`); + logger.warning(err); } } } @@ -248,15 +241,15 @@ const pattern_assembler = function () { var relativeDepth = (relPath.match(/\w(?=\\)|\w(?=\/)/g) || []).length; if (relativeDepth > 2) { - console.log(''); - 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.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(''); + logger.warning(''); + logger.warning('Warning:'); + logger.warning('A pattern file: ' + relPath + ' was found greater than 2 levels deep from ' + patternlab.config.paths.source.patterns + '.'); + logger.warning('It\'s strongly suggested to not deviate from the following structure under _patterns/'); + logger.warning('[patternType]/[patternSubtype]/[patternName].[patternExtension]'); + logger.warning(''); + logger.warning('While Pattern Lab may still function, assets may 404 and frontend links may break. Consider yourself warned. '); + logger.warning('Read More: http://patternlab.io/docs/pattern-organization.html'); + logger.warning(''); } //check if the found file is a top-level markdown file @@ -282,7 +275,7 @@ const pattern_assembler = function () { } catch (err) { // no file exists, meaning it's a pattern markdown file if (err.code !== 'ENOENT') { - console.log(err); + logger.warning(err); } } } @@ -312,36 +305,32 @@ const pattern_assembler = function () { //look for a json file for this template try { var jsonFilename = path.resolve(patternsPath, currentPattern.subdir, currentPattern.fileName); - const configData = dataLoader.loadDataFromFile(jsonFilename, fs); + const patternData = dataLoader.loadDataFromFile(jsonFilename, fs); - if (configData) { - currentPattern.jsonFileData = configData; - if (patternlab.config.debug) { - console.log('processPatternIterative: found pattern-specific config data for ' + currentPattern.patternPartial); - } + if (patternData) { + currentPattern.jsonFileData = patternData; + logger.debug(`found pattern-specific data for ${currentPattern.patternPartial}`); } } catch (err) { - console.log('There was an error parsing sibling JSON for ' + currentPattern.relPath); - console.log(err); + logger.warning(`There was an error parsing sibling JSON for ${currentPattern.relPath}`); + logger.warning(err); } //look for a listitems.json file for this template try { var listJsonFileName = path.resolve(patternsPath, currentPattern.subdir, currentPattern.fileName + ".listitems"); - const listItemsConfig = dataLoader.loadDataFromFile(listJsonFileName, fs); + const listItemsData = dataLoader.loadDataFromFile(listJsonFileName, fs); - if (listItemsConfig) { - currentPattern.listitems = listItemsConfig; + if (listItemsData) { + logger.debug(`found pattern-specific listitems data for ${currentPattern.patternPartial}`); + currentPattern.listitems = listItemsData; buildListItems(currentPattern); - if (patternlab.config.debug) { - console.log('found pattern-specific listitems config for ' + currentPattern.patternPartial); - } } } catch (err) { - console.log('There was an error parsing sibling listitem JSON for ' + currentPattern.relPath); - console.log(err); + logger.warning(`There was an error parsing sibling listitem JSON for ${currentPattern.relPath}`); + logger.warning(err); } //look for a markdown file for this template @@ -382,7 +371,7 @@ const pattern_assembler = function () { //find any pattern parameters that may be in the current pattern pattern.parameteredPartials = pattern.findPartialsWithPatternParameters(); return pattern; - }).catch(plutils.reportError('There was an error in processPatternIterative():')); + }).catch(logger.reportError('There was an error in processPatternIterative():')); } function processPatternRecursive(file, patternlab) { @@ -447,9 +436,7 @@ const pattern_assembler = function () { var style_modifier_hunter = new smh(), parameter_hunter = new ph(); - if (patternlab.config.debug) { - console.log('found partials for ' + currentPattern.patternPartial); - } + logger.debug(`found partials for ${currentPattern.patternPartial}`); // determine if the template contains any pattern parameters. if so they // must be immediately consumed @@ -513,18 +500,15 @@ const pattern_assembler = function () { var fullLink = patternlab.data.link[linkPatternPartial]; if (fullLink) { fullLink = path.normalize(fullLink).replace(/\\/g, '/'); - if (patternlab.config.debug) { - console.log('expanded data link from ' + dataLink + ' to ' + fullLink + ' inside ' + key); - } + + logger.debug(`expanded data link from ${dataLink} to ${fullLink} inside ${key}`); //also make sure our global replace didn't mess up a protocol fullLink = fullLink.replace(/:\//g, '://'); dataObjAsString = dataObjAsString.replace('link.' + linkPatternPartial, fullLink); } } else { - if (patternlab.config.debug) { - console.log('pattern not found for', dataLink, 'inside', key); - } + logger.warning(`pattern not found for ${dataLink} inside ${key}`); } } } @@ -534,8 +518,8 @@ const pattern_assembler = function () { try { dataObj = JSON.parse(dataObjAsString); } catch (err) { - console.log('There was an error parsing JSON for ' + key); - console.log(err); + logger.warning(`There was an error parsing JSON for ${key}`); + logger.warning(err); } return dataObj; diff --git a/core/lib/pattern_engines.js b/core/lib/pattern_engines.js index 8b825ed29..b6e013a91 100644 --- a/core/lib/pattern_engines.js +++ b/core/lib/pattern_engines.js @@ -2,10 +2,10 @@ 'use strict'; const {existsSync, lstatSync, readdirSync} = require('fs'); const path = require('path'); -const chalk = require('chalk'); const engineMatcher = /^patternengine-node-(.*)$/; const scopeMatch = /^@(.*)$/; const isDir = fPath => lstatSync(fPath).isDirectory(); +const logger = require('./log'); const enginesDirectories = [{ displayName: 'the core', @@ -20,7 +20,7 @@ const enginesDirectories = [{ function isEngineModule(filePath) { const baseName = path.basename(filePath); const engineMatch = baseName.match(engineMatcher); - + if (engineMatch) { return engineMatch[1]; } return false; } @@ -43,12 +43,12 @@ function isScopedPackage(filePath) { * @return {Array} An array of engine objects */ function resolveEngines(dir) { - + // Guard against non-existent directories. if (!existsSync(dir)) { return []; // Silence is golden … } - + /** * @name walk * @desc Traverse the given path and gather possible engines @@ -57,14 +57,14 @@ function resolveEngines(dir) { * @return {Array} - The final array of engines */ const walk = (fPath, engines) => { - + /** * @name dirList * @desc A list of all directories in the given path * @type {Array} */ const dirList = readdirSync(fPath).filter(p => isDir(path.join(fPath, p))); - + /** * @name e * @desc For the current dir get all engines @@ -76,10 +76,10 @@ function resolveEngines(dir) { return { name: isEngineModule(engine), modulePath: path.join(fPath, engine) - } + }; }) ); - + /** * 1. Flatten all engines from inner recursions and current dir * 2. Filter the dirList for scoped packages @@ -92,12 +92,12 @@ function resolveEngines(dir) { .map(scope => walk(path.join(fPath, scope), e)) // 3 ); }; - + return walk(dir, []); } function findEngineModulesInDirectory(dir) { - const foundEngines = resolveEngines(dir) + const foundEngines = resolveEngines(dir); return foundEngines; } @@ -117,27 +117,23 @@ function findEngineModulesInDirectory(dir) { // methods and properites below should therefore be on its prototype. const PatternEngines = Object.create({ - + loadAllEngines: function (patternLabConfig) { var self = this; - + // Try to load engines! We scan for engines at each path specified above. This // function is kind of a big deal. enginesDirectories.forEach(function (engineDirectory) { const enginesInThisDir = findEngineModulesInDirectory(engineDirectory.path); - if (patternLabConfig.debug) { - console.log(chalk.bold(`Loading engines from ${engineDirectory.displayName}...\n`)); - } - + + logger.debug(`Loading engines from ${engineDirectory.displayName}...`); + // find all engine-named things in this directory and try to load them, // unless it's already been loaded. enginesInThisDir.forEach(function (engineDiscovery) { let errorMessage; const successMessage = "good to go"; - if (patternLabConfig.debug) { - chalk.green(successMessage); - } - + try { // Give it a try! load 'er up. But not if we already have, // of course. Also pass the pattern lab config object into @@ -157,23 +153,18 @@ const PatternEngines = Object.create({ errorMessage = err.message; } finally { // report on the status of the engine, one way or another! - if (patternLabConfig.debug) { - console.log(` ${engineDiscovery.name}:`, errorMessage ? chalk.red(errorMessage) : successMessage); - } + logger.info(`Pattern Engine ${engineDiscovery.name}: ${errorMessage ? errorMessage : successMessage}`); } }); - console.log(''); }); - + // Complain if for some reason we haven't loaded any engines. if (Object.keys(self).length === 0) { - throw new Error('No engines loaded! Something is seriously wrong.'); - } - if (patternLabConfig.debug) { - console.log(chalk.bold('Done loading engines.\n')); + logger.error('No engines loaded! Something is seriously wrong.'); } + logger.debug(`Done loading engines`); }, - + getEngineNameForPattern: function (pattern) { // avoid circular dependency by putting this in here. TODO: is this slow? const of = require('./object_factory'); @@ -182,7 +173,7 @@ const PatternEngines = Object.create({ const engineNames = Object.keys(this); for (let i = 0; i < engineNames.length; i++) { const engine = this[engineNames[i]]; - + if (Array.isArray(engine.engineFileExtension)) { if (engine.engineFileExtension.includes(pattern.fileExtension)) { return engine.engineName; @@ -195,12 +186,12 @@ const PatternEngines = Object.create({ } } } - + // otherwise, assume it's a plain mustache template string and act // accordingly return 'mustache'; }, - + getEngineForPattern: function (pattern) { if (pattern.isPseudoPattern) { return this.getEngineForPattern(pattern.basePattern); @@ -209,7 +200,7 @@ const PatternEngines = Object.create({ return this[engineName]; } }, - + // combine all found engines into a single array of supported extensions getSupportedFileExtensions: function () { const engineNames = Object.keys(PatternEngines); @@ -218,19 +209,19 @@ const PatternEngines = Object.create({ }); return [].concat.apply([], allEnginesExtensions); }, - + isFileExtensionSupported: function (fileExtension) { const supportedExtensions = PatternEngines.getSupportedFileExtensions(); return (supportedExtensions.lastIndexOf(fileExtension) !== -1); }, - + // given a filename, return a boolean: whether or not the filename indicates // that the file is pseudopattern JSON isPseudoPatternJSON: function (filename) { const extension = path.extname(filename); return (extension === '.json' && filename.indexOf('~') > -1); }, - + // takes a filename string, not a full path; a basename (plus extension) // ignore _underscored patterns, dotfiles, and anything not recognized by a // loaded pattern engine. Pseudo-pattern .json files ARE considered to be @@ -242,7 +233,7 @@ const PatternEngines = Object.create({ (extension === '.json' && !PatternEngines.isPseudoPatternJSON(filename))) { return false; } - + // not a hidden pattern, let's dig deeper const supportedPatternFileExtensions = PatternEngines.getSupportedFileExtensions(); return (supportedPatternFileExtensions.lastIndexOf(extension) !== -1 || diff --git a/core/lib/patternlab.js b/core/lib/patternlab.js index 3240ba908..55ecbb78a 100644 --- a/core/lib/patternlab.js +++ b/core/lib/patternlab.js @@ -14,13 +14,12 @@ const diveSync = require('diveSync'); const dive = require('dive'); const _ = require('lodash'); const path = require('path'); -const chalk = require('chalk'); const cleanHtml = require('js-beautify').html; const inherits = require('util').inherits; const pm = require('./plugin_manager'); const packageInfo = require('../../package.json'); const dataLoader = require('./data_loader')(); -const plutils = require('./utilities'); +const logger = require('./log'); const jsonCopy = require('./json_copy'); const PatternGraph = require('./pattern_graph').PatternGraph; const pa = require('./pattern_assembler'); @@ -41,19 +40,24 @@ let serve = require('./serve'); // eslint-disable-line const pattern_assembler = new pa(); const lineage_hunter = new lh(); -//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)); - const patternEngines = require('./pattern_engines'); const EventEmitter = require('events').EventEmitter; +function PatternLabEventEmitter() { + EventEmitter.call(this); +} +inherits(PatternLabEventEmitter, EventEmitter); + class PatternLab { constructor(config) { // Either use the config we were passed, or load one up from the config file ourselves this.config = config || fs.readJSONSync(path.resolve(__dirname, '../../patternlab-config.json')); + + //register our log events + this.registerLogger(config.logLevel); + + logger.info(`Pattern Lab Node v${packageInfo.version}`); + // Load up engines please this.engines = patternEngines; this.engines.loadAllEngines(config); @@ -71,10 +75,70 @@ class PatternLab { this.watchers = {}; // Verify correctness of configuration (?) - checkConfiguration(this); + this.checkConfiguration(this); // TODO: determine if this is the best place to wire up plugins - initializePlugins(this); + this.initializePlugins(this); + } + + checkConfiguration(patternlab) { + + //default the output suffixes if not present + const outputFileSuffixes = { + rendered: '.rendered', + rawTemplate: '', + markupOnly: '.markup-only' + }; + + if (!patternlab.config.outputFileSuffixes) { + logger.warning(''); + logger.warning('Configuration key [outputFileSuffixes] not found, and defaulted to the following:'); + logger.info(outputFileSuffixes); + 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.'); + logger.warning(''); + } + patternlab.config.outputFileSuffixes = _.extend(outputFileSuffixes, patternlab.config.outputFileSuffixes); + + if (typeof patternlab.config.paths.source.patternlabFiles === 'string') { + logger.warning(''); + logger.warning(`Configuration key [paths.source.patternlabFiles] inside patternlab-config.json was found as the string '${patternlab.config.paths.source.patternlabFiles}'`); + 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.'); + logger.warning(''); + } + + if (typeof patternlab.config.debug === 'boolean') { + logger.warning(''); + logger.warning(`Configuration key [debug] inside patternlab-config.json was found. As of Pattern Lab Node Core 3.0.0 this key is replaced with a new key, [logLevel]. This is a string with possible values ['debug', 'info', 'warning', 'error', 'quiet'].`); + logger.warning(`Turning on 'info', 'warning', and 'error' levels by default, unless [logLevel] is present. If that is the case, [debug] has no effect.`); + logger.warning(''); + } + } + + /** + * Finds and calls the main method of any found plugins. + * @param patternlab - global data store + */ + //todo, move this to plugin_manager + initializePlugins(patternlab) { + + if (!patternlab.config.plugins) { return; } + + const plugin_manager = new pm(patternlab.config, path.resolve(__dirname, '../../patternlab-config.json')); + const foundPlugins = plugin_manager.detect_plugins(); + + if (foundPlugins && foundPlugins.length > 0) { + + for (let i = 0; i < foundPlugins.length; i++) { + + const pluginKey = foundPlugins[i]; + + logger.info(`Found plugin: ${pluginKey}`); + logger.info(`Attempting to load and initialize plugin.`); + + const plugin = plugin_manager.load_plugin(pluginKey); + plugin(patternlab); + } + } } buildGlobalData() { @@ -86,18 +150,20 @@ class PatternLab { // data.json try { - this.data = buildPatternData(paths.source.data, fs); + this.data = buildPatternData(paths.source.data, fs); // eslint-disable-line no-use-before-define } catch (ex) { - plutils.error('missing or malformed' + paths.source.data + 'data.json Pattern Lab may not work without this file.'); + logger.error('missing or malformed' + paths.source.data + 'data.json Pattern Lab may not work without this file.'); this.data = {}; } + // listitems.json try { this.listitems = fs.readJSONSync(path.resolve(paths.source.data, 'listitems.json')); } catch (ex) { - plutils.warning('WARNING: missing or malformed ' + paths.source.data + 'listitems.json file. Pattern Lab may not work without this file.'); + logger.warning('WARNING: missing or malformed ' + paths.source.data + 'listitems.json file. Pattern Lab may not work without this file.'); this.listitems = {}; } + // load up all the necessary files from pattern lab that apply to every template try { this.header = fs.readFileSync(path.resolve(paths.source.patternlabFiles['general-header']), 'utf8'); @@ -106,8 +172,8 @@ class PatternLab { this.patternSectionSubType = fs.readFileSync(path.resolve(paths.source.patternlabFiles.patternSectionSubtype), 'utf8'); this.viewAll = fs.readFileSync(path.resolve(paths.source.patternlabFiles.viewall), 'utf8'); } catch (ex) { - console.log(ex); - plutils.error('\nERROR: missing an essential file from ' + paths.source.patternlabFiles + '. Pattern Lab won\'t work without this file.\n'); + logger.info(ex); + logger.error('\nERROR: missing an essential file from ' + paths.source.patternlabFiles + '. Pattern Lab won\'t work without this file.\n'); // GTP: it seems increasingly naughty as we refactor to just unilaterally do this here, // but whatever. For now. @@ -132,9 +198,7 @@ class PatternLab { setCacheBust() { if (this.config.cacheBust) { - if (this.config.debug) { - console.log('setting cacheBuster value for frontend assets.'); - } + logger.debug('setting cacheBuster value for frontend assets.'); this.cacheBuster = new Date().getTime(); } else { this.cacheBuster = 0; @@ -171,8 +235,8 @@ class PatternLab { this.userHead = headPattern.extendedTemplate; } catch (ex) { - 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'); - if (this.config.debug) { console.log(ex); } + logger.warning(`Could not find the user-editable header template, currently configured to be at ${path.join(this.config.paths.source.meta, '_00-head.ext')}. 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.`); + logger.warning(ex); // GTP: it seems increasingly naughty as we refactor to just unilaterally do this here, // but whatever. For now. @@ -194,8 +258,8 @@ class PatternLab { this.userFoot = footPattern.extendedTemplate; } catch (ex) { - 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'); - if (this.config.debug) { console.log(ex); } + logger.error(`Could not find the user-editable footer template, currently configured to be at ${path.join(this.config.paths.source.meta, '_01-foot.ext')}. 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.`); + logger.warning(ex); // GTP: it seems increasingly naughty as we refactor to just unilaterally do this here, // but whatever. For now. @@ -210,7 +274,7 @@ class PatternLab { return this.package.version; } logVersion() { - console.log(this.package.version); + logger.info(this.package.version); } getSupportedTemplateExtensions() { return this.engines.getSupportedFileExtensions(); @@ -247,6 +311,32 @@ class PatternLab { //write the compiled template to the public patterns directory outputFiles.forEach(outFile => fs.outputFileSync(outFile.path, outFile.content)); } + + /** + * Binds console logging to different levels + * + * @param {string} logLevel + * @memberof PatternLab + */ + registerLogger(logLevel) { + if (logLevel === undefined) { + logger.log.on('info', msg => console.info(msg)); + logger.log.on('warning', msg => console.info(msg)); + logger.log.on('error', msg => console.info(msg)); + } else { + if (logLevel === 'quiet') { return; } + switch (logLevel) { + case 'debug': + logger.log.on('debug', msg => console.info(msg)); + case 'info': + logger.log.on('info', msg => console.info(msg)); + case 'warning': + logger.log.on('warning', msg => console.info(msg)); + case 'error': + logger.log.on('error', msg => console.info(msg)); + } + } + } } //bootstrap update notifier @@ -275,7 +365,7 @@ function processAllPatternsIterative(patterns_dir, patternlab) { (err, file) => { //log any errors if (err) { - console.log('error in processAllPatternsIterative():', err); + logger.info('error in processAllPatternsIterative():', err); return; } @@ -311,7 +401,7 @@ function processAllPatternsRecursive(patterns_dir, patternlab) { function (err, file) { //log any errors if (err) { - console.log(err); + logger.info(err); return; } pattern_assembler.process_pattern_recursive(path.relative(patterns_dir, file), patternlab); @@ -319,59 +409,6 @@ function processAllPatternsRecursive(patterns_dir, patternlab) { ); } -function checkConfiguration(patternlab) { - //default the output suffixes if not present - const outputFileSuffixes = { - rendered: '.rendered', - rawTemplate: '', - markupOnly: '.markup-only' - }; - - if (!patternlab.config.outputFileSuffixes) { - plutils.warning('Configuration Object "outputFileSuffixes" not found, and defaulted to the following:'); - console.log(outputFileSuffixes); - 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.'); - console.log(); - } - patternlab.config.outputFileSuffixes = _.extend(outputFileSuffixes, patternlab.config.outputFileSuffixes); - - if (typeof patternlab.config.paths.source.patternlabFiles === 'string') { - plutils.warning(`Configuration key [paths.source.patternlabFiles] inside patternlab-config.json was found as the string '${patternlab.config.paths.source.patternlabFiles}'`); - 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.'); - } - -} - -/** - * Finds and calls the main method of any found plugins. - * @param patternlab - global data store - */ - -//todo, move this to plugin_manager -function initializePlugins(patternlab) { - - if (!patternlab.config.plugins) { return; } - - const plugin_manager = new pm(patternlab.config, path.resolve(__dirname, '../../patternlab-config.json')); - const foundPlugins = plugin_manager.detect_plugins(); - - if (foundPlugins && foundPlugins.length > 0) { - - for (let i = 0; i < foundPlugins.length; i++) { - - const pluginKey = foundPlugins[i]; - - if (patternlab.config.debug) { - console.log('Found plugin: ', pluginKey); - console.log('Attempting to load and initialize plugin.'); - } - - const plugin = plugin_manager.load_plugin(pluginKey); - plugin(patternlab); - } - } -} - /** * Installs a given plugin. Assumes it has already been pulled down via npm * @param pluginName - the name of the plugin @@ -385,92 +422,64 @@ function installPlugin(pluginName) { plugin_manager.install_plugin(pluginName); } -function PatternLabEventEmitter() { - EventEmitter.call(this); -} -inherits(PatternLabEventEmitter, EventEmitter); - const patternlab_engine = function (config) { const patternlab = new PatternLab(config); const paths = patternlab.config.paths; function help() { - console.log(''); - - console.log('|=======================================|'); - 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.debug(' patternlab:build'); - console.log(' > Compiles the patterns and frontend, outputting to config.paths.public'); - console.log(''); - - plutils.debug(' patternlab:patternsonly'); - console.log(' > Compiles the patterns only, outputting to config.paths.public'); - console.log(''); - - plutils.debug(' patternlab:version'); - console.log(' > Return the version of patternlab-node you have installed'); - console.log(''); - - plutils.debug(' patternlab:help'); - console.log(' > Get more information about patternlab-node, pattern lab in general, and where to report issues.'); - console.log(''); - - 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.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.'); - console.log(' > arguments:'); - console.log(' -- kit '); - console.log(' > the name of the starter kit to load'); - console.log(' -- clean '); - console.log(' > removes all files from config.paths.source/ prior to load'); - console.log(' > example (gulp):'); - console.log(' `gulp patternlab:loadstarterkit --kit=starterkit-mustache-demo`'); - console.log(''); - - console.log('==============================='); - console.log(''); - console.log('Visit http://patternlab.io/ for more info about Pattern Lab'); - console.log('Visit https://github.com/pattern-lab/patternlab-node/issues to open an issue.'); - console.log('Visit https://github.com/pattern-lab/patternlab-node/wiki to view the changelog, roadmap, and other info.'); - console.log(''); - console.log('==============================='); + logger.info(''); + + logger.info('|=======================================|'); + logger.debug(' Pattern Lab Node Help v' + patternlab.package.version); + logger.info('|=======================================|'); + + logger.info(''); + logger.info('API - usually consumed by an edition'); + logger.info(''); + + logger.debug(' patternlab:build'); + logger.info(' > Compiles the patterns and frontend, outputting to config.paths.public'); + logger.info(''); + + logger.debug(' patternlab:patternsonly'); + logger.info(' > Compiles the patterns only, outputting to config.paths.public'); + logger.info(''); + + logger.debug(' patternlab:version'); + logger.info(' > Return the version of patternlab-node you have installed'); + logger.info(''); + + logger.debug(' patternlab:help'); + logger.info(' > Get more information about patternlab-node, pattern lab in general, and where to report issues.'); + logger.info(''); + + logger.debug(' patternlab:liststarterkits'); + logger.info(' > Returns a url with the list of available starterkits hosted on the Pattern Lab organization Github account'); + logger.info(''); + + logger.debug(' patternlab:loadstarterkit'); + logger.info(' > Load a starterkit into config.paths.source/*'); + logger.info(' > NOTE: Overwrites existing content, and only cleans out existing directory if --clean=true argument is passed.'); + logger.info(' > NOTE: In most cases, `npm install starterkit-name` will precede this call.'); + logger.info(' > arguments:'); + logger.info(' -- kit '); + logger.info(' > the name of the starter kit to load'); + logger.info(' -- clean '); + logger.info(' > removes all files from config.paths.source/ prior to load'); + logger.info(' > example (gulp):'); + logger.info(' `gulp patternlab:loadstarterkit --kit=starterkit-mustache-demo`'); + logger.info(''); + + logger.info('==============================='); + logger.info(''); + logger.info('Visit http://patternlab.io/ for more info about Pattern Lab'); + logger.info('Visit https://github.com/pattern-lab/patternlab-node/issues to open an issue.'); + logger.info('Visit https://github.com/pattern-lab/patternlab-node/wiki to view the changelog, roadmap, and other info.'); + logger.info(''); + logger.info('==============================='); } - function printDebug() { - // A replacer function to pass to stringify below; this is here to prevent - // the debug output from blowing up into a massive fireball of circular - // references. This happens specifically with the Handlebars engine. Remove - // if you like 180MB log files. - function propertyStringReplacer(key, value) { - if (key === 'engine' && value && value.engineName) { - return '{' + value.engineName + ' engine object}'; - } - return value; - } - - // GTP: this commented out now on the advice of Brian, because we think nobody looks at it, - // and it causes problems. - //debug file can be written by setting flag on patternlab-config.json - // if (patternlab.config.debug) { - // console.log('writing patternlab debug file to ./patternlab.json'); - // fs.outputFileSync('./patternlab.json', JSON.stringify(patternlab, propertyStringReplacer, 3)); - // } - } - - - function renderSinglePattern(pattern, head) { // Pattern does not need to be built and recompiled more than once if (!pattern.isPattern || pattern.compileState === CompileState.CLEAN) { @@ -494,8 +503,8 @@ const patternlab_engine = function (config) { try { allData = jsonCopy(patternlab.data, 'config.paths.source.data global data'); } catch (err) { - console.log('There was an error parsing JSON for ' + pattern.relPath); - console.log(err); + logger.info('There was an error parsing JSON for ' + pattern.relPath); + logger.info(err); } allData = _.merge(allData, pattern.jsonFileData); allData.cacheBuster = patternlab.cacheBuster; @@ -552,8 +561,8 @@ const patternlab_engine = function (config) { try { allFooterData = jsonCopy(patternlab.data, 'config.paths.source.data global data'); } catch (err) { - console.log('There was an error parsing JSON for ' + pattern.relPath); - console.log(err); + logger.info('There was an error parsing JSON for ' + pattern.relPath); + logger.info(err); } allFooterData = _.merge(allFooterData, pattern.jsonFileData); allFooterData.patternLabFoot = footerPartial; @@ -569,7 +578,7 @@ const patternlab_engine = function (config) { // Allows serializing the compile state patternlab.graph.node(pattern).compileState = pattern.compileState = CompileState.CLEAN; - plutils.log.info("Built pattern: " + pattern.patternPartial); + logger.info("Built pattern: " + pattern.patternPartial); return Promise.resolve(true); } @@ -595,7 +604,7 @@ const patternlab_engine = function (config) { function cleanBuildDirectory(incrementalBuildsEnabled) { if (incrementalBuildsEnabled) { - plutils.log.info("Incremental builds enabled."); + logger.log.info("Incremental builds enabled."); } else { // needs to be done BEFORE processing patterns fs.removeSync(paths.public.patterns); @@ -606,26 +615,19 @@ const patternlab_engine = function (config) { function buildPatterns(deletePatternDir) { patternlab.events.emit('patternlab-build-pattern-start', patternlab); - if (patternlab.config.debug) { - console.log( - chalk.bold('\n====[ Pattern Lab / Node'), - `- v${packageInfo.version}`, - chalk.bold(']====\n') - ); - } - // // CHECK INCREMENTAL BUILD GRAPH // const graph = patternlab.graph = loadPatternGraph(deletePatternDir); const graphNeedsUpgrade = !PatternGraph.checkVersion(graph); if (graphNeedsUpgrade) { - plutils.log.info("Due to an upgrade, a complete rebuild is required and the public/patterns directory was deleted. " + + logger.log.info("Due to an upgrade, a complete rebuild is required and the public/patterns directory was deleted. " + "Incremental build is available again on the next successful run."); // Ensure that the freshly built graph has the latest version again. patternlab.graph.upgradeVersion(); } + // Flags patternlab.incrementalBuildsEnabled = !(deletePatternDir || graphNeedsUpgrade); @@ -683,7 +685,7 @@ const patternlab_engine = function (config) { // When the graph was loaded from file, some patterns might have been moved/deleted between runs // so the graph data become out of sync patternlab.graph.sync().forEach(n => { - plutils.log.info("[Deleted/Moved] " + n); + logger.log.info("[Deleted/Moved] " + n); }); // TODO Find created or deleted files @@ -708,14 +710,14 @@ const patternlab_engine = function (config) { PatternGraph.storeToFile(patternlab); if (patternlab.config.exportToGraphViz) { PatternGraph.exportToDot(patternlab, "dependencyGraph.dot"); - plutils.log.info(`Exported pattern graph to ${path.join(config.paths.public.root, "dependencyGraph.dot")}`); + logger.log.info(`Exported pattern graph to ${path.join(config.paths.public.root, "dependencyGraph.dot")}`); } //export patterns if necessary pattern_exporter.export_patterns(patternlab); }); }).catch((err) => { - console.log('Error in buildPatterns():', err); + logger.info('Error in buildPatterns():', err); }); } @@ -747,7 +749,7 @@ const patternlab_engine = function (config) { */ build: function (callback, options) { if (patternlab && patternlab.isBusy) { - console.log('Pattern Lab is busy building a previous run - returning early.'); + logger.info('Pattern Lab is busy building a previous run - returning early.'); return Promise.resolve(); } patternlab.isBusy = true; @@ -772,7 +774,6 @@ const patternlab_engine = function (config) { return Promise.resolve(); }); - printDebug(); patternlab.isBusy = false; callback(); }); @@ -796,12 +797,11 @@ const patternlab_engine = function (config) { */ patternsonly: function (callback, options) { if (patternlab && patternlab.isBusy) { - console.log('Pattern Lab is busy building a previous run - returning early.'); + logger.info('Pattern Lab is busy building a previous run - returning early.'); return Promise.resolve(); } patternlab.isBusy = true; return buildPatterns(options.cleanPublic).then(() => { - printDebug(); patternlab.isBusy = false; callback(); }); diff --git a/core/lib/plugin_manager.js b/core/lib/plugin_manager.js index e636dd4a5..6aa92c9dc 100644 --- a/core/lib/plugin_manager.js +++ b/core/lib/plugin_manager.js @@ -3,7 +3,7 @@ const plugin_manager = function (config, configPath) { const path = require('path'); const fs = require('fs-extra'); - const util = require('./utilities'); + const logger = require('./log'); /** * Loads a plugin @@ -25,12 +25,12 @@ const plugin_manager = function (config, configPath) { const pluginPath = path.resolve( path.join(process.cwd(), 'node_modules', pluginName) ); - console.log('Attempting to load plugin from', pluginPath); + logger.debug(`Attempting to load plugin from ${pluginPath}`); try { var pluginDirStats = fs.statSync(pluginPath); } catch (ex) { - util.error(pluginName + ' not found, please use npm to install it first.'); - util.error(pluginName + ' not loaded.'); + logger.warning(`${pluginName} not found, use npm to install it first.`); + logger.warning(`${pluginName} not loaded.`); return; } const pluginPathDirExists = pluginDirStats.isDirectory(); @@ -63,13 +63,12 @@ const plugin_manager = function (config, configPath) { //write config entry back fs.outputFileSync(path.resolve(configPath), JSON.stringify(diskConfig, null, 2)); - util.debug('Plugin ' + pluginName + ' installed.'); - - //todo, tell them how to uninstall or disable - + logger.info('Plugin ' + pluginName + ' installed.'); + logger.info('Plugin configration added to patternlab-config.json.'); } } catch (ex) { - console.log(ex); + logger.warning(`An error occurred during plugin installation for plugin ${pluginName}`); + logger.warning(ex); } } @@ -91,7 +90,7 @@ const plugin_manager = function (config, configPath) { * Not implemented yet */ function disablePlugin(pluginName) { - console.log('disablePlugin not implemented yet. No change made to state of plugin', pluginName); + logger.warning(`disablePlugin() not implemented yet. No change made to state of plugin ${pluginName}`); } /** @@ -99,7 +98,7 @@ const plugin_manager = function (config, configPath) { * Not implemented yet */ function enablePlugin(pluginName) { - console.log('enablePlugin not implemented yet. No change made to state of plugin', pluginName); + logger.warning(`enablePlugin() not implemented yet. No change made to state of plugin ${pluginName}`); } return { diff --git a/core/lib/pseudopattern_hunter.js b/core/lib/pseudopattern_hunter.js index debae2d8c..c5cb25bb8 100644 --- a/core/lib/pseudopattern_hunter.js +++ b/core/lib/pseudopattern_hunter.js @@ -7,6 +7,7 @@ const _ = require('lodash'); const lh = require('./lineage_hunter'); const Pattern = require('./object_factory').Pattern; const path = require('path'); +const logger = require('./log'); const lineage_hunter = new lh(); const changes_hunter = new ch(); @@ -29,17 +30,15 @@ pseudopattern_hunter.prototype.find_pseudopatterns = function (currentPattern, p if (pseudoPatterns.length > 0) { for (let i = 0; i < pseudoPatterns.length; i++) { - if (patternlab.config.debug) { - console.log('found pseudoPattern variant of ' + currentPattern.patternPartial); - } + logger.debug(`Found pseudoPattern variant of ${currentPattern.patternPartial}`); //we want to do everything we normally would here, except instead read the pseudoPattern data try { var variantFileFullPath = path.resolve(paths.source.patterns, pseudoPatterns[i]); var variantFileData = fs.readJSONSync(variantFileFullPath); } catch (err) { - console.log('There was an error parsing pseudopattern JSON for ' + currentPattern.relPath); - console.log(err); + logger.warning(`There was an error parsing pseudopattern JSON for ${currentPattern.relPath}`); + logger.warning(err); } //extend any existing data with variant data @@ -84,8 +83,8 @@ pseudopattern_hunter.prototype.find_pseudopatterns = function (currentPattern, p var variantFileFullPath = path.resolve(paths.source.patterns, pseudoPatterns[i]); var variantFileData = fs.readJSONSync(variantFileFullPath); } catch (err) { - console.log('There was an error parsing pseudopattern JSON for ' + currentPattern.relPath); - console.log(err); + logger.warning(`There was an error parsing pseudopattern JSON for ${currentPattern.relPath}`); + logger.warning(err); } //extend any existing data with variant data diff --git a/core/lib/serve.js b/core/lib/serve.js index a773acde9..3b1b42074 100644 --- a/core/lib/serve.js +++ b/core/lib/serve.js @@ -1,6 +1,7 @@ "use strict"; const path = require('path'); -const liveServer = require('live-server'); +const liveServer = require('@pattern-lab/live-server'); +const logger = require('./log'); const serve = (patternlab) => { @@ -11,7 +12,8 @@ const serve = (patternlab) => { ignore: path.join(path.resolve(patternlab.config.paths.public.root)), file: 'index.html', logLevel: 0, // errors only - wait: 1000 + wait: 1000, + port: 3000 }; // allow for overrides should they exist inside patternlab-config.json @@ -34,6 +36,8 @@ const serve = (patternlab) => { //start! liveServer.start(liveServerConfig); + logger.info(`Pattern Lab is being served from http://127.0.0.1:${liveServerConfig.port}`); + }; module.exports = serve; diff --git a/core/lib/starterkit_manager.js b/core/lib/starterkit_manager.js index 2498580b9..b6535572d 100644 --- a/core/lib/starterkit_manager.js +++ b/core/lib/starterkit_manager.js @@ -4,7 +4,7 @@ const starterkit_manager = function (config) { const path = require('path'); const fetch = require('node-fetch'); const fs = require('fs-extra'); - const util = require('./utilities'); + const logger = require('./log'); const paths = config.paths; /** @@ -18,34 +18,35 @@ const starterkit_manager = function (config) { const kitPath = path.resolve( path.join(process.cwd(), 'node_modules', starterkitName, config.starterkitSubDir) ); - console.log('Attempting to load starterkit from', kitPath); + logger.debug('Attempting to load starterkit from', kitPath); try { var kitDirStats = fs.statSync(kitPath); } catch (ex) { - util.error(starterkitName + ' not found, please use npm to install it first.'); - util.error(starterkitName + ' not loaded.'); + logger.warning(`${starterkitName} not found, use npm to install it first.`); + logger.warning(`${starterkitName} not loaded.`); return; } const kitPathDirExists = kitDirStats.isDirectory(); if (kitPathDirExists) { if (clean) { - console.log('Deleting contents of', paths.source.root, 'prior to starterkit load.'); + logger.info(`Deleting contents of ${paths.source.root} prior to starterkit load.`); fs.emptyDirSync(paths.source.root); } else { - console.log('Overwriting contents of', paths.source.root, 'during starterkit load.'); + logger.info(`Overwriting contents of ${paths.source.root} during starterkit load.`); } try { fs.copySync(kitPath, paths.source.root); } catch (ex) { - util.error(ex); + logger.error(ex); return; } - util.debug('starterkit ' + starterkitName + ' loaded successfully.'); + logger.info('Starterkit ' + starterkitName + ' loaded into source/.'); } } catch (ex) { - console.log(ex); + logger.warning(`An error occurred during starterkit installation for starterkit ${starterkitName}`); + logger.warning(ex); } } @@ -75,7 +76,7 @@ const starterkit_manager = function (config) { return {name: repo.name, url: repo.html_url}; }); }).catch(function (err) { - console.error(err); + logger.error(err); return false; }); } diff --git a/core/lib/style_modifier_hunter.js b/core/lib/style_modifier_hunter.js index af50fb155..c58f9e37a 100644 --- a/core/lib/style_modifier_hunter.js +++ b/core/lib/style_modifier_hunter.js @@ -1,5 +1,7 @@ "use strict"; +const logger = require('./log'); + const style_modifier_hunter = function () { /** @@ -17,9 +19,7 @@ const style_modifier_hunter = function () { //replace the special character pipe | used to separate multiple classes with a space styleModifier = styleModifier.replace(/\|/g, ' '); - if (patternlab.config.debug) { - console.log('found partial styleModifier within pattern ' + pattern.patternPartial); - } + logger.debug(`Found partial styleModifier within pattern ${pattern.patternPartial}`); //replace the stylemodifier placeholder with the class name pattern.extendedTemplate = pattern.extendedTemplate.replace(/{{[ ]?styleModifier[ ]?}}/i, styleModifier); diff --git a/core/lib/ui_builder.js b/core/lib/ui_builder.js index 6c2807467..8bb287775 100644 --- a/core/lib/ui_builder.js +++ b/core/lib/ui_builder.js @@ -5,7 +5,7 @@ const jsonCopy = require('./json_copy'); const ae = require('./annotation_exporter'); const of = require('./object_factory'); const Pattern = of.Pattern; -const plutils = require('./utilities'); +const logger = require('./log'); const eol = require('os').EOL; const _ = require('lodash'); @@ -67,18 +67,14 @@ const ui_builder = function () { // skip underscore-prefixed files isOmitted = pattern.isPattern && pattern.fileName.charAt(0) === '_'; if (isOmitted) { - if (patternlab.config.debug) { - console.log('Omitting ' + pattern.patternPartial + " from styleguide patterns because it has an underscore suffix."); - } + logger.debug(`Omitting ${pattern.patternPartial} from styleguide patterns because it has an underscore suffix.`); return true; } //this is meant to be a homepage that is not present anywhere else isOmitted = pattern.patternPartial === patternlab.config.defaultPattern; if (isOmitted) { - if (patternlab.config.debug) { - console.log('Omitting ' + pattern.patternPartial + ' from styleguide patterns because it is defined as a defaultPattern.'); - } + logger.debug(`Omitting ${pattern.patternPartial} from styleguide patterns because it is defined as a defaultPattern.`); patternlab.defaultPattern = pattern; return true; } @@ -86,18 +82,14 @@ const ui_builder = function () { //this pattern is contained with a directory prefixed with an underscore (a handy way to hide whole directories from the nav isOmitted = pattern.relPath.charAt(0) === '_' || pattern.relPath.indexOf(path.sep + '_') > -1; if (isOmitted) { - if (patternlab.config.debug) { - console.log('Omitting ' + pattern.patternPartial + ' from styleguide patterns because its contained within an underscored directory.'); - } + logger.debug(`Omitting ${pattern.patternPartial} from styleguide patterns because its contained within an underscored directory.`); return true; } //this pattern is a head or foot pattern isOmitted = pattern.isMetaPattern; if (isOmitted) { - if (patternlab.config.debug) { - console.log('Omitting ' + pattern.patternPartial + ' from styleguide patterns because its a meta pattern.'); - } + logger.debug(`Omitting ${pattern.patternPartial} from styleguide patterns because its a meta pattern.`); return true; } @@ -169,9 +161,7 @@ const ui_builder = function () { const patternType = _.find(patternlab.patternTypes, ['patternType', pattern.patternType]); if (!patternType) { - plutils.error('Could not find patternType' + pattern.patternType + '. This is a critical error.'); - console.trace(); - process.exit(1); + logger.error(`Could not find patternType ${pattern.patternType}. This is a critical error.`); } return patternType; @@ -188,9 +178,7 @@ const ui_builder = function () { const patternSubType = _.find(patternType.patternTypeItems, ['patternSubtype', pattern.patternSubType]); if (!patternSubType) { - plutils.error('Could not find patternType ' + pattern.patternType + '-' + pattern.patternType + '. This is a critical error.'); - console.trace(); - process.exit(1); + logger.error(`Could not find patternType ${pattern.patternType}-${pattern.patternType}. This is a critical error.`); } return patternSubType; @@ -276,9 +264,7 @@ const ui_builder = function () { function addPatternItem(patternlab, pattern, isViewAllVariant) { const patternType = getPatternType(patternlab, pattern); if (!patternType) { - plutils.error('Could not find patternType' + pattern.patternType + '. This is a critical error.'); - console.trace(); - process.exit(1); + logger.error(`Could not find patternType ${pattern.patternType}. This is a critical error.`); } if (!patternType.patternItems) { @@ -439,8 +425,8 @@ const ui_builder = function () { try { allFooterData = jsonCopy(patternlab.data, 'config.paths.source.data plus patterns data'); } catch (err) { - console.log('There was an error parsing JSON for patternlab.data'); - console.log(err); + logger.warning('There was an error parsing JSON for patternlab.data'); + logger.warning(err); } allFooterData.patternLabFoot = footerPartial; @@ -517,9 +503,7 @@ const ui_builder = function () { return exclude === patternType + '/' + patternSubtype; }); if (omitPatternType) { - if (patternlab.config.debug) { - console.log('Omitting ' + patternType + '/' + patternSubtype + ' from building a viewall page because its patternSubGroup is specified in styleguideExcludes.'); - } + logger.debug(`Omitting ${patternType}/${patternSubtype} from building a viewall page because its patternSubGroup is specified in styleguideExcludes.`); } else { styleguideTypePatterns = styleguideTypePatterns.concat(subtypePatterns); } @@ -556,9 +540,7 @@ const ui_builder = function () { return exclude === patternType; }); if (omitPatternType) { - if (patternlab.config.debug) { - console.log('Omitting ' + patternType + ' from building a viewall page because its patternGroup is specified in styleguideExcludes.'); - } + logger.debug(`Omitting ${patternType} from building a viewall page because its patternGroup is specified in styleguideExcludes.`); } else { patterns = patterns.concat(styleguideTypePatterns); } @@ -671,10 +653,8 @@ const ui_builder = function () { let patternlabSiteHtml; try { patternlabSiteHtml = fs.readFileSync(path.resolve(paths.source.styleguide, 'index.html'), 'utf8'); - } catch (error) { - console.log(error); - console.log("\nERROR: Could not load one or more styleguidekit assets from", paths.source.styleguide, '\n'); - process.exit(1); + } catch (err) { + logger.error(`Could not load one or more styleguidekit assets from ${paths.source.styleguide}`); } fs.outputFileSync(path.resolve(paths.public.root, 'index.html'), patternlabSiteHtml); diff --git a/package-lock.json b/package-lock.json index 80de22468..345c3c3c3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,6 +4,33 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@pattern-lab/live-server": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/@pattern-lab/live-server/-/live-server-1.3.2.tgz", + "integrity": "sha512-Ka1e+1DclAZHGSFLcmj3+ZA7R1rXcHEzBf34kYi+x3Jtf6yaNZASIVfa8nxaru5/82EbjHKVNpYK4J+NmZakHw==", + "requires": { + "chokidar": "1.7.0", + "colors": "1.1.2", + "connect": "3.6.5", + "cors": "2.8.4", + "event-stream": "3.3.4", + "faye-websocket": "0.11.1", + "http-auth": "3.2.3", + "morgan": "1.9.0", + "object-assign": "4.1.1", + "opn": "5.1.0", + "proxy-middleware": "0.15.0", + "send": "0.16.1", + "serve-index": "1.9.1" + }, + "dependencies": { + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" + } + } + }, "accepts": { "version": "1.3.4", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.4.tgz", @@ -229,14 +256,14 @@ "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" }, "connect": { - "version": "3.5.1", - "resolved": "https://registry.npmjs.org/connect/-/connect-3.5.1.tgz", - "integrity": "sha1-bTDXpjx/FwhXprOqazY9lz3KWI4=", + "version": "3.6.5", + "resolved": "https://registry.npmjs.org/connect/-/connect-3.6.5.tgz", + "integrity": "sha1-+43ee6B2OHfQ7J352sC0tA5yx9o=", "requires": { - "debug": "2.2.0", - "finalhandler": "0.5.1", + "debug": "2.6.9", + "finalhandler": "1.0.6", "parseurl": "1.3.2", - "utils-merge": "1.0.0" + "utils-merge": "1.0.1" } }, "core-util-is": { @@ -261,11 +288,11 @@ } }, "debug": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.2.0.tgz", - "integrity": "sha1-+HBX6ZWxofauaklgZkE3vFbwOdo=", + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", "requires": { - "ms": "0.7.1" + "ms": "2.0.0" } }, "del": { @@ -1418,13 +1445,15 @@ } }, "finalhandler": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-0.5.1.tgz", - "integrity": "sha1-LEANjUUwk1vCMlScX6OF7Afeb80=", + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.0.6.tgz", + "integrity": "sha1-AHrqM9Gk0+QgF/YkhIrVjSEvgU8=", "requires": { - "debug": "2.2.0", + "debug": "2.6.9", + "encodeurl": "1.0.1", "escape-html": "1.0.3", "on-finished": "2.3.0", + "parseurl": "1.3.2", "statuses": "1.3.1", "unpipe": "1.0.0" } @@ -1652,9 +1681,9 @@ } }, "http-auth": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/http-auth/-/http-auth-3.1.3.tgz", - "integrity": "sha1-lFz63WZSHq+PfISRPTd9exXyTjE=", + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/http-auth/-/http-auth-3.2.3.tgz", + "integrity": "sha1-Y2hCtx1uHyyY26Ca9UQXof74thw=", "requires": { "apache-crypt": "1.2.1", "apache-md5": "1.1.2", @@ -1898,31 +1927,6 @@ "graceful-fs": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz" } }, - "live-server": { - "version": "github:pattern-lab/live-server#5db065902f95266af29b7e80873c3a4dbdd4620d", - "requires": { - "chokidar": "1.7.0", - "colors": "1.1.2", - "connect": "3.5.1", - "cors": "2.8.4", - "event-stream": "3.3.4", - "faye-websocket": "0.11.1", - "http-auth": "3.1.3", - "morgan": "1.9.0", - "object-assign": "4.1.1", - "opn": "5.1.0", - "proxy-middleware": "0.15.0", - "send": "0.16.1", - "serve-index": "1.9.1" - }, - "dependencies": { - "object-assign": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" - } - } - }, "lodash": { "version": "4.13.1", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.13.1.tgz", @@ -2078,27 +2082,12 @@ "depd": "1.1.1", "on-finished": "2.3.0", "on-headers": "1.0.1" - }, - "dependencies": { - "debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "requires": { - "ms": "2.0.0" - } - }, - "ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" - } } }, "ms": { - "version": "0.7.1", - "resolved": "https://registry.npmjs.org/ms/-/ms-0.7.1.tgz", - "integrity": "sha1-nNE8A62/8ltl7/3nzoZO6VIBcJg=" + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" }, "mz": { "version": "2.7.0", @@ -2424,21 +2413,6 @@ "on-finished": "2.3.0", "range-parser": "1.2.0", "statuses": "1.3.1" - }, - "dependencies": { - "debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "requires": { - "ms": "2.0.0" - } - }, - "ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" - } } }, "serve-index": { @@ -2453,21 +2427,6 @@ "http-errors": "1.6.2", "mime-types": "2.1.17", "parseurl": "1.3.2" - }, - "dependencies": { - "debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "requires": { - "ms": "2.0.0" - } - }, - "ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" - } } }, "set-immediate-shim": { @@ -5331,9 +5290,9 @@ "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" }, "utils-merge": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.0.tgz", - "integrity": "sha1-ApT7kiu5N1FTVBxPcJYjHyh8ivg=" + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", + "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=" }, "uuid": { "version": "3.1.0", diff --git a/package.json b/package.json index fb21acda4..e4e94ac34 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "graphlib": "^2.1.1", "js-beautify": "^1.6.3", "js-yaml": "^3.6.1", - "live-server": "github:pattern-lab/live-server#semver:^1.0", + "@pattern-lab/live-server": "^1.3.2", "lodash": "~4.13.1", "markdown-it": "^6.0.1", "node-fetch": "^1.6.0", diff --git a/patternlab-config.json b/patternlab-config.json index dc3021cc6..e8ee94ee3 100644 --- a/patternlab-config.json +++ b/patternlab-config.json @@ -29,7 +29,7 @@ "defaultPattern": "all", "ignored-extensions" : ["scss", "DS_Store", "less"], "ignored-directories" : ["scss"], - "debug": false, + "logLevel": "info", "ishControlsHide": { "s": false, "m": false, diff --git a/test/asset_copy_tests.js b/test/asset_copy_tests.js index 9d2346912..d3865817b 100644 --- a/test/asset_copy_tests.js +++ b/test/asset_copy_tests.js @@ -38,7 +38,7 @@ function createFakePatternLab(customProps) { } }, styleGuideExcludes: [ ], - debug: false, + logLevel: 'quiet', outputFileSuffixes: { rendered: '.rendered', rawTemplate: '', diff --git a/test/lineage_hunter_tests.js b/test/lineage_hunter_tests.js index 58d7892c6..cf87a6b04 100644 --- a/test/lineage_hunter_tests.js +++ b/test/lineage_hunter_tests.js @@ -49,7 +49,7 @@ function createBasePatternLabObject() { }; pl.data = {}; pl.data.link = {}; - pl.config.debug = false; + pl.config.logLevel = 'quiet'; pl.patterns = []; pl.partials = {}; pl.patternGroups = {}; diff --git a/test/list_item_hunter_tests.js b/test/list_item_hunter_tests.js index ff7dae374..36eb16a0b 100644 --- a/test/list_item_hunter_tests.js +++ b/test/list_item_hunter_tests.js @@ -66,7 +66,7 @@ function createFakePatternLab(customProps) { "partials": [] }, "config": { - "debug": false, + "logLevel": 'quiet', "paths": { "source": { "patterns": "./test/files/_patterns" @@ -344,7 +344,7 @@ tap.test('process_list_item_partials - correctly ignores bookended partials with pl.config = {}; pl.data = {}; pl.data.link = {}; - pl.config.debug = false; + pl.config.logLevel = 'quiet'; pl.patterns = []; pl.partials = {}; pl.config.patterns = { source: patterns_dir }; diff --git a/test/parameter_hunter_tests.js b/test/parameter_hunter_tests.js index 05823fd30..40049a4a1 100644 --- a/test/parameter_hunter_tests.js +++ b/test/parameter_hunter_tests.js @@ -56,7 +56,7 @@ function patternlabClosure() { } ], config: { - debug: false + logLevel: 'quiet' }, data: { description: 'Not a quote from a smart man', diff --git a/test/pattern_assembler_tests.js b/test/pattern_assembler_tests.js index fe35e6fb6..63a073ba7 100644 --- a/test/pattern_assembler_tests.js +++ b/test/pattern_assembler_tests.js @@ -93,7 +93,7 @@ tap.test('processPatternRecursive - correctly replaces all stylemodifiers when m }; pl.data = {}; pl.data.link = {}; - pl.config.debug = false; + pl.config.logLevel = 'quiet'; pl.patterns = []; pl.partials = {}; @@ -137,7 +137,7 @@ tap.test('processPatternRecursive - correctly replaces multiple stylemodifier cl }; pl.data = {}; pl.data.link = {}; - pl.config.debug = false; + pl.config.logLevel = 'quiet'; pl.patterns = []; pl.partials = {}; @@ -182,7 +182,7 @@ tap.test('processPatternRecursive - correctly ignores a partial without a style }; pl.data = {}; pl.data.link = {}; - pl.config.debug = false; + pl.config.logLevel = 'quiet'; pl.patterns = []; pl.partials = {}; @@ -225,7 +225,7 @@ tap.test('processPatternRecursive - correctly ignores bookended partials without }; pl.data = {}; pl.data.link = {}; - pl.config.debug = false; + pl.config.logLevel = 'quiet'; pl.patterns = []; pl.partials = {}; @@ -269,7 +269,7 @@ tap.test('processPatternRecursive - correctly ignores a partial without a style }; pl.data = {}; pl.data.link = {}; - pl.config.debug = false; + pl.config.logLevel = 'quiet'; pl.patterns = []; pl.partials = {}; @@ -314,7 +314,7 @@ tap.test('processPatternRecursive - correctly ignores bookended partials without }; pl.data = {}; pl.data.link = {}; - pl.config.debug = false; + pl.config.logLevel = 'quiet'; pl.patterns = []; pl.partials = {}; @@ -359,7 +359,7 @@ tap.test('processPatternRecursive - does not pollute previous patterns when a la }; pl.data = {}; pl.data.link = {}; - pl.config.debug = false; + pl.config.logLevel = 'quiet'; pl.patterns = []; pl.partials = {}; @@ -413,7 +413,7 @@ tap.test('processPatternRecursive - ensure deep-nesting works', function(test) { }; pl.data = {}; pl.data.link = {}; - pl.config.debug = false; + pl.config.logLevel = 'quiet'; pl.patterns = []; pl.partials = {}; @@ -611,7 +611,7 @@ tap.test('addPattern - adds pattern extended template to patternlab partial obje patternlab.patterns = []; patternlab.partials = {}; patternlab.data = {link: {}}; - patternlab.config = {debug: false}; + patternlab.config = {logLevel: 'quiet'}; patternlab.config.outputFileSuffixes = {rendered: ''}; var pattern = new Pattern('00-test/01-bar.mustache'); @@ -635,7 +635,7 @@ tap.test('addPattern - adds pattern template to patternlab partial object if ext patternlab.patterns = []; patternlab.partials = {}; patternlab.data = {link: {}}; - patternlab.config = { debug: false }; + patternlab.config = { logLevel: 'quiet' }; patternlab.config.outputFileSuffixes = {rendered : ''}; var pattern = new Pattern('00-test/01-bar.mustache'); @@ -699,7 +699,7 @@ tap.test('markModifiedPatterns - finds patterns when modification date is missin var patternlab = emptyPatternLab(); patternlab.partials = {}; patternlab.data = {link: {}}; - patternlab.config = { debug: false }; + patternlab.config = { logLevel: 'quiet' }; patternlab.config.outputFileSuffixes = {rendered : ''}; var pattern = new Pattern('00-test/01-bar.mustache'); @@ -720,7 +720,7 @@ tap.test('markModifiedPatterns - finds patterns via compile state', function(tes var patternlab = emptyPatternLab(); patternlab.partials = {}; patternlab.data = {link: {}}; - patternlab.config = { debug: false }; + patternlab.config = { logLevel: 'quiet' }; patternlab.config.outputFileSuffixes = {rendered : ''}; var pattern = new Pattern('00-test/01-bar.mustache'); diff --git a/test/pseudopattern_hunter_tests.js b/test/pseudopattern_hunter_tests.js index 57becf357..e3643dada 100644 --- a/test/pseudopattern_hunter_tests.js +++ b/test/pseudopattern_hunter_tests.js @@ -33,7 +33,7 @@ function stubPatternlab() { }; pl.data = {}; pl.data.link = {}; - pl.config.debug = false; + pl.config.logLevel = 'quiet'; pl.patterns = []; pl.partials = {}; pl.config.patternStates = {}; diff --git a/test/style_modifier_hunter_tests.js b/test/style_modifier_hunter_tests.js index e1a999a8b..2d3e25df0 100644 --- a/test/style_modifier_hunter_tests.js +++ b/test/style_modifier_hunter_tests.js @@ -9,7 +9,7 @@ tap.test('uses the partial stylemodifer to modify the patterns extendedTemplate' var pl = {}; pl.partials = {}; pl.config = {}; - pl.config.debug = false; + pl.config.logLevel = 'quiet'; var pattern = { extendedTemplate: '
' @@ -30,7 +30,7 @@ tap.test('replaces style modifiers with spaces in the syntax', function(test){ var pl = {}; pl.partials = {}; pl.config = {}; - pl.config.debug = false; + pl.config.logLevel = 'quiet'; var pattern = { extendedTemplate: '
' @@ -51,7 +51,7 @@ tap.test('replaces multiple style modifiers', function(test){ var pl = {}; pl.partials = {}; pl.config = {}; - pl.config.debug = false; + pl.config.logLevel = 'quiet'; var pattern = { extendedTemplate: '
' @@ -72,7 +72,7 @@ tap.test('does not alter pattern extendedTemplate if styleModifier not found in var pl = {}; pl.partials = {}; pl.config = {}; - pl.config.debug = false; + pl.config.logLevel = 'quiet'; var pattern = { extendedTemplate: '
' diff --git a/test/ui_builder_tests.js b/test/ui_builder_tests.js index 6dc5bf308..8e563d71c 100644 --- a/test/ui_builder_tests.js +++ b/test/ui_builder_tests.js @@ -42,7 +42,7 @@ function createFakePatternLab(customProps) { } }, styleGuideExcludes: [ 'templates' ], - debug: false, + logLevel: 'quiet', outputFileSuffixes: { rendered: '.rendered', rawTemplate: '', diff --git a/test/util/patternlab-config.json b/test/util/patternlab-config.json index 720975302..2029bccfe 100644 --- a/test/util/patternlab-config.json +++ b/test/util/patternlab-config.json @@ -36,7 +36,7 @@ "defaultPattern": "all", "ignored-extensions" : ["scss", "DS_Store", "less"], "ignored-directories" : ["scss"], - "debug": false, + "logLevel": "quiet", "ishControlsHide": { "s": false, "m": false,