Last active
December 30, 2015 08:39
-
-
Save asad01304/7804447 to your computer and use it in GitHub Desktop.
Node script Moduler Js deployment script
This file contains 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
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; | |
} |
This file contains 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
{ | |
"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