Skip to content
Browse files

Reorganizing library to support plugins

  • Loading branch information...
1 parent 7417536 commit 69c32e78694ae59722b5f355f85127a261a1a72a @DamonOehlman committed Jul 10, 2012
View
0 lib/helpers/filters.js → helpers/filters.js
File renamed without changes.
View
0 lib/helpers/find-package.js → helpers/find-package.js
File renamed without changes.
View
38 lib/scaffolder.js → index.js
@@ -4,14 +4,13 @@ var async = require('async'),
util = require('util'),
fs = require('fs'),
path = require('path'),
- mkdirp = require('mkdirp'),
nopt = require('nopt'),
- ncp = require('ncp').ncp,
out = require('out'),
read = require('read'),
_ = require('underscore'),
findPackage = require('./helpers/find-package'),
filters = require('./helpers/filters'),
+ pluginFiles = fs.readdirSync(path.resolve(__dirname, 'plugins')).filter(filters.jsOnly),
rePathDelim = /[\/\\]/,
_exists = fs.exists || path.exists,
@@ -89,37 +88,6 @@ function Scaffolder(opts) {
util.inherits(Scaffolder, events.EventEmitter);
-Scaffolder.prototype.copy = function(src, dest, callback) {
- var scaffolder = this;
-
- // create a dummy callback if we don't have one
- callback = callback || function() {};
-
- // get the source path for the package
- this.getPath(function(basePath) {
- src = path.resolve(basePath, src);
-
- debug('attempting to copy files from ' + src + ' ==> ' + dest);
-
- // if the path exists, copy the files
- _exists(src, function(exists) {
- if (exists) {
- mkdirp(dest, function(err) {
- if (err) {
- callback(err);
- }
- else {
- ncp(src, dest, callback);
- }
- });
- }
- else {
- callback(new Error('no source files'));
- }
- });
- });
-};
-
Scaffolder.prototype.getPath = function(callback) {
var scaffolder = this;
@@ -294,6 +262,10 @@ Scaffolder.prototype.run = function(name, opts, callback) {
command.run.call(this, opts, callback);
};
+// patch in plugins for the prototype
+pluginFiles.forEach(function(pluginFile) {
+ Scaffolder.prototype[path.basename(pluginFile, '.js')] = require('./plugins/' + pluginFile);
+});
exports = module.exports = function(opts, initFn) {
var scaffolder,
View
8 package.json
@@ -6,20 +6,22 @@
],
"author": "Damon Oehlman <damon.oehlman@sidelab.com>",
"version": "0.5.8",
- "main": "lib/scaffolder",
"engines": {
"node": ">= 0.6.x < 0.9.0"
},
"dependencies": {
"async": "0.1.x",
"debug": "*",
- "mkdirp": "0.3.x",
- "ncp": "0.2.x",
"nopt": "1.0.x",
"out": "0.4.x",
"read": "0.1.x",
+ "squirrel": "0.1.x",
"underscore": "1.3.x"
},
+ "pluginDependencies": {
+ "mkdirp": "0.3.x",
+ "ncp": "0.2.6"
+ },
"devDependencies": {
"mocha": "1.2.x",
"expect.js": "0.1.x"
View
36 plugins/copy.js
@@ -0,0 +1,36 @@
+var squirrel = require('squirrel');
+
+module.exports = function(src, dest, callback) {
+ var scaffolder = this;
+
+ // create a dummy callback if we don't have one
+ callback = callback || function() {};
+
+ squirrel(['ncp', 'mkdirp'], { allowInstall: 'prompt' }, function(err, ncp, mkdirp) {
+ if (err) return callback(err);
+
+ // get the source path for the package
+ scaffolder.getPath(function(basePath) {
+ src = path.resolve(basePath, src);
+
+ debug('attempting to copy files from ' + src + ' ==> ' + dest);
+
+ // if the path exists, copy the files
+ _exists(src, function(exists) {
+ if (exists) {
+ mkdirp(dest, function(err) {
+ if (err) {
+ callback(err);
+ }
+ else {
+ ncp(src, dest, callback);
+ }
+ });
+ }
+ else {
+ callback(new Error('no source files'));
+ }
+ });
+ });
+ });
+};

0 comments on commit 69c32e7

Please sign in to comment.
Something went wrong with that request. Please try again.