Files
meteor/packages/ecmascript/plugin.js
Ben Newman 095ded40b0 Add an ecmascript core package.
This package will be installed by default for all new apps and packages.

Passing the {transpile:false} option to api.addFiles makes it possible for
a dependent package to specify that some files should not be processed
through babel-compiler.
2015-07-16 18:02:07 -04:00

47 lines
1.3 KiB
JavaScript

function BabelCompiler() {}
var BCp = BabelCompiler.prototype;
BCp.processFilesForTarget = function (inputFiles) {
inputFiles.forEach(function (inputFile) {
var source = inputFile.getContentsAsString();
var inputFilePath = inputFile.getPathInPackage();
var outputFilePath = inputFile.getPathInPackage();
var fileOptions = inputFile.getFileOptions();
var toBeAdded = {
sourcePath: inputFilePath,
path: outputFilePath,
data: source,
hash: inputFile.getSourceHash(),
sourceMap: null,
bare: !! fileOptions.bare
};
if (fileOptions.transpile !== false) {
var babelOptions = Babel.getDefaultOptions();
babelOptions.sourceMap = true;
babelOptions.filename = inputFilePath;
babelOptions.sourceFileName = "/" + inputFilePath;
babelOptions.sourceMapName = "/" + outputFilePath + ".map";
var result = Babel.compile(source, babelOptions);
toBeAdded.data = result.code;
toBeAdded.hash = result.hash;
toBeAdded.sourceMap = result.map;
}
inputFile.addJavaScript(toBeAdded);
});
};
BCp.setDiskCacheDirectory = function (cacheDir) {
Babel.setCacheDir(cacheDir);
};
Plugin.registerCompiler({
extensions: ['js'],
}, function () {
return new BabelCompiler();
});