Permalink
Browse files

cleaning up build script, seperating concerns of code creation and do…

…cumentation creation
  • Loading branch information...
1 parent 7e28afa commit 6b4d524b95181c220ea08ef9c68bbe7e61e33f4b @Marak committed Jun 19, 2010
Showing with 46 additions and 37 deletions.
  1. +27 −34 BUILD/BUILD.js
  2. +9 −1 examples/js/js-fu.js
  3. +1 −1 index.js
  4. +9 −1 js-fu.js
View
@@ -12,57 +12,66 @@ var ChildProcess = require('child_process');
var code = {};
var docs = {};
-docs.main = '';
-docs.API = '';
-docs.dateTimeFu = '';
-
-// read in the the main.js file as our main boilerplate code
+/* setup code object */
code.main = '';
code.main += fs.readFileSync('./code/index.js', encoding='utf8');
code.main = M.Mustache.to_html(code.main, {"today":new Date().getTime()});
-docs.main += fs.readFileSync('./docs/index.js', encoding='utf8');
-docs.dateTimeFu += fs.readFileSync('./docs/dateTime.js', encoding='utf8');
-
// require the entire library as a CommonJS module. we are going to iterate over the CommonJS structure and generate a bundle
var fu = require('../index');
-code.main += ('\n');
-
-var fuMethods = {};
+code.main += ('\n\n'); // maybe we can remove this
+// moduleTree will take in a CommonJS module loop through it creating a JS code bundle (generates new JS code)
+// currently this is hardcoded / customized to work only with the js-fu library
function moduleTree( level, context ){
-
for(var module in level){
fuMethods[module] = [];
for(var method in level[module]){
-
if(typeof level[module][method] == 'object'){
//moduleTree(level[module][method]);
}
else{
-
fuMethods[module].push(method);
code.main += ( 'fu.' + method + ' = ');
code.main += (level[module][method].toString() + ';\n');
-
}
-
}
fuMethods[module] = fuMethods[module].sort();
}
}
+// create object that will hold all our js-fu methods for bundle
+var fuMethods = {};
moduleTree(fu, 'fu');
+// exports hack for dual sided stuff
+// if we are running in a CommonJS env, export everything out
+code.main += 'if(typeof exports != "undefined"){for(var prop in fu){exports[prop] = fu[prop];}}';
+code.main += 'Date.prototype.format = function (mask, utc) {return fu.dateFormat(this, mask, utc);}';
+// generate some samples sets (move this code to another section)
+fs.writeFile('../js-fu.js', code.main, function() {
+ sys.puts("js-fu.js generated successfully!");
+});
+
+// generate library for demos
+fs.writeFile('../examples/js/js-fu.js', code.main, function() {
+ sys.puts("../examples/js/js-fu.js generated successfully!");
+});
+
+
+/* setup docs object */
+docs.main = '';
+docs.API = '';
+docs.dateTimeFu = '';
+docs.main += fs.readFileSync('./docs/index.js', encoding='utf8');
+docs.dateTimeFu += fs.readFileSync('./docs/dateTime.js', encoding='utf8');
sys.puts(JSON.stringify(fuMethods));
// instead of building the library in a linear fashion, we are going to split up methods
// based on their fu discipline
// store the methods in a variable as we parse
-
function docsTree(level){
-
// generate nice tree of api for docs
docs.API += '<ul>';
for(var method in level){
@@ -122,22 +131,6 @@ docs.toFu += ('</ul>');
docs.formatFu += ('</ul>');
docs.getFu += ('</ul>');
-
-// exports hack for dual sided stuff
-// if we are running in a CommonJS env, export everything out
-code.main += 'if(typeof exports != "undefined"){for(var prop in fu){exports[prop] = fu[prop];}}';
-code.main += 'Date.prototype.format = function (mask, utc) {return fu.dateFormat(this, mask, utc);}';
-// generate some samples sets (move this code to another section)
-fs.writeFile('../js-fu.js', code.main, function() {
- sys.puts("js-fu.js generated successfully!");
-});
-
-// generate library for demos
-fs.writeFile('../examples/js/js-fu.js', code.main, function() {
- sys.puts("../examples/js/js-fu.js generated successfully!");
-});
-
-
var docOutput = M.Mustache.to_html(docs.main, {
"API":docs.API
,"isFu":docs.isFu
View
@@ -1,4 +1,4 @@
-/*************** AUTOGENERATED @ 1276972091411 ***************
+/*************** AUTOGENERATED @ 1276975543355 ***************
WARNING: THIS FILE WAS AUTOGENERATED BY THE JS-FU BUILD SCRIPT
MODIFYING THIS FILE IS FINE, BUT YOU REALLY SHOULD BE MODIFYING
THE LIBRARY DIRECTLY AND REGENERATING THIS FILE USING BUILD.js!!!!
@@ -7,6 +7,7 @@
*/
var fu = {};
fu.version = "0.0.1";
+
fu.isDefined = function ( objecty ){
if(typeof objecty == 'undefined'){
return false;
@@ -1772,4 +1773,11 @@ fu.getIndex = function ( array, item ){
fu.getFunctions = function ( object ){
// todo add check for iterating through an object and returning an array of all functions (isFunction())
};
+fu.linq = function (dataItems) {
+ if (!(this instanceof JSLINQ)) {
+ return new JSLINQ(dataItems);
+ }
+
+ this.items = dataItems;
+ };
if(typeof exports != "undefined"){for(var prop in fu){exports[prop] = fu[prop];}}Date.prototype.format = function (mask, utc) {return fu.dateFormat(this, mask, utc);}
View
@@ -5,7 +5,7 @@ exports.isFu = require('./lib/isFu');
exports.toFu = require('./lib/toFu');
exports.dateTimeFu = require('./lib/dateTimeFu');
exports.getFu = require('./lib/getFu');
-//exports.linq = require('./lib/JSLINQ');
+exports.linq = require('./lib/JSLINQ');
// For convenience...
Date.prototype.format = function (mask, utc) {
View
@@ -1,4 +1,4 @@
-/*************** AUTOGENERATED @ 1276972091411 ***************
+/*************** AUTOGENERATED @ 1276975543355 ***************
WARNING: THIS FILE WAS AUTOGENERATED BY THE JS-FU BUILD SCRIPT
MODIFYING THIS FILE IS FINE, BUT YOU REALLY SHOULD BE MODIFYING
THE LIBRARY DIRECTLY AND REGENERATING THIS FILE USING BUILD.js!!!!
@@ -7,6 +7,7 @@
*/
var fu = {};
fu.version = "0.0.1";
+
fu.isDefined = function ( objecty ){
if(typeof objecty == 'undefined'){
return false;
@@ -1772,4 +1773,11 @@ fu.getIndex = function ( array, item ){
fu.getFunctions = function ( object ){
// todo add check for iterating through an object and returning an array of all functions (isFunction())
};
+fu.linq = function (dataItems) {
+ if (!(this instanceof JSLINQ)) {
+ return new JSLINQ(dataItems);
+ }
+
+ this.items = dataItems;
+ };
if(typeof exports != "undefined"){for(var prop in fu){exports[prop] = fu[prop];}}Date.prototype.format = function (mask, utc) {return fu.dateFormat(this, mask, utc);}

0 comments on commit 6b4d524

Please sign in to comment.