Skip to content
Browse files

gets build working again... horray now just everything else has to wo…

…rk :P
  • Loading branch information...
1 parent eaea4e0 commit 08a0b543788f258f20f151a1e75be3b3db8ad8f1 @fat fat committed Jul 4, 2011
Showing with 71 additions and 59 deletions.
  1. 0 bin/ender
  2. +2 −1 doc/styleguide.md
  3. +11 −4 lib/ender.cmd.js
  4. +4 −4 lib/ender.docs.js
  5. +48 −46 lib/ender.file.js
  6. +1 −1 lib/ender.get.js
  7. +5 −3 lib/ender.npm.js
View
0 bin/ender 100644 → 100755
File mode changed.
View
3 doc/styleguide.md
@@ -350,4 +350,5 @@ so that's where they belong.
## SMALL LITTLE NITS
- **RULE**: No spaces around brackets: ['foo', 'bar', 'baz']
-- **RULE**: Single quotes > double quotes
+- **RULE**: Single quotes > double quotes
+- **RULE**: there should be a space seperating // and comment text
View
15 lib/ender.cmd.js
@@ -17,12 +17,12 @@ module.exports = {
for (i = cmdOptions.length; i--;) {
option = cmdOptions[i]
- size = 1
+ size = 0
if (option == '-o' || option == '--output') {
option = 'output'
value = args[i + 1] && args[i + 1].replace(/\.js$/, '')
size = 2
- } else if option == '--use' || option == '-u') {
+ } else if (option == '--use' || option == '-u') {
option = 'use'
value = args[i + 1] && args[i + 1].replace(/\.js$/, '')
size = 2
@@ -33,18 +33,25 @@ module.exports = {
} else if (option == '--noop' || option == '-x'){
option = 'noop'
value = true
+ size = 1
} else if (option == '--silent' || option == '-s') {
option = 'silent'
value = true
+ size = 1
} else if (option == '--help') {
option = 'help'
value = true
+ size = 1
} else if (option == '--sans') {
option = 'sans'
value = true
+ size = 1
+ }
+
+ if (size) {
+ options[option] = value
+ cmdOptions.splice(i, size)
}
- options[option] = value
- cmdOptions.splice(i, size)
}
for (i in options) {
View
8 lib/ender.docs.js
@@ -96,12 +96,12 @@ var ENDER = {
}
}
-module.exports = ENDER.util.merge(Ender.docs, {
+module.exports = ENDER.util.merge(ENDER.docs, {
- 'rm': Ender.docs.remove
+ 'rm': ENDER.docs.remove
- , 'ls': Ender.docs.info
+ , 'ls': ENDER.docs.info
- , 'list': Ender.docs.info
+ , 'list': ENDER.docs.info
});
View
94 lib/ender.file.js
@@ -6,10 +6,9 @@ var fs = require('fs')
, ENDER = {
util: require('./ender.util')
, get: require('./ender.get')
- , file: module.exports
}
-module.exports = {
+ENDER.file = module.exports = {
getComment: function (context) {
return (
@@ -23,16 +22,19 @@ module.exports = {
, " * Build: ender " + context
, " * ======================================================="
, " */"
- ].join('\n') + '\n\n'
+ ].join('\n')
)
}
, uglify: function (source, filename, context, callback) {
try {
- var comments = [],
+ var comments = []
, token = '"Ender: preserved comment block"'
, reMultiComments = /\/\*![\s\S]*?\*\//g
- , reTokens = RegExp(token, 'g')
+
+ // we add a comma because uglify does too
+ , reTokens = RegExp(token + ',', 'g')
+
, tok
, ast
, c
@@ -53,12 +55,12 @@ module.exports = {
source = uglifyJS.uglify.gen_code(ast)
source = source.replace(reTokens, function() {
- return '\n' + comments.shift() + '\n';
+ return '\n' + comments.shift() + '\n'
})
- FILE.output(source, filename, context, callback)
+ ENDER.file.output(source, filename, context, callback)
} catch (e) {
- console.log('Ender was unable to minify your library with UglifyJS!'.red);
+ console.log('Ender was unable to minify your library with UglifyJS!'.red)
console.log('This usually means you have a js syntax error in one of your packages.')
}
}
@@ -67,7 +69,7 @@ module.exports = {
filename = filename || 'ender'
filename += '.js'
- fs.writeFile(filename, (this.getComment(context) + data), encoding='utf8', function (err) {
+ fs.writeFile(filename, ([ENDER.file.getComment(context), data].join('\n\n')), encoding='utf8', function (err) {
if (err) {
console.log('Something went wrong trying to write to ' + filename + '.')
return callback(err)
@@ -83,11 +85,11 @@ module.exports = {
path.exists(file, function (exists) {
if (exists) {
- async.waterfall({
+ async.waterfall([
async.apply(fs.readFile, file, 'utf-8')
, ENDER.file.gzip
, writeSize
- })
+ ])
} else if(/\.min\.js$/.test(file)) {
console.log('Active Ender library couldn\'t be found.')
callback(new Error)
@@ -116,7 +118,7 @@ module.exports = {
} else {
callback()
}
- });
+ })
}
, gzip: function (_data, callback) {
@@ -133,7 +135,7 @@ module.exports = {
console.log('assembling packages...')
packages = packages.map(function (item) { return item.replace(/@.*/, '') })
- FILE.processPackages(packages, options, function (err, result) {
+ ENDER.file.processPackages(packages, options, function (err, result) {
callback(null, result.join('\n\n'))
})
}
@@ -169,7 +171,7 @@ module.exports = {
uniques = uniques || []
for (packageName in tree) {
- if (~uniques.indexOf(k)) {
+ if (~uniques.indexOf(packageName)) {
continue
}
@@ -180,7 +182,7 @@ module.exports = {
} else if (packageValue) {
flattenedTree = this.flattenDependencyTree(packageValue, uniques)
flattenedTree = flattenedTree.map(function (treeItem) {
- return treeItem.indexOf('@') ? [packageName, treeItem].join('/') : treeItem.replace(/^@/, '');
+ return treeItem.indexOf('@') ? [packageName, treeItem].join('/') : treeItem.replace(/^@/, '')
})
packages = packages.concat(flattenedTree)
}
@@ -190,7 +192,7 @@ module.exports = {
}
if (callback) {
- return orderFlattenedTree(packages, uniques, callback);
+ return ENDER.file.orderFlattenedTree(packages, uniques, callback)
}
return packages
@@ -205,7 +207,7 @@ module.exports = {
, packageMatcher
, lookahead
- while (++i < l) {
+ for (i; i < l; i++) {
packageName = packages[i]
packageMatcher = RegExp('^' + packageName)
@@ -262,24 +264,20 @@ module.exports = {
packagePath = /^[\/.]/.test(packageName) ? path.join(packageName, 'package.json') : path.join(dir, packageName, 'package.json')
isInstallingFromRoot = packageName == '.' || packageName == './'
- async.waterfall({
+ async.waterfall([
async.apply(fs.readFile, packagePath, 'utf-8')
- , function (data, cb) { findDependencies(data, tree, dir, cb) }
+ , function (data, cb) { ENDER.file.findDependencies(data, tree, dir, isInstallingFromRoot, cb) }
, function () { if (++x == packages.length) { callback(null, tree) } }
- })
+ ])
})
}
-, findDependencies: function (data, tree, directory, callback) {
+, findDependencies: function (data, tree, directory, isInstallingFromRoot, callback) {
var packageJSON
, dependencies
, packageJSON
, dependencies
- if (err) {
- return console.log('something went wrong while trying to read ' + packagePath);
- }
-
packageJSON = JSON.parse(data)
packageName = packageJSON.name
dependencies = packageJSON.dependencies
@@ -302,21 +300,21 @@ module.exports = {
path.exists(directory, function (exists) {
if (exists) {
- return fs.readdir(directory, function () {
- dependencyFromDirectory (directory, filenames)
+ return fs.readdir(directory, function (err, filenames) {
+ dependencyFromDirectories(err, packageName, directory, filenames)
})
} else if (dependencies.length) {
- tree[packageName] = tree[packageName] || {};
+ tree[packageName] = tree[packageName] || {}
dependencies.forEach(function (item) {
- tree[name][item] = -1;
- });
+ tree[name][item] = -1
+ })
} else {
- tree[packageName] = 0;
+ tree[packageName] = 0
}
callback(null, tree)
})
- function dependencyFromDirectories(directory, filenames) {
+ function dependencyFromDirectories(err, packageName, directory, filenames) {
if (err) {
console.log('something went wrong while trying to read ' + _dir)
return callback(err)
@@ -328,7 +326,7 @@ module.exports = {
if (filenames.length != dependencies.length) {
UTIL.reject(dependencies, filenames).forEach(function (item) {
tree[packageName][item] = -1
- });
+ })
}
callback(null, tree)
})
@@ -339,39 +337,42 @@ module.exports = {
, processPackages: function (packages, options, callback) {
var result = []
- , packagesCompleteCount
+ , packagesCompleteCount = 0
+ , flattenedPackageLength
- async.waterfall({
+ async.waterfall([
async.apply(ENDER.file.constructDependencyTree, packages, 'node_modules')
- , function (tree, cb) { ENDER.file.flattenDependencyTree(tree, null, cb)}
+ , function (tree, cb) { ENDER.file.flattenDependencyTree(tree, null, cb) }
, proccessPackageJSONs
- })
+ ])
function proccessPackageJSONs(packages) {
+ flattenedPackageLength = packages.length
+
packages.forEach(function (packageName, index) {
var packagePath = path.join('node_modules', packageName.replace(/\//g, '/node_modules/'))
, packageJSONLocation = path.join(packagePath, 'package.json')
path.exists(packageJSONLocation, function (exists) {
if (!exists) {
- if (packages.length == ++packagesCompleteCount) {
+ if (++packagesCompleteCount == flattenedPackageLength) {
callback(result)
}
- return console.log('The package.json for ' + name.red + ' could not be found.'.yellow)
+ return console.log('The package.json for ' + packageName.red + ' could not be found.'.yellow)
}
- fs.readFile(location, 'utf-8', function (err, data) { gatherSource(packageName, index, data) })
+ fs.readFile(packageJSONLocation, 'utf-8', function (err, data) { gatherSource(err, packageName, packagePath, index, data) })
})
})
}
- function gatherSource(packageName, index, data) {
+ function gatherSource(err, packageName, packagePath, index, data) {
var packageJSON
, parallelQue
, source
if (err) {
- return console.log('something whent wrong trying to read ' + err.path);
+ return console.log('something whent wrong trying to read ' + err.path)
}
packageJSON = JSON.parse(data)
@@ -406,10 +407,11 @@ module.exports = {
result[index] = source
- if (packages.length == ++packagesCompleteCount) {
+ if (++packagesCompleteCount == flattenedPackageLength) {
callback && callback(null, result)
}
})
+ }
}
, constructSource: function(packagePath, filePaths, callback) {
@@ -421,7 +423,7 @@ module.exports = {
filePaths.forEach(function (filePath) {
if (!(/\.js$/.test(filePath))) {
- filePath += '.js';
+ filePath += '.js'
}
fs.readFile(path.join(packagePath, filePath), 'utf-8', function (err, data) {
if (err) {
@@ -438,14 +440,14 @@ module.exports = {
, constructBridge: function (packagePath, bridge, callback) {
if (!bridge || bridge == 'noop') {
- return callback && callback(null, '');
+ return callback && callback(null, '')
}
fs.readFile(path.join(packagePath, bridge), 'utf-8', function (err, data) {
if (err) {
callback(err)
return console.log('somethign went wrong trying to read ' + path.join(packagePath, bridge))
}
- callback && callback(data)
+ callback && callback(null, data)
})
}
View
2 lib/ender.get.js
@@ -30,7 +30,7 @@ module.exports = {
callback(err)
return console.log('something went wrong trying to read' + file + '.js')
}
- callback(null, data.match(/\*\sBuild:\s([^\n]*)/)[1]))
+ callback(null, data.match(/\*\sBuild:\s([^\n]*)/)[1])
})
}
}
View
8 lib/ender.npm.js
@@ -114,8 +114,10 @@ module.exports = {
console.log('this can take a minute...'.yellow)
npm.load({ logfd: null, outfd: null }, function (err) {
if (err) return console.log('something went wrong trying to load npm!'.red)
- npm.commands.install(packages, function (err, data)
- if (err) return console.log('something went wrong install your packags!'.red)
+ npm.commands.install(packages, function (err, data) {
+ if (err) {
+ return console.log('something went wrong install your packags!'.red)
+ }
var localInstall = packages.some(function (item) {
// this is a hack because of REEEIDD! DAMN YOU REEIIDD!
@@ -134,7 +136,7 @@ module.exports = {
console.log('invalid package specified... please check your spelling and try again.'.red)
return callback && callback(err)
}
- NPM.log('successfully finished installing packages')
+ console.log('successfully finished installing packages')
callback && callback()
}
})

0 comments on commit 08a0b54

Please sign in to comment.
Something went wrong with that request. Please try again.