Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add --sandbox option to build method for sandboxing your scripts

uses the `with` hack

accepts multiple optional packages after argument to define directly on the window object:

   build jeesh myPackage --sandbox myPackage
  • Loading branch information...
commit 58c558ea7c2501284df891aa2c8a8eeaf4038eee 1 parent cdef3e5
@fat fat authored
Showing with 27 additions and 5 deletions.
  1. +11 −0 lib/ender.cmd.js
  2. +15 −4 lib/ender.file.js
  3. +1 −1  package.json
View
11 lib/ender.cmd.js
@@ -13,7 +13,10 @@ module.exports = {
, option
, value
, size
+ , opts
, i
+ , j
+ , l
for (i = cmdOptions.length; i--;) {
option = cmdOptions[i]
@@ -30,6 +33,14 @@ module.exports = {
option = 'max'
value = cmdOptions[i + 1]
size = 2
+ } else if (option == '--sandbox') {
+ option = 'sandbox'
+ opts = cmdOptions.slice(i + 1)
+ for (j = 0, l = opts.length; j < l; j++) {
+ if (!opts[j].indexOf('-')) break
+ }
+ value = opts.splice(0, j)
+ size = 1 + value.length
} else if (option == '--noop' || option == '-x'){
option = 'noop'
value = true
View
19 lib/ender.file.js
@@ -133,7 +133,11 @@ ENDER.file = module.exports = {
packages = packages.map(function (item) { return item.replace(/@.*/, '') })
ENDER.file.processPackages(packages, options, function (err, result) {
- callback(null, result.join('\n\n'))
+ result = result.join('\n\n')
+ if (options.sandbox) {
+ result = ['!function () { with (this) {', result, '}}.call({});'].join('\n\n')
+ }
+ callback(null, result)
})
}
@@ -428,17 +432,24 @@ ENDER.file = module.exports = {
if (err && options.debug) throw err
var source = results.source
, content = results.content
+ , strippedName = packageName.replace(/.*(?=\/)\//, '')
if (source && packageName != 'ender-js' && !options.noop) {
source = [ '!function () {\n\n var module = { exports: {} }, exports = module.exports;'
, source.replace(/\n/g, '\n ')
- , 'provide("' + packageName.replace(/.*(?=\/)\//, '') + '", module.exports);'
+ , 'provide("' + strippedName + '", module.exports);'
]
- if (packageJSON.ender) {
+
+ if (options.sandbox && ~options.sandbox.indexOf(strippedName)) {
+ source.push('window["' + strippedName + '"] = module.exports;')
+ }
+
+ if (packageJSON.ender && content) {
source.push(content.replace(/\n/g, '\n '))
- } else {
+ } else if (!packageJSON.ender) {
source.push('$.ender(module.exports);')
}
+
source = source.join('\n\n ') + '\n\n}();'
}
View
2  package.json
@@ -1,7 +1,7 @@
{
"name": "ender",
"description": "next level JavaScript modules",
- "version": "0.7.0",
+ "version": "0.7.1",
"authors": ["Dustin Diaz <@ded>", "Jacob Thornton <@fat>"],
"keywords": ["ender", "modules", "builder", "framework", "packager"],
"main": "./lib/ender.js",
Please sign in to comment.
Something went wrong with that request. Please try again.