Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactoring to remove climate

  • Loading branch information...
commit 8d815951ca634912870ae17ba5e1021b2bd27a19 1 parent a95bcb5
@DamonOehlman authored
View
14 bin/demogen
@@ -1,14 +1,2 @@
#!/usr/bin/env node
-
-var path = require('path'),
- repl = require('climate').repl('demogen>');
-
-// create the generator
-repl.generator = require('../lib/generator');
-
-// load the actions and run
-repl
- .history()
- .loadActions(path.resolve(__dirname, '../lib/actions'), function() {
- repl.run(process.argv.slice(2).join(' '));
- });
+require('scaffolder')();
View
33 lib/actions/build.js → lib/commands/build.js
@@ -2,7 +2,6 @@ var async = require('async'),
fs = require('fs'),
path = require('path'),
handlebars = require('handlebars'),
- out = require('out'),
_ = require('underscore'),
reIgnore = /^_/,
reDemoFile = /(^demo\.|\.js$)/i,
@@ -87,7 +86,7 @@ readers.markdown = function(filename, existingValue) {
/* internal functions */
-function compile(repl, demo, callback) {
+function compile(scaffolder, demo, callback) {
var outputFile = path.join(demo.basePath, demo.key + '.html'),
template;
@@ -121,7 +120,7 @@ function compile(repl, demo, callback) {
demo.keys = demo.keys || [];
// prepare the views
- prepareViews(repl, demo, function() {
+ prepareViews(scaffolder, demo, function() {
// if we have a layout for the demo, then build
if (demo.key && demo.layout) {
template = handlebars.compile(demo.layout);
@@ -129,10 +128,10 @@ function compile(repl, demo, callback) {
// write the file
fs.writeFile(outputFile, template(demo), function(err) {
if (err) {
- out('!{red}Unable to generate!{} file !{underline}{0}', outputFile);
+ scaffolder.out('!{red}Unable to generate!{} file !{underline}{0}', outputFile);
}
else {
- out('Generated demo file: !{underline}{0}', outputFile);
+ scaffolder.out('Generated demo file: !{underline}{0}', outputFile);
} // if..else
callback(err);
@@ -170,7 +169,7 @@ function extractSettings(config) {
return settings;
} // extractSettings
-function findSnippets(repl, targetPath, config, callback) {
+function findSnippets(scaffolder, targetPath, config, callback) {
var subdirs = [],
snippets = [],
isDemo = false,
@@ -242,14 +241,14 @@ function findSnippets(repl, targetPath, config, callback) {
});
}
catch (e) {
- out('!{red}Error parsing deck config @ {0}', configFile);
+ scaffolder.out('!{red}Error parsing deck config @ {0}', configFile);
} // try..catch
} // if
// read the contents of the directory
fs.readdir(targetPath, function(err, files) {
if (err) {
- out('Unable to read directory: {0}', targetPath);
+ scaffolder.out('Unable to read directory: {0}', targetPath);
callback();
}
else {
@@ -265,7 +264,7 @@ function findSnippets(repl, targetPath, config, callback) {
async.forEach(
subdirs,
function(testPath, dirCallback) {
- findSnippets(repl, testPath, childConfig, function(childSnippets) {
+ findSnippets(scaffolder, testPath, childConfig, function(childSnippets) {
snippets = snippets.concat(childSnippets);
dirCallback(null);
});
@@ -354,7 +353,7 @@ function orderScripts(scripts) {
return output.join('\n\n').replace(/\n*$/, '');
} // orderScripts
-function prepareViews(repl, demo, callback) {
+function prepareViews(scaffolder, demo, callback) {
var views = (demo.views || 'editor').split(/[\s\,]/),
preparedViews = {},
viewFn;
@@ -368,13 +367,13 @@ function prepareViews(repl, demo, callback) {
}
catch (e) {
viewFn = null;
- out('Could not load view renderer: {0}', view);
+ scaffolder.out('Could not load view renderer: {0}', view);
console.log(e);
} // try..catch
if (viewFn) {
- viewFn.call(null, repl, demo, function(contents) {
+ viewFn.call(null, scaffolder, demo, function(contents) {
preparedViews[view] = contents;
viewCallback();
});
@@ -394,22 +393,22 @@ function prepareViews(repl, demo, callback) {
/* exports */
-module.exports = function(opts, callback) {
- var repl = this,
+exports.run = function(opts, callback) {
+ var scaffolder = this,
baseConfig = {
basePath: path.resolve(),
theme: 'dawn',
mode: 'javascript'
};
- out('Looking for demos in: !{underline}{0}', baseConfig.basePath);
- findSnippets(repl, path.join(baseConfig.basePath, '_sources'), baseConfig, function(snippets) {
+ this.out('Looking for demos in: !{underline}{0}', baseConfig.basePath);
+ findSnippets(scaffolder, path.join(baseConfig.basePath, '_sources'), baseConfig, function(snippets) {
if (snippets && snippets.length) {
// compile each of the decks
async.forEach(
snippets,
function(demo, compileCallback) {
- compile(repl, demo.config, compileCallback);
+ compile(scaffolder, demo.config, compileCallback);
},
callback || function() {}
);
View
0  lib/actions/create.js → lib/commands/create.js
File renamed without changes
View
15 lib/generator.js
@@ -1,15 +0,0 @@
-var fs = require('fs'),
- path = require('path'),
- scaffolder = require('scaffolder')(module);
-
-function Generator() {
-
-} // Generator
-
-Generator.prototype.readFile = function(filename, callback) {
- scaffolder.getPath(function(filepath) {
- fs.readFile(path.join(filepath, 'assets', filename), 'utf8', callback);
- });
-};
-
-module.exports = new Generator();
View
6 lib/views/console.js
@@ -1,19 +1,19 @@
var fs = require('fs'),
path = require('path');
-module.exports = function(repl, demo, callback) {
+module.exports = function(scaffolder, demo, callback) {
demo.includes = demo.includes || [];
// if we have a demo mode, then specify the mode
// demo.includes.unshift('_demogen/js/fakeconsole.js');
// read the fakeconsole files
- repl.generator.readFile('views/console.css', function(err, data) {
+ scaffolder.readFile('views/console.css', function(err, data) {
if (! err) {
demo.css.push(data);
} // if
- repl.generator.readFile('views/console.html', function(err, data) {
+ scaffolder.readFile('views/console.html', function(err, data) {
callback(data);
});
});
View
6 lib/views/editor.js
@@ -2,13 +2,13 @@ var fs = require('fs'),
path = require('path'),
handlebars = require('handlebars');
-module.exports = function(repl, demo, callback) {
- repl.generator.readFile('views/editor.css', function(err, data) {
+module.exports = function(scaffolder, demo, callback) {
+ scaffolder.readFile('views/editor.css', function(err, data) {
if (! err) {
demo.css.push(data);
} // if
- repl.generator.readFile('views/editor.html', function(err, data) {
+ scaffolder.readFile('views/editor.html', function(err, data) {
if (err) {
data = '<div id="editor">{{{ code }}}</div>';
} // if
View
4 package.json
@@ -16,11 +16,9 @@
},
"dependencies": {
"async": "0.1.x",
- "climate": "0.2.x",
"handlebars": ">= 1.0.0",
"underscore": "1.3.x",
- "scaffolder": "0.4.x",
- "out": "*"
+ "scaffolder": "0.5.x"
},
"devDependencies": {
"vows": "0.5.x"
Please sign in to comment.
Something went wrong with that request. Please try again.