Created
December 12, 2012 01:09
-
-
Save kara-ryli/4263977 to your computer and use it in GitHub Desktop.
A simple nodejs script that imports an existing YUI module-based project into a Yogi <http://yui.github.com/yogi/>-based tree. It's not perfect--it doesn't remove the existing boilerplate, but it's a start.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*global require,console,process*/ | |
var fs = require("fs.extra"), | |
exec = require('child_process').exec, | |
path = process.argv[2]; | |
fs.readdirSync(path).forEach(function (name) { | |
var loc = path + "/" + name; | |
// Is it a directory? | |
if ((/^[^\.]/).test(name)) { | |
fs.lstat(loc, function (err, stats) { | |
var jsFile = "/" + name + ".js", | |
cssFile = "/" + name + ".css", | |
dest = "./src/" + name, | |
type, | |
cmd; | |
if (err || !stats.isDirectory()) { | |
return; | |
} | |
type = fs.existsSync(loc + jsFile) ? "js" : "css"; | |
cmd = "yogi init " + name + " --yes --type " + type; | |
// create the directory | |
exec(cmd, function (error, stdout, stderr) { | |
if (error) { | |
console.log("yogi error on " + name + ": " + error); | |
return; | |
} | |
// if it's a JavaScript module | |
if ("js" === type) { | |
// copy the javascript file into the generated src folder | |
fs.unlink(dest + "/js" + jsFile, function (err) { | |
if (err) { | |
throw err; | |
} | |
fs.copy(loc + jsFile, dest + "/js" + jsFile, function (err2) { | |
if (!err) { | |
console.log("copied " + loc + jsFile + " --> " + dest + "/js" + jsFile); | |
} | |
}); | |
}); | |
// otherwise | |
} else if ("css" === type) { | |
// copy the CSS into the CSS folder | |
fs.unlink(dest + "/css" + cssFile, function (err) { | |
if (err) { | |
throw err; | |
} | |
fs.copy(loc + cssFile, dest + "/css" + cssFile, function (err) { | |
if (!err) { | |
console.log("copied " + loc + cssFile + " --> " + dest + "/css" + cssFile); | |
} | |
}); | |
}); | |
} | |
// if an assets folder exists | |
fs.exists(loc + "/assets", function (exists) { | |
if (exists) { | |
// copy the contents of the assets into the new assets folder | |
fs.copyRecursive(loc + "/assets", dest + "/assets", function (err) { | |
if (!err) { | |
console.log("copied " + loc + "/assets --> " + dest + "/assets"); | |
} | |
}); | |
} | |
}); | |
}); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment