From adabe828f2358d6f9b4aa8b5766640a0e9ebaece Mon Sep 17 00:00:00 2001 From: Marak Squires Date: Sat, 15 May 2010 05:18:18 -0400 Subject: cleaning up directories, creating BUILD script --- BUILD.js | 4 ---- BUILD/BUILD.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ BUILD/main.js | 4 ++++ generateSet.js | 0 helper.js | 48 ------------------------------------------------ index.js | 2 +- lib/address.js | 2 +- lib/company.js | 2 +- lib/helper.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/internet.js | 2 +- lib/lorem.js | 2 +- lib/name.js | 2 +- lib/phone_number.js | 2 +- sampleSets/test.js | 0 14 files changed, 104 insertions(+), 59 deletions(-) delete mode 100644 BUILD.js create mode 100644 BUILD/BUILD.js create mode 100644 BUILD/main.js delete mode 100644 generateSet.js delete mode 100644 helper.js create mode 100644 lib/helper.js create mode 100644 sampleSets/test.js diff --git a/BUILD.js b/BUILD.js deleted file mode 100644 index 50050bff..00000000 --- a/BUILD.js +++ /dev/null @@ -1,4 +0,0 @@ -// create exports wrapper - -// parse entire lib directory and concat it into one file for the browser - diff --git a/BUILD/BUILD.js b/BUILD/BUILD.js new file mode 100644 index 00000000..f7c7a106 --- /dev/null +++ b/BUILD/BUILD.js @@ -0,0 +1,45 @@ +var sys = require('sys') + , fs = require('fs'); + +var code = ''; + +// read in the the main.js file as our main boilerplate code +code += fs.readFileSync('./main.js', encoding='utf8'); + +// parse entire lib directory and concat it into one file for the browser +var lib = paths('./lib'); + +sys.puts(JSON.stringify(lib)); + +// generate some samples sets (move this code to another section) + +/*********************** BUILD HELPER METHODS *********************/ + + // Recursively traverse a hierarchy, returning a list of all relevant .js files. + function paths(dir) { + var paths = []; + + try { fs.statSync(dir) } + catch (e) { return e } + + (function traverse(dir, stack) { + stack.push(dir); + fs.readdirSync(stack.join('/')).forEach(function (file) { + var path = stack.concat([file]).join('/'), + stat = fs.statSync(path); + + if (file[0] == '.' || file === 'vendor') { + return; + } else if (stat.isFile() && /\.js$/.test(file)) { + paths.push(path); + } else if (stat.isDirectory()) { + paths.push(path); + traverse(file, stack); + } + }); + stack.pop(); + })(dir || '.', []); + + return paths; + } + diff --git a/BUILD/main.js b/BUILD/main.js new file mode 100644 index 00000000..bd1dc117 --- /dev/null +++ b/BUILD/main.js @@ -0,0 +1,4 @@ +// this is just boilerplate code for generating the actual mustache-rides.js file, do not use this outside of node_builder.js +var Faker = {}; + +Faker.version = "0.0.1"; diff --git a/generateSet.js b/generateSet.js deleted file mode 100644 index e69de29b..00000000 diff --git a/helper.js b/helper.js deleted file mode 100644 index 49086a6b..00000000 --- a/helper.js +++ /dev/null @@ -1,48 +0,0 @@ -(function (Helper) { - -// returns a single random number based on a range -Helper.randomNumber = function(range) { - r = Math.floor(Math.random()*range); - return r; -}; - -// takes an array and returns the array randomly sorted -Helper.randomize = function(array) { - r = Math.floor(Math.random()*array.length); - return array[r]; -}; - -// parses string for a symbol and replace it with a random number from 1-10 -Helper.replaceSymbolWithNumber = function(string, symbol){ - - // default symbol is '#' - if(typeof symbol == 'undefined'){ - var symbol = '#'; - } - - var str = ''; - for(var i = 0; i < string.length; i++){ - if(string[i] == symbol){ - str += Math.floor(Math.random()*10); - } - else{ - str += string[i]; - } - } - return str; -}; - -// takes an array and returns it randomized -Helper.shuffle = function(o){ - for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x); - return o; -}; - -})( - // exports will be set in any commonjs platform; use it if it's available - typeof exports !== "undefined" ? - exports : - // otherwise construct a name space. outside the anonymous function, - // "this" will always be "window" in a browser, even in strict mode. - this.window = {} -); \ No newline at end of file diff --git a/index.js b/index.js index 92e3f85d..47331d56 100644 --- a/index.js +++ b/index.js @@ -12,7 +12,7 @@ Faker.Company = require('./lib/company'); Faker.Lorem = require('./lib/lorem'); -var Helper = require('helper');; +var Helper = require('./lib/helper');; sys.puts(JSON.stringify(Faker.Name.first_name())); sys.puts(JSON.stringify(Faker.Name.findName())); diff --git a/lib/address.js b/lib/address.js index bfd786b6..1b96819f 100644 --- a/lib/address.js +++ b/lib/address.js @@ -1,4 +1,4 @@ -var Helper = require('../helper'); +var Helper = require('./helper'); var definitions = require('../lib/definitions'); exports.zipCode = function() { diff --git a/lib/company.js b/lib/company.js index 3cd31594..d01eace6 100644 --- a/lib/company.js +++ b/lib/company.js @@ -1,4 +1,4 @@ -var Helper = require('../helper'); +var Helper = require('./helper'); var definitions = require('../lib/definitions'); exports.companyName = function() { diff --git a/lib/helper.js b/lib/helper.js new file mode 100644 index 00000000..49086a6b --- /dev/null +++ b/lib/helper.js @@ -0,0 +1,48 @@ +(function (Helper) { + +// returns a single random number based on a range +Helper.randomNumber = function(range) { + r = Math.floor(Math.random()*range); + return r; +}; + +// takes an array and returns the array randomly sorted +Helper.randomize = function(array) { + r = Math.floor(Math.random()*array.length); + return array[r]; +}; + +// parses string for a symbol and replace it with a random number from 1-10 +Helper.replaceSymbolWithNumber = function(string, symbol){ + + // default symbol is '#' + if(typeof symbol == 'undefined'){ + var symbol = '#'; + } + + var str = ''; + for(var i = 0; i < string.length; i++){ + if(string[i] == symbol){ + str += Math.floor(Math.random()*10); + } + else{ + str += string[i]; + } + } + return str; +}; + +// takes an array and returns it randomized +Helper.shuffle = function(o){ + for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x); + return o; +}; + +})( + // exports will be set in any commonjs platform; use it if it's available + typeof exports !== "undefined" ? + exports : + // otherwise construct a name space. outside the anonymous function, + // "this" will always be "window" in a browser, even in strict mode. + this.window = {} +); \ No newline at end of file diff --git a/lib/internet.js b/lib/internet.js index 9e7a8539..046ffa42 100644 --- a/lib/internet.js +++ b/lib/internet.js @@ -1,4 +1,4 @@ -var Helper = require('../helper'); +var Helper = require('./helper'); var definitions = require('./definitions'); exports.email = function() { diff --git a/lib/lorem.js b/lib/lorem.js index 7ba1b118..d9101e2c 100644 --- a/lib/lorem.js +++ b/lib/lorem.js @@ -1,4 +1,4 @@ -var Helper = require('../helper'); +var Helper = require('./helper'); var definitions = require('../lib/definitions'); exports.words = function(num){ diff --git a/lib/name.js b/lib/name.js index 37d92511..fa32d6e6 100644 --- a/lib/name.js +++ b/lib/name.js @@ -1,4 +1,4 @@ -var Helper = require('../helper'); +var Helper = require('./helper'); var definitions = require('./definitions'); exports.first_name = function(){ diff --git a/lib/phone_number.js b/lib/phone_number.js index 5537ff7e..975e47ad 100644 --- a/lib/phone_number.js +++ b/lib/phone_number.js @@ -1,4 +1,4 @@ -var Helper = require('../helper'); +var Helper = require('./helper'); var definitions = require('./definitions'); exports.phoneNumber = function(){ diff --git a/sampleSets/test.js b/sampleSets/test.js new file mode 100644 index 00000000..e69de29b -- cgit v1.2.3