Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making create.js more extensible #92

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
37 changes: 24 additions & 13 deletions lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var log = require('./log'),
timethat = require('timethat'),
fs = require('fs'),
util = require('./util');
mods;


var _defaultDirs = [
Expand All @@ -15,9 +16,16 @@ var _defaultDirs = [
'./meta',
'./css',
'./assets'
];
],

var createJSON = function(options, callback) {
mods = {

/**
Create a JSON
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be a bit more descriptive. Perhaps "Creates the JSON assets for the new module"?

@method createJSON
@param {Object} options {options.name, options.location, options.defaultDirs}
**/
createJSON : function (options, callback) {

var name = options.name,
build = {
Expand Down Expand Up @@ -82,10 +90,10 @@ var createJSON = function(options, callback) {
log.debug('creating meta/' + name + '.json file: ' + metaFile);
fs.writeFileSync(metaFile, JSON.stringify(meta, null, 4) + '\n', 'utf8');
callback();
};
},


var replaceTitle = function(options, items, callback) {
replaceTitle : function(options, items, callback) {
var tags = '[ "gallery" ]',
title = options.name;
author = config.get('username');
Expand All @@ -106,15 +114,16 @@ var replaceTitle = function(options, items, callback) {
}
});
callback();
};
},

var createDirs = function(options, callback) {
createDirs : function (options, callback) {

log.info('creating default directory structure');
var stack = new util.Stack(),
copied = [];
defaultDirs = options.defaultDirs || _defaultDirs;

_defaultDirs.forEach(function(dir) {
defaultDirs.forEach(function (dir) {
var d = path.join(__dirname, '../defaults/', dir),
toDir = path.join(options.location, dir);

Expand All @@ -138,22 +147,21 @@ var createDirs = function(options, callback) {
});
stack.done(function() {
log.info('directories created, processing files');
replaceTitle(options, copied, function() {
createJSON(options, function() {
mods.replaceTitle(options, copied, function() {
mods.createJSON(options, function() {
callback();
});
});
});
};

exports.init = function(options, callback) {
},
init : function (options, callback) {
var start = (new Date()).getTime();
log.info('creating module (' + options.name + ') in: ' + options.location);
if (util.exists(options.location)) {
log.bail('destination already exists, you are on your own! bailing..');
}

createDirs(options, function() {
this.createDirs(options, function () {
util.tree(options.location, options.root, function(tree) {
log.log('');
log.info('module created, here\'s what yogi did for you:');
Expand All @@ -163,5 +171,8 @@ exports.init = function(options, callback) {
callback();
});
});
}
};

util.mix(exports, mods);