chore(sources): intro modules_dart; move analyzer code there

We have Dart code in `angular2` module that ought to be in its own
package. Examples include Dart analysis plugins, and potentially the
transformers (although transformers cannot be moved out just yet).
However, this code is Dart-only and it doesn’t make sense to use JS
directory layout for it. This commit introduces a sub-directory called
`modules_dart`. All modules in this directory are pure Dart packages
using standard pub directory layout. The code in these packages never
gets transpiled. It is directly copied to `dist` unmodified, except an
adjustment in relative paths in `pubspec.yaml` files.
This commit is contained in:
Yegor Jbanov 2015-04-23 17:37:05 -07:00
parent 4bab25b366
commit 87cf434929
6 changed files with 89 additions and 1 deletions

View File

@ -508,9 +508,67 @@ gulp.task('test.transpiler.unittest', function() {
// -----------------
// orchestrated targets
// Pure Dart packages only contain Dart code and conform to pub package layout.
// These packages need no transpilation. All code is copied over to `dist`
// unmodified and directory structure is preserved.
//
// This task also fixes relative `dependency_overrides` paths in `pubspec.yaml`
// files.
gulp.task('build/pure-packages.dart', function() {
var through2 = require('through2');
var yaml = require('js-yaml');
var originalPrefix = '../../dist/dart/';
return gulp
.src([
'modules_dart/**/*.dart',
'modules_dart/**/pubspec.yaml',
])
.pipe(through2.obj(function(file, enc, done) {
if (file.path.endsWith('pubspec.yaml')) {
// Pure packages specify dependency_overrides relative to
// `modules_dart`, so they have to walk up and into `dist`.
//
// Example:
//
// dependency_overrides:
// angular2:
// path: ../../dist/dart/angular2
//
// When we copy a pure package into `dist` the relative path
// must be updated. The code below replaces paths accordingly.
// So the example above is turned into:
//
// dependency_overrides:
// angular2:
// path: ../angular2
//
var pubspec = yaml.safeLoad(file.contents.toString());
var overrides = pubspec['dependency_overrides'];
if (overrides) {
Object.keys(overrides).forEach(function(pkg) {
var overridePath = overrides[pkg]['path'];
if (overridePath.startsWith(originalPrefix)) {
overrides[pkg]['path'] = overridePath.replace(originalPrefix, '../');
}
});
file.contents = new Buffer(yaml.safeDump(pubspec));
}
}
this.push(file);
done();
}))
.pipe(gulp.dest('dist/dart'));
});
// Builds all Dart packages, but does not compile them
gulp.task('build/packages.dart', function(done) {
runSequence('build/tree.dart', 'build/format.dart', done);
runSequence(
'build/tree.dart',
// Run after 'build/tree.dart' because broccoli clears the dist/dart folder
'build/pure-packages.dart',
'build/format.dart',
done);
});
// Builds and compiles all Dart packages

View File

@ -0,0 +1,11 @@
name: angular2_analysis_plugin
version: 0.0.0
description: Dart analyzer plugin for Angular 2
environment:
sdk: '>=1.9.0-dev.8.0'
dependencies:
angular2: '0.0.0'
analyzer: '^0.24.4'
dependency_overrides:
angular2:
path: ../../dist/dart/angular2

View File

@ -0,0 +1,7 @@
name: angular2_analysis_server
version: 0.0.0
description: Dart analyzer server plugin for Angular 2
environment:
sdk: '>=1.9.0-dev.8.0'
dependencies:
analyzer: '^0.24.4'

View File

@ -15,4 +15,16 @@ var doc = yaml.safeLoad(fs.readFileSync(pubspecFile, 'utf8'));
// Pub does not allow publishing with dependency_overrides
delete doc['dependency_overrides'];
// Overwrite temporary values with real values
delete doc['version'];
delete doc['authors'];
delete doc['homepage']
var BASE_PACKAGE_JSON = require('../../package.json');
doc['version'] = BASE_PACKAGE_JSON.version;
doc['homepage'] = BASE_PACKAGE_JSON.homepage;
doc['authors'] = Object.keys(BASE_PACKAGE_JSON.contributors).map(function(name) {
return name + ' <' + BASE_PACKAGE_JSON.contributors[name] + '>';
});
fs.writeFileSync(pubspecFile, yaml.safeDump(doc));