Skip to content

Commit 100d662

Browse files
committed
build: execute pub get and dart analyzer
When chaining a `pubspec.yaml` we automatically run `pub get`. In `gulp build` we also run `dartanalyzer` for all files that have the pattern: `<module>/lib/<module>.dart` Closes angular#13 Closes angular#5 Closes angular#2
1 parent b42111a commit 100d662

File tree

6 files changed

+139
-51
lines changed

6 files changed

+139
-51
lines changed

gulpfile.js

Lines changed: 69 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var runSequence = require('run-sequence');
99
var glob = require('glob');
1010
var ejs = require('gulp-ejs');
1111
var path = require('path');
12+
var through2 = require('through2');
1213

1314
// import js2dart build tasks
1415
var js2dartTasks = require('./tools/js2dart/gulp-tasks');
@@ -38,10 +39,10 @@ var traceur = require('./tools/js2dart/gulp-traceur');
3839
// rtts-assert and traceur runtime
3940

4041
gulp.task('jsRuntime/build', function() {
41-
return jsRuntime(false);
42+
return createJsRuntimeTask(false);
4243
});
4344

44-
function jsRuntime(isWatch) {
45+
function createJsRuntimeTask(isWatch) {
4546
var srcFn = isWatch ? watch : gulp.src.bind(gulp);
4647
var rttsAssert = srcFn('tools/rtts-assert/src/assert.js')
4748
.pipe(traceur(js2es5Options))
@@ -60,11 +61,20 @@ var sourceTypeConfigs = {
6061
},
6162
transpileSrc: ['modules/**/*.js'],
6263
htmlSrc: ['modules/*/src/**/*.html'],
63-
// TODO: execute pub get after a yaml changed and was copied over to 'build' folder
6464
copySrc: ['modules/**/*.dart', 'modules/**/*.yaml'],
6565
outputDir: 'build/dart',
6666
outputExt: 'dart',
67-
mimeType: 'application/dart'
67+
mimeType: 'application/dart',
68+
postProcess: function(file, done) {
69+
if (file.path.match(/pubspec\.yaml/)) {
70+
console.log(file.path);
71+
shell.task(['pub get'], {
72+
cwd: path.dirname(file.path)
73+
})().on('end', done);
74+
} else {
75+
done();
76+
}
77+
}
6878
},
6979
js: {
7080
compiler: function() {
@@ -74,46 +84,74 @@ var sourceTypeConfigs = {
7484
htmlSrc: ['modules/*/src/**/*.html'],
7585
copySrc: ['modules/**/*.es5'],
7686
outputDir: 'build/js',
77-
outputExt: 'js'
87+
outputExt: 'js',
88+
postProcess: function() {
89+
90+
}
7891
}
7992
};
8093

94+
8195
gulp.task('modules/clean', function() {
8296
return gulp.src('build', {read: false})
8397
.pipe(clean());
8498
});
8599

100+
gulp.task('modules/build.dart/src', function() {
101+
return createModuleTask(sourceTypeConfigs.dart, false);
102+
});
103+
104+
gulp.task('modules/build.dart/analyzer', function() {
105+
var baseDir = sourceTypeConfigs.dart.outputDir;
106+
var files = [].slice.call(glob.sync('*/lib/*.dart', {
107+
cwd: baseDir
108+
}));
109+
files = files.filter(function(fileName) {
110+
return fileName.match(/(\w+)\/lib\/\1/);
111+
});
112+
var commands = files.map(function(fileName) {
113+
return 'dartanalyzer '+baseDir+'/'+fileName
114+
});
115+
return shell.task(commands)();
116+
});
117+
118+
gulp.task('modules/build.dart', function(done) {
119+
runSequence('modules/build.dart/src', 'modules/build.dart/analyzer', done);
120+
});
121+
122+
gulp.task('modules/build.js', function() {
123+
return createModuleTask(sourceTypeConfigs.js, false);
124+
});
125+
86126
function renameSrcToLib(file) {
87127
file.dirname = file.dirname.replace(/\bsrc\b/, 'lib');
88128
}
89129

90130
function createModuleTask(sourceTypeConfig, isWatch) {
91131
var start = isWatch ? watch : gulp.src.bind(gulp);
92-
return function(done) {
93-
var transpile = start(sourceTypeConfig.transpileSrc)
94-
.pipe(rename({extname: '.'+sourceTypeConfig.outputExt}))
95-
.pipe(rename(renameSrcToLib))
96-
.pipe(sourceTypeConfig.compiler())
97-
.pipe(gulp.dest(sourceTypeConfig.outputDir));
98-
var copy = start(sourceTypeConfig.copySrc)
99-
.pipe(rename(renameSrcToLib))
100-
.pipe(gulp.dest(sourceTypeConfig.outputDir));
101-
// TODO: provide the list of files to the template
102-
// automatically!
103-
var html = start(sourceTypeConfig.htmlSrc)
104-
.pipe(rename(renameSrcToLib))
105-
.pipe(ejs({
106-
type: sourceTypeConfig.outputExt
107-
}))
108-
.pipe(gulp.dest(sourceTypeConfig.outputDir));
109-
110-
return mergeStreams(transpile, copy, html);
111-
};
132+
var transpile = start(sourceTypeConfig.transpileSrc)
133+
.pipe(rename({extname: '.'+sourceTypeConfig.outputExt}))
134+
.pipe(rename(renameSrcToLib))
135+
.pipe(sourceTypeConfig.compiler())
136+
.pipe(gulp.dest(sourceTypeConfig.outputDir));
137+
var copy = start(sourceTypeConfig.copySrc)
138+
.pipe(rename(renameSrcToLib))
139+
.pipe(gulp.dest(sourceTypeConfig.outputDir));
140+
// TODO: provide the list of files to the template
141+
// automatically!
142+
var html = start(sourceTypeConfig.htmlSrc)
143+
.pipe(rename(renameSrcToLib))
144+
.pipe(ejs({
145+
type: sourceTypeConfig.outputExt
146+
}))
147+
.pipe(gulp.dest(sourceTypeConfig.outputDir));
148+
149+
var s = mergeStreams(transpile, copy, html);
150+
return s.pipe(through2.obj(function(file, enc, done) {
151+
sourceTypeConfig.postProcess(file, done);
152+
}));
112153
}
113154

114-
gulp.task('modules/build.dart', createModuleTask(sourceTypeConfigs.dart, false));
115-
gulp.task('modules/build.js', createModuleTask(sourceTypeConfigs.js, false));
116-
117155
// ------------------
118156
// WEB SERVER
119157
gulp.task('serve', connect.server({
@@ -155,7 +193,7 @@ gulp.task('watch', function() {
155193
['jsRuntime/build', 'modules/build.dart', 'modules/build.js'],
156194
done);
157195
});
158-
var dartModuleWatch = createModuleTask(sourceTypeConfigs.dart, true)();
159-
var jsModuleWatch = createModuleTask(sourceTypeConfigs.js, true)();
160-
return mergeStreams(js2dartWatch, dartModuleWatch, jsModuleWatch, jsRuntime(true));
196+
var dartModuleWatch = createModuleTask(sourceTypeConfigs.dart, true);
197+
var jsModuleWatch = createModuleTask(sourceTypeConfigs.js, true);
198+
return mergeStreams(js2dartWatch, dartModuleWatch, jsModuleWatch, createJsRuntimeTask(true));
161199
});
File renamed without changes.

modules/di/pubspec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@ name: di
22
environment:
33
sdk: '>=1.4.0'
44
dependencies:
5+
facade:
6+
path: ../facade
57
dev_dependencies:
68
unittest: '>=0.10.1 <0.12.0'

modules/di/src/module.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {Type} from 'facade/lang';
22
import {Map, MapWrapper wraps Map} from 'facade/collection';
33

4-
/// becouse we need to know when toValue was not set.
5-
/// (it could be that toValue is set to null or undefined in js)
6-
var _UNDEFINED = {}
4+
/// becouse we need to know when toValue was not set.
5+
/// (it could be that toValue is set to null or undefined in js)
6+
var _UNDEFINED = {}
77

88
export class Module {
99

@@ -12,12 +12,12 @@ export class Module {
1212
this.bindings = new MapWrapper();
1313
}
1414

15-
bind(type:Type,
16-
{toValue=_UNDEFINED, toFactory, toImplementation, inject, toInstanceOf, withAnnotation}/*:
15+
bind(type:Type,
16+
{toValue/*=_UNDEFINED*/, toFactory, toImplementation, inject, toInstanceOf, withAnnotation}/*:
1717
{toFactory:Function, toImplementation: Type, inject: Array, toInstanceOf:Type}*/) {}
1818

19-
bindByKey(key:Key,
20-
{toValue=_UNDEFINED, toFactory, toImplementation, inject, toInstanceOf}/*:
19+
bindByKey(key:Key,
20+
{toValue/*=_UNDEFINED*/, toFactory, toImplementation, inject, toInstanceOf}/*:
2121
{toFactory:Function, toImplementation: Type, inject: Array, toInstanceOf:Type}*/) {}
2222

2323
install(module:Module) {}

modules/facade/test.dart

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
var traceur = require('traceur');
2+
3+
var createTraceurPreprocessor = function(args, config, logger, helper) {
4+
config = config || {};
5+
6+
var log = logger.create('preprocessor.traceur');
7+
var defaultOptions = {
8+
sourceMaps: false,
9+
modules: 'amd'
10+
};
11+
var options = helper.merge(defaultOptions, args.options || {}, config.options || {});
12+
13+
var transformPath = args.transformPath || config.transformPath || function(filepath) {
14+
return filepath.replace(/\.es6.js$/, '.js').replace(/\.es6$/, '.js');
15+
};
16+
17+
return function(content, file, done) {
18+
log.debug('Processing "%s".', file.originalPath);
19+
file.path = transformPath(file.originalPath);
20+
options.filename = file.originalPath;
21+
22+
var result = traceur.compile(content, options);
23+
var transpiledContent = result.js;
24+
25+
result.errors.forEach(function(err) {
26+
log.error(err);
27+
});
28+
29+
if (result.errors.length) {
30+
return done(new Error('TRACEUR COMPILE ERRORS\n' + result.errors.join('\n')));
31+
}
32+
33+
// TODO(vojta): Tracer should return JS object, rather than a string.
34+
if (result.generatedSourceMap) {
35+
var map = JSON.parse(result.generatedSourceMap);
36+
map.file = file.path;
37+
transpiledContent += '\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,';
38+
transpiledContent += new Buffer(JSON.stringify(map)).toString('base64') + '\n';
39+
40+
file.sourceMap = map;
41+
}
42+
43+
return done(null, transpiledContent);
44+
};
45+
};
46+
47+
createTraceurPreprocessor.$inject = ['args', 'config.traceurPreprocessor', 'logger', 'helper'];
48+
49+
50+
var initTraceurFramework = function(files) {
51+
files.unshift({pattern: traceur.RUNTIME_PATH, included: true, served: true, watched: false});
52+
};
53+
54+
initTraceurFramework.$inject = ['config.files'];
55+
56+
57+
// PUBLISH DI MODULE
58+
module.exports = {
59+
'preprocessor:traceur': ['factory', createTraceurPreprocessor],
60+
'framework:traceur': ['factory', initTraceurFramework]
61+
};

0 commit comments

Comments
 (0)