add --amd option to generate ender.js as an AMD whole #158

Closed
wants to merge 2 commits into
from
View
@@ -41,6 +41,10 @@ module.exports = {
}
value = opts.splice(0, j)
size = 1 + value.length
+ } else if (option == '--amd') {
+ option = 'amd'
+ value = true
+ size = 1;
} else if (option == '--noop' || option == '-x'){
option = 'noop'
value = true
View
@@ -146,6 +146,8 @@ ENDER.file = module.exports = {
result = result.join('\n\n')
if (options.sandbox) {
result = ['(function () {', result, '}).call({});'].join('\n\n')
+ }else if (options.amd){
+ result = ['define(function(){\n\n var _ender = {}; \n\n (function () {', result, '}).call(_ender); \n\n return _ender.ender;\n});'].join('\n\n')
}
callback(null, result)
})
@@ -470,6 +472,16 @@ ENDER.file = module.exports = {
].join('\n')
}
+ if (options.amd && packageName == 'ender-js') {
+ source = ['/* Declare local API */',
+ 'var require, provide, $, ender;', '',
+ '/* Prevent any module here to register using AMDs "define" */',
+ 'var define = null;', '',
+ , source
+ , '\n/* Set Local API */\nrequire = this.require\nprovide = this.provide\nender = $ = this.ender;'
+ ].join('\n')
+ }
+
result[index] = source
if (++packagesCompleteCount == flattenedPackageLength) {