Skip to content

Instantly share code, notes, and snippets.

@asad01304
Last active December 30, 2015 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asad01304/7804447 to your computer and use it in GitHub Desktop.
Save asad01304/7804447 to your computer and use it in GitHub Desktop.
Node script Moduler Js deployment script
var _ = require('underscore'), fs = require('fs');
var UglifyJS = require("uglify-js");
var root = 'public/javascripts/modules/';
var modules = ['Hadith'];
var FILE_ENCODING = 'utf-8', EOL = '\n';
_.each(modules, function(module){
var moduleRoot = root + module,
file = moduleRoot + '/module.json';
fs.readFile(file, FILE_ENCODING, function (err, data) {
if (err) return console.log('Error: ' + err);
var package = JSON.parse(data);
var files = [].concat(
getFilePath(package.models, moduleRoot + '/models/'),
getFilePath(package.views , moduleRoot + '/views/')
);
files.push( moduleRoot + '/module.js');
var out = files.map(function(filePath){
return fs.readFileSync(filePath, FILE_ENCODING);
});
//fs.writeFile(moduleRoot + '/module.js', out.join(EOL), FILE_ENCODING);
fs.writeFile(moduleRoot + '/module.map.js',
"(function (){" + EOL +
out.join(EOL) + EOL +
"})();",
FILE_ENCODING);
});
});
function getFilePath(files, path){
var temp = []; _.each(files, function(file){
temp.push(path + file); }); return temp;
}
{
"models" : [
"Book.js",
"collections/Book.js",
"Chapter.js",
"collections/Chapter.js",
"Hadith.js",
"collections/Hadith.js"
],
"views" : [
"abstract/Default.js",
"Book.js",
"BookList.js",
"Chapter.js",
"ChapterList.js",
"Haidth.js",
"HadithList.js"
],
"routers" : [
"Hadith.js"
],
"templates" : [
"Book.html",
"BookList.html",
"Chapter.html",
"ChapterList.html",
"Hadith.html",
"HadithList.html"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment