angular/tools/js2dart/gulp-traceur.js
Vojta Jina c3b442ea53 chore: karma with JS, Dart
Note: karma with dart is still not working
because of how `karma-dart` loads `package:…` dependencies.

Usage:
```
karma start karma-js.conf.js
karma start karma-dart.conf.js
```

Make sure to set `DARTIUM_BIN` env variable.

Refactors `js2dart`:
- live outside of the traceur module (`tools/js2dart/index.js`)
  so it can be reused by gulp and karma
- automatically build the sources in memory,
  so that `js2dart` can be used without running `gulp build` first
- provide a way to specify the moduleName of a compilation run
  independently of the input filename. This helps error messages
  and source maps (not yet enabled) to report the correct file name

Changes project setup:
- add module `test_lib` that contains the primitives for tests
  (e.g. `describe`, `it`, …)
- clean up some sources that had errors in them
- module names in transpiled js and dart files don’t contain
  `lib`, `test` nor `src` any more (e.g. `di/di`).
2014-09-26 16:53:54 -07:00

41 lines
1.0 KiB
JavaScript

'use strict';
var through = require('through2');
var compiler = require('./index');
module.exports = gulpTraceur;
gulpTraceur.RUNTIME_PATH = compiler.RUNTIME_PATH;
gulpTraceur.sourcesChanged = compiler.sourcesChanged;
function gulpTraceur(options, resolveModuleName) {
options = options || {};
return through.obj(function (file, enc, done) {
if (file.isNull()) {
done();
return;
}
if (file.isStream()) {
throw new Error('gulp-traceur: Streaming not supported');
}
try {
var moduleName = resolveModuleName ? resolveModuleName(file.relative) : null;
var compiled = compiler.compile(options, {
inputPath: file.relative,
outputPath: file.relative,
moduleName: moduleName
}, file.contents.toString());
file.contents = new Buffer(compiled);
this.push(file);
done();
} catch (errors) {
if (errors.join) {
throw new Error('gulp-traceur: '+errors.join('\n'));
} else {
throw errors;
}
}
});
};