Skip to content

Commit

Permalink
Merge branch '212-verbose-flag' Fixes #212.
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnAlbin committed Jun 4, 2015
2 parents a5972fa + bb1efa5 commit 3e827ca
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 34 deletions.
16 changes: 13 additions & 3 deletions bin/kss-node
Expand Up @@ -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',
Expand Down Expand Up @@ -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('');
}
}
});

Expand Down
67 changes: 44 additions & 23 deletions generator/handlebars/kss_handlebars_generator.js
Expand Up @@ -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) {
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 {
Expand Down Expand Up @@ -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.
Expand All @@ -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];
Expand All @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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) {
Expand All @@ -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*/
Expand Down
4 changes: 3 additions & 1 deletion generator/kss_generator.js
Expand Up @@ -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*/

Expand Down
14 changes: 7 additions & 7 deletions test/kss-node.js
Expand Up @@ -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();
});
Expand All @@ -37,17 +37,17 @@ 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();
});
});
});

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();
});
Expand All @@ -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();
});
});
Expand Down

0 comments on commit 3e827ca

Please sign in to comment.