Merge pull request #176 from darvelo/master
Generate moduleNames for AMD/UMD
This commit is contained in:
commit
dadab64e39
@ -29,12 +29,39 @@ AMDFormatter.prototype.transform = function (ast) {
|
||||
var params = _.values(this.ids);
|
||||
params.unshift(t.identifier("exports"));
|
||||
|
||||
var moduleName = this.getModuleName(this.file);
|
||||
|
||||
var container = t.functionExpression(null, params, t.blockStatement(body));
|
||||
var call = t.callExpression(t.identifier("define"), [names, container]);
|
||||
var call = t.callExpression(t.identifier("define"), [t.literal(moduleName), names, container]);
|
||||
|
||||
program.body = [t.expressionStatement(call)];
|
||||
};
|
||||
|
||||
AMDFormatter.prototype.getModuleName = function (file) {
|
||||
var opts = file.opts,
|
||||
filenameRelative = opts.filenameRelative,
|
||||
sourceRootRegEx,
|
||||
moduleName;
|
||||
|
||||
if (opts.moduleRoot) {
|
||||
moduleName = opts.moduleRoot + '/';
|
||||
}
|
||||
|
||||
if (!opts.filenameRelative) {
|
||||
return moduleName + opts.filename.replace(/^\//, '');
|
||||
}
|
||||
|
||||
if (opts.sourceRoot) {
|
||||
sourceRootRegEx = new RegExp('^' + opts.sourceRoot + '\/?');
|
||||
filenameRelative = filenameRelative.replace(sourceRootRegEx, '');
|
||||
}
|
||||
|
||||
filenameRelative = filenameRelative.replace(/\.js$/, '');
|
||||
moduleName += filenameRelative;
|
||||
|
||||
return moduleName;
|
||||
};
|
||||
|
||||
AMDFormatter.prototype._push = function (node) {
|
||||
var id = node.source.value;
|
||||
var ids = this.ids;
|
||||
|
||||
@ -32,8 +32,10 @@ UMDFormatter.prototype.transform = function (ast) {
|
||||
|
||||
// runner
|
||||
|
||||
var moduleName = this.getModuleName(this.file);
|
||||
|
||||
var runner = util.template("umd-runner-body", {
|
||||
AMD_ARGUMENTS: t.arrayExpression([t.literal("exports")].concat(names)),
|
||||
AMD_ARGUMENTS: [t.literal(moduleName), t.arrayExpression([t.literal("exports")].concat(names))],
|
||||
|
||||
COMMON_ARGUMENTS: names.map(function (name) {
|
||||
return t.callExpression(t.identifier("require"), [name]);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user