Permalink
Browse files

Refactor, make things nicer

  • Loading branch information...
felixge committed Oct 21, 2012
1 parent 4947b29 commit d16b30a99e02a8260d79ecbfabbb53e1a328c261
Showing with 56 additions and 28 deletions.
  1. +1 −12 bin/romulus
  2. +3 −1 index.js
  3. +11 −0 lib/buildSite.js
  4. +0 −15 lib/getPageList.js
  5. +13 −0 lib/getPagePaths.js
  6. +28 −0 lib/handleCommandLine.js
View
@@ -1,14 +1,3 @@
#!/usr/bin/env node
var romulus = require('..');
-var cwd = process.cwd();
-var options = {
- layouts : cwd + '/layouts',
- pages : cwd + '/pages',
- public : cwd + '/public',
- port : 8080,
-};
-
-var server = romulus.createServer(options);
-server.on('listening', function() {
- console.log('Building your empire at http://localhost:' + options.port + '/ ...');
-});
+romulus.handleCommandLine(process.cwd(), process.argv);
View
@@ -1,3 +1,5 @@
var romulus = exports;
-romulus.createServer = require('./lib/createServer');
+romulus.buildSite = require('./lib/buildSite');
+romulus.createServer = require('./lib/createServer');
+romulus.handleCommandLine = require('./lib/handleCommandLine');
View
@@ -0,0 +1,11 @@
+var getPagePaths = require('./getPagePaths');
+
+module.exports = function buildSite(options, cb) {
+ var pagesDir = options.pages;
+
+ getPagePaths(pagesDir, function(err, pages) {
+ if (err) return cb(err);
+
+ throw new Error('unfinished: needs recursive mkdir and copy module');
+ });
+};
View
@@ -1,15 +0,0 @@
-var glob = require('glob');
-
-module.exports = function findPages(options, cb) {
- var dir = options.pages;
-
- glob('**/*.html', {cwd: dir}, function(err, files) {
- if (err) return cb(err);
-
- var fullPaths = files.map(function(relativePath) {
- return dir + '/' + relativePath;
- });
-
- cb(null, fullPaths);
- });
-};
View
@@ -0,0 +1,13 @@
+var glob = require('glob');
+
+module.exports = function getPagePaths(pagesDir, cb) {
+ glob('**/*.html', {cwd: pagesDir}, function(err, files) {
+ if (err) return cb(err);
+
+ var fullPaths = files.map(function(relativePath) {
+ return pagesDir + '/' + relativePath;
+ });
+
+ cb(null, fullPaths);
+ });
+};
View
@@ -0,0 +1,28 @@
+var buildSite = require('./buildSite');
+var createServer = require('./createServer');
+
+module.exports = function handleCommandLine(cwd, args) {
+ var options = {
+ layouts : cwd + '/layouts',
+ pages : cwd + '/pages',
+ public : cwd + '/public',
+ port : 8080,
+ };
+
+
+ var outputPath = process.argv[2];
+ if (outputPath) {
+ var start = Date.now();
+ buildSite(options, function(err) {
+ if (err) throw err;
+
+ console.log('time', Date.now() - start, 'ms');
+ });
+ return;
+ }
+
+ var server = createServer(options);
+ server.on('listening', function() {
+ console.log('Building your static empire at http://localhost:' + options.port + '/ ...');
+ });
+};

0 comments on commit d16b30a

Please sign in to comment.