From d036034ecc2abf04bae0bdd6b4186669d50cb127 Mon Sep 17 00:00:00 2001 From: JohnAlbin Date: Thu, 4 Jun 2015 17:47:28 +0800 Subject: [PATCH 1/3] Prevent empty helpers list in output. #212 --- generator/handlebars/kss_handlebars_generator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/handlebars/kss_handlebars_generator.js b/generator/handlebars/kss_handlebars_generator.js index a75dacef..76c8a8ad 100644 --- a/generator/handlebars/kss_handlebars_generator.js +++ b/generator/handlebars/kss_handlebars_generator.js @@ -63,7 +63,7 @@ kssHandlebarsGenerator.init = function(config) { console.log(' * KSS Source : ' + this.config.source.join(', ')); console.log(' * Destination : ' + this.config.destination); console.log(' * Template : ' + this.config.template); - if (this.config.helpers) { + if (this.config.helpers.length) { console.log(' * Helpers : ' + this.config.helpers.join(', ')); } console.log(''); From 486bedd342919fe0f3536afb036a44fc2dac0ac4 Mon Sep 17 00:00:00 2001 From: JohnAlbin Date: Thu, 4 Jun 2015 18:24:56 +0800 Subject: [PATCH 2/3] Implement --verbose option to supress most output by default. #212 --- bin/kss-node | 16 ++++- .../handlebars/kss_handlebars_generator.js | 67 ++++++++++++------- generator/kss_generator.js | 4 +- 3 files changed, 60 insertions(+), 27 deletions(-) diff --git a/bin/kss-node b/bin/kss-node index 7043bafb..94dd5fe7 100755 --- a/bin/kss-node +++ b/bin/kss-node @@ -70,6 +70,12 @@ var generator, default : 'styleguide' }, + 'verbose': { + count : true, + multiple : false, + describe : 'Display verbose details while generating' + }, + 'xdemo': { // Alias is redundant, but prevents "Unknown argument: xdemo" error. alias : 'xdemo', @@ -222,9 +228,13 @@ generatorConfig = normalizeConfig(generatorConfig); // Set up error handling. process.on('exit', function() { if (KSS_GENERATING && !KSS_FAILED) { - console.log(''); - console.log('Generation completed successfully!'); - console.log(''); + if (generatorConfig.verbose) { + console.log(''); + } + console.log('Style guide generation completed successfully!'); + if (generatorConfig.verbose) { + console.log(''); + } } }); diff --git a/generator/handlebars/kss_handlebars_generator.js b/generator/handlebars/kss_handlebars_generator.js index 76c8a8ad..c9dbb0b3 100644 --- a/generator/handlebars/kss_handlebars_generator.js +++ b/generator/handlebars/kss_handlebars_generator.js @@ -57,16 +57,18 @@ kssHandlebarsGenerator.init = function(config) { // Save the configuration parameters. this.config = config; - console.log(''); - console.log('Generating your KSS style guide!'); - console.log(''); - console.log(' * KSS Source : ' + this.config.source.join(', ')); - console.log(' * Destination : ' + this.config.destination); - console.log(' * Template : ' + this.config.template); - if (this.config.helpers.length) { - console.log(' * Helpers : ' + this.config.helpers.join(', ')); + if (this.config.verbose) { + console.log(''); + console.log('Generating your KSS style guide!'); + console.log(''); + console.log(' * KSS Source : ' + this.config.source.join(', ')); + console.log(' * Destination : ' + this.config.destination); + console.log(' * Template : ' + this.config.template); + if (this.config.helpers.length) { + console.log(' * Helpers : ' + this.config.helpers.join(', ')); + } + console.log(''); } - console.log(''); // Create a new destination directory. try { @@ -145,16 +147,20 @@ kssHandlebarsGenerator.generate = function(styleguide) { i, key; - console.log(styleguide.data.files.map(function(file) { - return ' - ' + file; - }).join('\n')); + if (this.config.verbose) { + console.log(styleguide.data.files.map(function(file) { + return ' - ' + file; + }).join('\n')); + } // Throw an error if no KSS sections are found in the source files. if (sectionCount === 0) { throw new Error('No KSS documentation discovered in source files.'); } - console.log('...Determining section markup:'); + if (this.config.verbose) { + console.log('...Determining section markup:'); + } for (i = 0; i < sectionCount; i += 1) { // Register all the markup blocks as Handlebars partials. @@ -179,8 +185,13 @@ kssHandlebarsGenerator.generate = function(styleguide) { // If the markup file is not found, note that in the style guide. if (!files.length) { partial.markup += ' NOT FOUND!'; + if (!this.config.verbose) { + console.log('WARNING: In section ' + partial.reference + ', ' + partial.markup); + } + } + if (this.config.verbose) { + console.log(' - ' + partial.reference + ': ' + partial.markup); } - console.log(' - ' + partial.reference + ': ' + partial.markup); if (files.length) { // Load the partial's markup from file. partial.file = files[0]; @@ -194,7 +205,7 @@ kssHandlebarsGenerator.generate = function(styleguide) { } } } - } else { + } else if (this.config.verbose) { console.log(' - ' + partial.reference + ': inline markup'); } // Register the partial using the filename (without extension) or using @@ -216,7 +227,9 @@ kssHandlebarsGenerator.generate = function(styleguide) { } } - console.log('...Generating style guide sections:'); + if (this.config.verbose) { + console.log('...Generating style guide sections:'); + } // Now, group all of the sections by their root // reference, and make a page for each. @@ -252,7 +265,9 @@ kssHandlebarsGenerator.generatePage = function(styleguide, sections, root, secti if (root === 'styleguide.homepage') { filename = 'index.html'; - console.log(' - homepage'); + if (this.config.verbose) { + console.log(' - homepage'); + } // Ensure homepageText is a non-false value. for (key in this.config.source) { if (!homepageText) { @@ -268,15 +283,21 @@ kssHandlebarsGenerator.generatePage = function(styleguide, sections, root, secti } if (!homepageText) { homepageText = ' '; - console.log(' ...no homepage content found in ' + this.config.homepage + '.'); + if (this.config.verbose) { + console.log(' ...no homepage content found in ' + this.config.homepage + '.'); + } else { + console.log('WARNING: no homepage content found in ' + this.config.homepage + '.'); + } } } else { filename = 'section-' + KssSection.prototype.encodeReferenceURI(root) + '.html'; - console.log( - ' - section ' + root + ' [', - styleguide.section(root) ? styleguide.section(root).header() : 'Unnamed', - ']' - ); + if (this.config.verbose) { + console.log( + ' - section ' + root + ' [', + styleguide.section(root) ? styleguide.section(root).header() : 'Unnamed', + ']' + ); + } } // Create the HTML to load the optional CSS and JS. /*eslint-disable guard-for-in*/ diff --git a/generator/kss_generator.js b/generator/kss_generator.js index 1a98ec9c..3f08c101 100644 --- a/generator/kss_generator.js +++ b/generator/kss_generator.js @@ -124,7 +124,9 @@ KssGenerator.prototype.init = function(config) { * the HTML files of the style guide. */ KssGenerator.prototype.parse = function(callback) { - console.log('...Parsing your style guide:'); + if (this.config.verbose) { + console.log('...Parsing your style guide:'); + } /*eslint-disable key-spacing*/ From bb1efa50abfd77c333feb82b3546fc33f25ae231 Mon Sep 17 00:00:00 2001 From: JohnAlbin Date: Thu, 4 Jun 2015 21:05:59 +0800 Subject: [PATCH 3/3] Update tests. #212 --- test/kss-node.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/kss-node.js b/test/kss-node.js index ef923dce..368b2c0d 100644 --- a/test/kss-node.js +++ b/test/kss-node.js @@ -15,16 +15,16 @@ suite('Command Line Interface', function() { suite('Option: --source', function() { test('Should read source directory from option', function(done) { - exec('bin/kss-node --source test/fixtures-styles/with-include --destination test/output', function(err, stdout, stderr) { + exec('bin/kss-node --verbose --source test/fixtures-styles/with-include --destination test/output', function(err, stdout, stderr) { assert.ok(/\* KSS Source : .+test\/fixtures\-styles\/with\-include/g.test(stdout), 'Read --source option'); assert.strictEqual(/no styleguide overview generated/g.test(stdout), false, 'Styleguide homepage not generated from empty file'); done(); }); }); test('Should not declare success if source directory is empty', function(done) { - exec('bin/kss-node --source test/fixtures-styles/empty-source --destination test/output', function(err, stdout, stderr) { + exec('bin/kss-node --verbose --source test/fixtures-styles/empty-source --destination test/output', function(err, stdout, stderr) { assert.ok(/\* KSS Source : .+test\/fixtures\-styles\/empty\-source/g.test(stdout), 'Read --source option'); - assert.strictEqual(/Generation completed successfully/g.test(stdout), false, 'Success incorrectly declared'); + assert.strictEqual(/Style guide generation completed successfully/g.test(stdout), false, 'Success incorrectly declared'); assert.ok(/No KSS documentation discovered in source files./g.test(stdout), 'Warning about no KSS docs given'); done(); }); @@ -37,9 +37,9 @@ suite('Command Line Interface', function() { }); }); test('Should read multiple source directories from option', function(done) { - exec('bin/kss-node --source test/fixtures-styles/with-include --source test/fixtures-styles/empty-source --destination test/output', function(err, stdout, stderr) { + exec('bin/kss-node --verbose --source test/fixtures-styles/with-include --source test/fixtures-styles/empty-source --destination test/output', function(err, stdout, stderr) { assert.ok(/\* KSS Source : .+test\/fixtures\-styles\/with\-include, .+test\/fixtures\-styles\/empty\-source/g.test(stdout), 'Read multiple --source options'); - assert.strictEqual(/Generation completed successfully/g.test(stdout), true, 'Styleguide generated from multiple sources'); + assert.strictEqual(/Style guide generation completed successfully/g.test(stdout), true, 'Styleguide generated from multiple sources'); done(); }); }); @@ -47,7 +47,7 @@ suite('Command Line Interface', function() { suite('Option: --destination', function() { test('Should read destination directory from option', function(done) { - exec('bin/kss-node test/fixtures-styles/with-include --destination test/output', function(err, stdout, stderr) { + exec('bin/kss-node --verbose test/fixtures-styles/with-include --destination test/output', function(err, stdout, stderr) { assert.ok(/\* Destination : .+test\/output/g.test(stdout), 'Read --destination option'); done(); }); @@ -67,7 +67,7 @@ suite('Command Line Interface', function() { suite('Option: --config', function() { test('Should load configuration from json file', function(done) { exec('bin/kss-node --config test/cli-option-config.json', function(err, stdout, stderr) { - assert.ok(/Generation completed successfully/g.test(stdout), 'Read --config option'); + assert.ok(/Style guide generation completed successfully/g.test(stdout), 'Read --config option'); done(); }); });