Skip to content

Commit

Permalink
Now working with Aloha Editor :)
Browse files Browse the repository at this point in the history
  • Loading branch information
balupton committed Mar 23, 2011
1 parent 4bae8b5 commit 36c5c5b
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 17 deletions.
7 changes: 7 additions & 0 deletions bin/buildr.js
@@ -0,0 +1,7 @@
// Prepare
var
Buildr = require('buildr').Buildr,
myBuildr = new Buildr(process.argv[2]||__dirname);

// Run
myBuildr.run();
51 changes: 35 additions & 16 deletions lib/buildr.js
Expand Up @@ -28,24 +28,24 @@
"config": {
"dir": {
// Exists in root path
"src": "src",
"out": "out",
"template": "template"
"src": "src"
// "out": "out",
// "template": "template"
},
"subdir": {
// Exists in src and out paths
"src": "src",
"demo": "demo",
"plugin": "plugin",
"i18n": "i18n"
// "demo": "demo",
// "plugin": "plugin",
// "i18n": "i18n"
},
"template": {
// Exists in template path
"footer": "footer.js",
"header": "header.js",
"replace": "replace.js",
"bundle": "bundle.js",
"prefix": "prefix.js"
// "footer": "footer.js",
// "header": "header.js",
// "replace": "replace.js",
// "bundle": "bundle.js",
// "prefix": "prefix.js"
},
"js": [],
"css": [],
Expand All @@ -59,7 +59,7 @@
**/
init: function(rootPath){
// Normalise Configuration
this.parseConfig(rootPath||process.argv[2]||__dirname);
this.parseConfig(rootPath);
},

/**
Expand Down Expand Up @@ -87,12 +87,25 @@

// Directories
config.dir.each(function(key,value){
// Prepare
var
relativePath = config.rootPath+'/'+value,
realPath = false;

// Exists?
try {
config.dir[key] = fs.realpathSync(config.rootPath+'/'+value);
realPath = fs.realpathSync(relativePath);
}
catch ( e ) {
config.dir[key] = false;
catch ( e ) { }

// Check
if ( !realPath ) {
fs.mkdirSync(relativePath,0700);
realPath = fs.realpathSync(relativePath);
}

// Apply
config.dir[key] = realPath;
});

// Templates
Expand Down Expand Up @@ -140,6 +153,12 @@
});
}

// Clean
if ( config.dir.out ) {
util.rmdirSync(config.dir.out);
fs.mkdirSync(config.dir.out,0700);
util.cpdirSync(config.dir.src,config.dir.out);
}

// Done
return true;
Expand Down Expand Up @@ -397,5 +416,5 @@
});

// Export
exports.buildr = Buildr;
module.exports.Buildr = Buildr;
})();
79 changes: 79 additions & 0 deletions lib/util.js
Expand Up @@ -21,6 +21,85 @@
return true;
},

/**
* Recursively remove a directory
* @param {Path} src
*/
cpdirSync: function(sourcePath,targetPath){
// Prepare
var me = this, targetPathStat = false;

// Check
try {
targetPathStat = fs.statSync(targetPath);
}
catch ( e ) { }

// Create
if ( !targetPathStat ) {
fs.mkdirSync(targetPath,0700);
}

// Cycle
fs.readdirSync(sourcePath).each(function(key,file){
// Prepare
var
sourceFilePath = sourcePath+'/'+file,
targetFilePath = targetPath+'/'+file,
sourceFileStat = fs.statSync(sourceFilePath);

// Handle
if ( sourceFileStat.isDirectory() ) {
// Recurse
me.cpdirSync(sourceFilePath,targetFilePath);
}
else {
// Copy
me.cpSync(sourceFilePath,targetFilePath);
}
});

// Done
return true;
},

/**
* Recursively remove a directory
* @param {Path} src
*/
rmdirSync: function(parentPath){
// Prepare
var me = this;

// Check
var stat = fs.statSync(parentPath);
if ( !stat ) return true;

// Cycle
fs.readdirSync(parentPath).each(function(key,file){
// Prepare
var
filePath = parentPath+'/'+file,
stat = fs.statSync(filePath);

// Handle
if ( stat.isDirectory() ) {
// Recurse
me.rmdirSync(filePath);
}
else {
// Delete
fs.unlinkSync(filePath);
}
});

// Delete
fs.rmdirSync(parentPath);

// Done
return true;
},

/**
* Get the parent path
* @param {Path} p
Expand Down
5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -31,7 +31,7 @@
},
"licenses": [
{
"type": "MIT"
"type": "MIT",
"url": "http://creativecommons.org/licenses/MIT/"
}
],
Expand All @@ -51,5 +51,8 @@
"directories": {
"lib": "./lib/buildr"
},
"bin": {
"buildr": "./bin/buildr"
},
"main": "./lib/buildr"
}

0 comments on commit 36c5c5b

Please sign in to comment.