-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
37 lines (27 loc) · 1020 Bytes
/
index.js
File metadata and controls
37 lines (27 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var Filter = require('broccoli-filter');
var Petal = require('petal');
var path = require('path');
var escodegen = require('escodegen');
module.exports = BroccoliRemap;
BroccoliRemap.prototype = Object.create(Filter.prototype);
BroccoliRemap.prototype.constructor = BroccoliRemap;
function BroccoliRemap (inputTree, options) {
if (!(this instanceof BroccoliRemap)) return new BroccoliRemap(inputTree, options);
Filter.call(this, inputTree, options);
this.options = options || {};
}
BroccoliRemap.prototype.extensions = ['js'];
BroccoliRemap.prototype.targetExtension = 'js';
BroccoliRemap.prototype.processString = function (source, destDir) {
var petal = new Petal(destDir, source);
if (petal.hasDefine() && petal.isAnonymous){
var name = this.options.name;
var fileName = path.basename(destDir, '.js');
if (fileName !== 'main') {
name = name + '/' + fileName;
}
var remaped = petal.remap(name);
source = escodegen.generate(remaped.ast);
}
return source;
};