Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

dumb down the cli, remove options

  • Loading branch information...
commit c1b829779121f63c5f59876ceb8b2959bdc842c7 1 parent f27ed1d
@ianstormtaylor ianstormtaylor authored
View
2  Makefile
@@ -3,6 +3,6 @@ node_modules: package.json
@npm install
test: node_modules
- @./node_modules/.bin/mocha --reporter spec
+ @./node_modules/.bin/mocha --reporter spec --slow 300
.PHONY: test
View
51 bin/metalsmith
@@ -1,24 +1,17 @@
#!/usr/bin/env node
+var colors = require('colors');
var exists = require('fs').existsSync;
var Metalsmith = require('..');
-var program = require('commander');
var resolve = require('path').resolve;
/**
- * Program.
+ * Config.
*/
-program
- .option('-c, --config <file>', 'set an alternate config file')
- .parse(process.argv);
-
-/**
- * Settings.
- */
-
-var config = resolve(process.cwd(), program.config || 'metalsmith.json');
-var json = exists(config) ? require(config) : {};
+var config = resolve(process.cwd(), 'metalsmith.json');
+if (!exists(config)) console.error('Could not find a "metalsmith.json" configuration file.');
+var json = require(config);
/**
* Metalsmith.
@@ -40,8 +33,7 @@ for (var key in json.plugins) {
try {
plugin = require(key);
} catch (e) {
- console.error('failed to require plugin "' + key + '"');
- process.exit(1);
+ fatal('Failed to require plugin "' + key + '".');
}
metalsmith.use(plugin(opts));
@@ -52,6 +44,31 @@ for (var key in json.plugins) {
*/
metalsmith.build(function(err){
- if (err) return console.error(err);
- console.log('built');
-});
+ if (err) return fatal(err.message);
+ log('Successfully built to ' + metalsmith.destination());
+});
+
+/**
+ * Log an error and then exit the process.
+ *
+ * @param {String} message
+ */
+
+function fatal(msg){
+ console.error();
+ console.error(' Error: '.red + msg);
+ console.error();
+ process.exit(1);
+}
+
+/**
+ * Log a `message`.
+ *
+ * @param {String} message
+ */
+
+function log(message){
+ console.log();
+ console.log(' Metalsmith: '.gray + message);
+ console.log();
+}
View
1  lib/index.js
@@ -90,7 +90,6 @@ Metalsmith.prototype.metadata = function(metadata){
Metalsmith.prototype.join = function(){
var strs = [].slice.call(arguments);
strs.unshift(this.dir);
- console.log(strs);
return path.join.apply(path, strs);
};
View
5 package.json
@@ -30,7 +30,8 @@
"async": "~0.2.10",
"fs-extra": "~0.8.1",
"defaults": "~1.0.0",
- "is-utf8": "~0.2.0"
+ "is-utf8": "~0.2.0",
+ "colors": "~0.6.2"

you don't want to use colors. it clobbers the String.prototype for this module all dependencies.

For a sane alternative there's: chalk or a little heavier cli-colors.

@ianstormtaylor Owner

nice! good to know ill update myth too. just fixed: af15c9a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
},
"devDependencies": {
"mocha": "1.x",
@@ -40,4 +41,4 @@
"assert-dir-equal": "~0.1.0",
"metalsmith-drafts": "0.0.1"
}
-}
+}
View
1  test/fixtures/cli-basic/expected/index.md
@@ -1 +0,0 @@
-body
View
1  test/fixtures/cli-basic/src/index.md
@@ -1 +0,0 @@
-body
View
4 test/fixtures/cli-config/config.json
@@ -1,4 +0,0 @@
-{
- "source": "source",
- "destination": "destination"
-}
View
1  test/fixtures/cli-config/destination/index.md
@@ -1 +0,0 @@
-body
View
1  test/fixtures/cli-config/expected/index.md
@@ -1 +0,0 @@
-body
View
0  test/fixtures/cli-config/source/index.md → test/fixtures/cli-no-config/src/index.md
File renamed without changes
View
5 test/fixtures/cli-no-plugin/metalsmith.json
@@ -0,0 +1,5 @@
+{
+ "plugins": {
+ "metalsmith-non-existant": {}
+ }
+}
View
5 test/fixtures/cli-no-plugin/src/one.md
@@ -0,0 +1,5 @@
+---
+draft: true
+---
+
+one
View
1  test/fixtures/cli-no-plugin/src/two.md
@@ -0,0 +1 @@
+two
View
26 test/index.js
@@ -134,10 +134,10 @@ describe('CLI', function(){
var bin = __dirname + '/../bin/metalsmith';
describe('build', function(){
- it('should perform a basic build', function(done){
- exec('cd test/fixtures/cli-basic && ' + bin, function(err, stdout){
- if (err) return done(err);
- equal('test/fixtures/cli-basic/build', 'test/fixtures/cli-basic/expected');
+ it('should error without a metalsmith.json', function(done){
+ exec('cd test/fixtures/cli-no-config && ' + bin, function(err, stdout){
+ assert(err);
+ assert(~err.message.indexOf('Could not find a "metalsmith.json" configuration file.'));
done();
});
});
@@ -146,22 +146,26 @@ describe('CLI', function(){
exec('cd test/fixtures/cli-json && ' + bin, function(err, stdout){
if (err) return done(err);
equal('test/fixtures/cli-json/destination', 'test/fixtures/cli-json/expected');
+ assert(~stdout.indexOf('Successfully built to '));
+ assert(~stdout.indexOf('test/fixtures/cli-json/destination'));
done();
});
});
- it('should grab config from alternate json', function(done){
- exec('cd test/fixtures/cli-config && ' + bin + ' -c config.json', function(err, stdout){
+ it('should require a plugin', function(done){
+ exec('cd test/fixtures/cli-drafts && ' + bin, function(err, stdout){
if (err) return done(err);
- equal('test/fixtures/cli-config/destination', 'test/fixtures/cli-config/expected');
+ equal('test/fixtures/cli-drafts/build', 'test/fixtures/cli-drafts/expected');
+ assert(~stdout.indexOf('Successfully built to '));
+ assert(~stdout.indexOf('test/fixtures/cli-drafts/build'));
done();
});
});
- it('should require a plugin', function(done){
- exec('cd test/fixtures/cli-drafts && ' + bin, function(err, stdout){
- if (err) return done(err);
- equal('test/fixtures/cli-drafts/build', 'test/fixtures/cli-drafts/expected');
+ it('should error when failing to require a plugin', function(done){
+ exec('cd test/fixtures/cli-no-plugin && ' + bin, function(err, stdout){
+ assert(err);
+ assert(~err.message.indexOf('Failed to require plugin "metalsmith-non-existant".'));
done();
});
});
Please sign in to comment.
Something went wrong with that request. Please try again.