2014-09-25 17:04:46 -04:00
|
|
|
var js2dart = require('./index.js');
|
2014-09-25 20:55:46 -04:00
|
|
|
|
2014-09-25 17:04:46 -04:00
|
|
|
module.exports = {
|
|
|
|
'preprocessor:traceur': ['factory', createJs2DartPreprocessor]
|
|
|
|
};
|
2014-09-25 20:55:46 -04:00
|
|
|
|
2014-09-25 17:04:46 -04:00
|
|
|
function createJs2DartPreprocessor(logger, basePath, config) {
|
|
|
|
var log = logger.create('traceur');
|
2014-09-25 20:55:46 -04:00
|
|
|
|
|
|
|
return function(content, file, done) {
|
|
|
|
|
2014-09-25 17:04:46 -04:00
|
|
|
try {
|
|
|
|
var moduleName = config.resolveModuleName(file.originalPath);
|
|
|
|
if (config.transformPath) {
|
|
|
|
file.path = config.transformPath(file.originalPath);
|
|
|
|
}
|
|
|
|
done(null, js2dart.compile(config.options, {
|
|
|
|
inputPath: file.originalPath,
|
|
|
|
moduleName: moduleName
|
|
|
|
}, content));
|
|
|
|
} catch (errors) {
|
|
|
|
var errorString;
|
|
|
|
if (errors.forEach) {
|
|
|
|
errors.forEach(function(error) {
|
|
|
|
log.error(error);
|
|
|
|
});
|
|
|
|
errorString = errors.join('\n');
|
|
|
|
} else {
|
|
|
|
log.error(errors);
|
|
|
|
errorString = errors;
|
|
|
|
}
|
|
|
|
done(new Error('TRACEUR COMPILE ERRORS\n' + errorString));
|
2014-09-25 20:55:46 -04:00
|
|
|
}
|
|
|
|
};
|
2014-09-25 17:04:46 -04:00
|
|
|
}
|
2014-09-25 20:55:46 -04:00
|
|
|
|
2014-09-25 17:04:46 -04:00
|
|
|
createJs2DartPreprocessor.$inject = ['logger', 'config.basePath', 'config.traceurPreprocessor'];
|