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 #13 Closes #5 Closes #2
This commit is contained in:
parent
b42111a608
commit
100d66222c
98
gulpfile.js
98
gulpfile.js
|
@ -9,6 +9,7 @@ var runSequence = require('run-sequence');
|
||||||
var glob = require('glob');
|
var glob = require('glob');
|
||||||
var ejs = require('gulp-ejs');
|
var ejs = require('gulp-ejs');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
|
var through2 = require('through2');
|
||||||
|
|
||||||
// import js2dart build tasks
|
// import js2dart build tasks
|
||||||
var js2dartTasks = require('./tools/js2dart/gulp-tasks');
|
var js2dartTasks = require('./tools/js2dart/gulp-tasks');
|
||||||
|
@ -38,10 +39,10 @@ var traceur = require('./tools/js2dart/gulp-traceur');
|
||||||
// rtts-assert and traceur runtime
|
// rtts-assert and traceur runtime
|
||||||
|
|
||||||
gulp.task('jsRuntime/build', function() {
|
gulp.task('jsRuntime/build', function() {
|
||||||
return jsRuntime(false);
|
return createJsRuntimeTask(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
function jsRuntime(isWatch) {
|
function createJsRuntimeTask(isWatch) {
|
||||||
var srcFn = isWatch ? watch : gulp.src.bind(gulp);
|
var srcFn = isWatch ? watch : gulp.src.bind(gulp);
|
||||||
var rttsAssert = srcFn('tools/rtts-assert/src/assert.js')
|
var rttsAssert = srcFn('tools/rtts-assert/src/assert.js')
|
||||||
.pipe(traceur(js2es5Options))
|
.pipe(traceur(js2es5Options))
|
||||||
|
@ -60,11 +61,20 @@ var sourceTypeConfigs = {
|
||||||
},
|
},
|
||||||
transpileSrc: ['modules/**/*.js'],
|
transpileSrc: ['modules/**/*.js'],
|
||||||
htmlSrc: ['modules/*/src/**/*.html'],
|
htmlSrc: ['modules/*/src/**/*.html'],
|
||||||
// TODO: execute pub get after a yaml changed and was copied over to 'build' folder
|
|
||||||
copySrc: ['modules/**/*.dart', 'modules/**/*.yaml'],
|
copySrc: ['modules/**/*.dart', 'modules/**/*.yaml'],
|
||||||
outputDir: 'build/dart',
|
outputDir: 'build/dart',
|
||||||
outputExt: 'dart',
|
outputExt: 'dart',
|
||||||
mimeType: 'application/dart'
|
mimeType: 'application/dart',
|
||||||
|
postProcess: function(file, done) {
|
||||||
|
if (file.path.match(/pubspec\.yaml/)) {
|
||||||
|
console.log(file.path);
|
||||||
|
shell.task(['pub get'], {
|
||||||
|
cwd: path.dirname(file.path)
|
||||||
|
})().on('end', done);
|
||||||
|
} else {
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
js: {
|
js: {
|
||||||
compiler: function() {
|
compiler: function() {
|
||||||
|
@ -74,46 +84,74 @@ var sourceTypeConfigs = {
|
||||||
htmlSrc: ['modules/*/src/**/*.html'],
|
htmlSrc: ['modules/*/src/**/*.html'],
|
||||||
copySrc: ['modules/**/*.es5'],
|
copySrc: ['modules/**/*.es5'],
|
||||||
outputDir: 'build/js',
|
outputDir: 'build/js',
|
||||||
outputExt: 'js'
|
outputExt: 'js',
|
||||||
|
postProcess: function() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
gulp.task('modules/clean', function() {
|
gulp.task('modules/clean', function() {
|
||||||
return gulp.src('build', {read: false})
|
return gulp.src('build', {read: false})
|
||||||
.pipe(clean());
|
.pipe(clean());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
gulp.task('modules/build.dart/src', function() {
|
||||||
|
return createModuleTask(sourceTypeConfigs.dart, false);
|
||||||
|
});
|
||||||
|
|
||||||
|
gulp.task('modules/build.dart/analyzer', function() {
|
||||||
|
var baseDir = sourceTypeConfigs.dart.outputDir;
|
||||||
|
var files = [].slice.call(glob.sync('*/lib/*.dart', {
|
||||||
|
cwd: baseDir
|
||||||
|
}));
|
||||||
|
files = files.filter(function(fileName) {
|
||||||
|
return fileName.match(/(\w+)\/lib\/\1/);
|
||||||
|
});
|
||||||
|
var commands = files.map(function(fileName) {
|
||||||
|
return 'dartanalyzer '+baseDir+'/'+fileName
|
||||||
|
});
|
||||||
|
return shell.task(commands)();
|
||||||
|
});
|
||||||
|
|
||||||
|
gulp.task('modules/build.dart', function(done) {
|
||||||
|
runSequence('modules/build.dart/src', 'modules/build.dart/analyzer', done);
|
||||||
|
});
|
||||||
|
|
||||||
|
gulp.task('modules/build.js', function() {
|
||||||
|
return createModuleTask(sourceTypeConfigs.js, false);
|
||||||
|
});
|
||||||
|
|
||||||
function renameSrcToLib(file) {
|
function renameSrcToLib(file) {
|
||||||
file.dirname = file.dirname.replace(/\bsrc\b/, 'lib');
|
file.dirname = file.dirname.replace(/\bsrc\b/, 'lib');
|
||||||
}
|
}
|
||||||
|
|
||||||
function createModuleTask(sourceTypeConfig, isWatch) {
|
function createModuleTask(sourceTypeConfig, isWatch) {
|
||||||
var start = isWatch ? watch : gulp.src.bind(gulp);
|
var start = isWatch ? watch : gulp.src.bind(gulp);
|
||||||
return function(done) {
|
var transpile = start(sourceTypeConfig.transpileSrc)
|
||||||
var transpile = start(sourceTypeConfig.transpileSrc)
|
.pipe(rename({extname: '.'+sourceTypeConfig.outputExt}))
|
||||||
.pipe(rename({extname: '.'+sourceTypeConfig.outputExt}))
|
.pipe(rename(renameSrcToLib))
|
||||||
.pipe(rename(renameSrcToLib))
|
.pipe(sourceTypeConfig.compiler())
|
||||||
.pipe(sourceTypeConfig.compiler())
|
.pipe(gulp.dest(sourceTypeConfig.outputDir));
|
||||||
.pipe(gulp.dest(sourceTypeConfig.outputDir));
|
var copy = start(sourceTypeConfig.copySrc)
|
||||||
var copy = start(sourceTypeConfig.copySrc)
|
.pipe(rename(renameSrcToLib))
|
||||||
.pipe(rename(renameSrcToLib))
|
.pipe(gulp.dest(sourceTypeConfig.outputDir));
|
||||||
.pipe(gulp.dest(sourceTypeConfig.outputDir));
|
// TODO: provide the list of files to the template
|
||||||
// TODO: provide the list of files to the template
|
// automatically!
|
||||||
// automatically!
|
var html = start(sourceTypeConfig.htmlSrc)
|
||||||
var html = start(sourceTypeConfig.htmlSrc)
|
.pipe(rename(renameSrcToLib))
|
||||||
.pipe(rename(renameSrcToLib))
|
.pipe(ejs({
|
||||||
.pipe(ejs({
|
type: sourceTypeConfig.outputExt
|
||||||
type: sourceTypeConfig.outputExt
|
}))
|
||||||
}))
|
.pipe(gulp.dest(sourceTypeConfig.outputDir));
|
||||||
.pipe(gulp.dest(sourceTypeConfig.outputDir));
|
|
||||||
|
|
||||||
return mergeStreams(transpile, copy, html);
|
var s = mergeStreams(transpile, copy, html);
|
||||||
};
|
return s.pipe(through2.obj(function(file, enc, done) {
|
||||||
|
sourceTypeConfig.postProcess(file, done);
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
gulp.task('modules/build.dart', createModuleTask(sourceTypeConfigs.dart, false));
|
|
||||||
gulp.task('modules/build.js', createModuleTask(sourceTypeConfigs.js, false));
|
|
||||||
|
|
||||||
// ------------------
|
// ------------------
|
||||||
// WEB SERVER
|
// WEB SERVER
|
||||||
gulp.task('serve', connect.server({
|
gulp.task('serve', connect.server({
|
||||||
|
@ -155,7 +193,7 @@ gulp.task('watch', function() {
|
||||||
['jsRuntime/build', 'modules/build.dart', 'modules/build.js'],
|
['jsRuntime/build', 'modules/build.dart', 'modules/build.js'],
|
||||||
done);
|
done);
|
||||||
});
|
});
|
||||||
var dartModuleWatch = createModuleTask(sourceTypeConfigs.dart, true)();
|
var dartModuleWatch = createModuleTask(sourceTypeConfigs.dart, true);
|
||||||
var jsModuleWatch = createModuleTask(sourceTypeConfigs.js, true)();
|
var jsModuleWatch = createModuleTask(sourceTypeConfigs.js, true);
|
||||||
return mergeStreams(js2dartWatch, dartModuleWatch, jsModuleWatch, jsRuntime(true));
|
return mergeStreams(js2dartWatch, dartModuleWatch, jsModuleWatch, createJsRuntimeTask(true));
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,5 +2,7 @@ name: di
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=1.4.0'
|
sdk: '>=1.4.0'
|
||||||
dependencies:
|
dependencies:
|
||||||
|
facade:
|
||||||
|
path: ../facade
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
unittest: '>=0.10.1 <0.12.0'
|
unittest: '>=0.10.1 <0.12.0'
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import {Type} from 'facade/lang';
|
import {Type} from 'facade/lang';
|
||||||
import {Map, MapWrapper wraps Map} from 'facade/collection';
|
import {Map, MapWrapper wraps Map} from 'facade/collection';
|
||||||
|
|
||||||
/// becouse we need to know when toValue was not set.
|
/// becouse we need to know when toValue was not set.
|
||||||
/// (it could be that toValue is set to null or undefined in js)
|
/// (it could be that toValue is set to null or undefined in js)
|
||||||
var _UNDEFINED = {}
|
var _UNDEFINED = {}
|
||||||
|
|
||||||
export class Module {
|
export class Module {
|
||||||
|
|
||||||
|
@ -12,12 +12,12 @@ export class Module {
|
||||||
this.bindings = new MapWrapper();
|
this.bindings = new MapWrapper();
|
||||||
}
|
}
|
||||||
|
|
||||||
bind(type:Type,
|
bind(type:Type,
|
||||||
{toValue=_UNDEFINED, toFactory, toImplementation, inject, toInstanceOf, withAnnotation}/*:
|
{toValue/*=_UNDEFINED*/, toFactory, toImplementation, inject, toInstanceOf, withAnnotation}/*:
|
||||||
{toFactory:Function, toImplementation: Type, inject: Array, toInstanceOf:Type}*/) {}
|
{toFactory:Function, toImplementation: Type, inject: Array, toInstanceOf:Type}*/) {}
|
||||||
|
|
||||||
bindByKey(key:Key,
|
bindByKey(key:Key,
|
||||||
{toValue=_UNDEFINED, toFactory, toImplementation, inject, toInstanceOf}/*:
|
{toValue/*=_UNDEFINED*/, toFactory, toImplementation, inject, toInstanceOf}/*:
|
||||||
{toFactory:Function, toImplementation: Type, inject: Array, toInstanceOf:Type}*/) {}
|
{toFactory:Function, toImplementation: Type, inject: Array, toInstanceOf:Type}*/) {}
|
||||||
|
|
||||||
install(module:Module) {}
|
install(module:Module) {}
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
import 'dart:core' as core;
|
|
||||||
import 'dart:collection';
|
|
||||||
|
|
||||||
class Map {
|
|
||||||
|
|
||||||
new() => null;
|
|
||||||
|
|
||||||
ping() => core.print('map');
|
|
||||||
}
|
|
||||||
|
|
||||||
main() {
|
|
||||||
new Map().ping();
|
|
||||||
}
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
var traceur = require('traceur');
|
||||||
|
|
||||||
|
var createTraceurPreprocessor = function(args, config, logger, helper) {
|
||||||
|
config = config || {};
|
||||||
|
|
||||||
|
var log = logger.create('preprocessor.traceur');
|
||||||
|
var defaultOptions = {
|
||||||
|
sourceMaps: false,
|
||||||
|
modules: 'amd'
|
||||||
|
};
|
||||||
|
var options = helper.merge(defaultOptions, args.options || {}, config.options || {});
|
||||||
|
|
||||||
|
var transformPath = args.transformPath || config.transformPath || function(filepath) {
|
||||||
|
return filepath.replace(/\.es6.js$/, '.js').replace(/\.es6$/, '.js');
|
||||||
|
};
|
||||||
|
|
||||||
|
return function(content, file, done) {
|
||||||
|
log.debug('Processing "%s".', file.originalPath);
|
||||||
|
file.path = transformPath(file.originalPath);
|
||||||
|
options.filename = file.originalPath;
|
||||||
|
|
||||||
|
var result = traceur.compile(content, options);
|
||||||
|
var transpiledContent = result.js;
|
||||||
|
|
||||||
|
result.errors.forEach(function(err) {
|
||||||
|
log.error(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result.errors.length) {
|
||||||
|
return done(new Error('TRACEUR COMPILE ERRORS\n' + result.errors.join('\n')));
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(vojta): Tracer should return JS object, rather than a string.
|
||||||
|
if (result.generatedSourceMap) {
|
||||||
|
var map = JSON.parse(result.generatedSourceMap);
|
||||||
|
map.file = file.path;
|
||||||
|
transpiledContent += '\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,';
|
||||||
|
transpiledContent += new Buffer(JSON.stringify(map)).toString('base64') + '\n';
|
||||||
|
|
||||||
|
file.sourceMap = map;
|
||||||
|
}
|
||||||
|
|
||||||
|
return done(null, transpiledContent);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
createTraceurPreprocessor.$inject = ['args', 'config.traceurPreprocessor', 'logger', 'helper'];
|
||||||
|
|
||||||
|
|
||||||
|
var initTraceurFramework = function(files) {
|
||||||
|
files.unshift({pattern: traceur.RUNTIME_PATH, included: true, served: true, watched: false});
|
||||||
|
};
|
||||||
|
|
||||||
|
initTraceurFramework.$inject = ['config.files'];
|
||||||
|
|
||||||
|
|
||||||
|
// PUBLISH DI MODULE
|
||||||
|
module.exports = {
|
||||||
|
'preprocessor:traceur': ['factory', createTraceurPreprocessor],
|
||||||
|
'framework:traceur': ['factory', initTraceurFramework]
|
||||||
|
};
|
Loading…
Reference in New Issue