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 ejs = require('gulp-ejs');
|
||||
var path = require('path');
|
||||
var through2 = require('through2');
|
||||
|
||||
// import js2dart build tasks
|
||||
var js2dartTasks = require('./tools/js2dart/gulp-tasks');
|
||||
|
@ -38,10 +39,10 @@ var traceur = require('./tools/js2dart/gulp-traceur');
|
|||
// rtts-assert and traceur runtime
|
||||
|
||||
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 rttsAssert = srcFn('tools/rtts-assert/src/assert.js')
|
||||
.pipe(traceur(js2es5Options))
|
||||
|
@ -60,11 +61,20 @@ var sourceTypeConfigs = {
|
|||
},
|
||||
transpileSrc: ['modules/**/*.js'],
|
||||
htmlSrc: ['modules/*/src/**/*.html'],
|
||||
// TODO: execute pub get after a yaml changed and was copied over to 'build' folder
|
||||
copySrc: ['modules/**/*.dart', 'modules/**/*.yaml'],
|
||||
outputDir: 'build/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: {
|
||||
compiler: function() {
|
||||
|
@ -74,46 +84,74 @@ var sourceTypeConfigs = {
|
|||
htmlSrc: ['modules/*/src/**/*.html'],
|
||||
copySrc: ['modules/**/*.es5'],
|
||||
outputDir: 'build/js',
|
||||
outputExt: 'js'
|
||||
outputExt: 'js',
|
||||
postProcess: function() {
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
gulp.task('modules/clean', function() {
|
||||
return gulp.src('build', {read: false})
|
||||
.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) {
|
||||
file.dirname = file.dirname.replace(/\bsrc\b/, 'lib');
|
||||
}
|
||||
|
||||
function createModuleTask(sourceTypeConfig, isWatch) {
|
||||
var start = isWatch ? watch : gulp.src.bind(gulp);
|
||||
return function(done) {
|
||||
var transpile = start(sourceTypeConfig.transpileSrc)
|
||||
.pipe(rename({extname: '.'+sourceTypeConfig.outputExt}))
|
||||
.pipe(rename(renameSrcToLib))
|
||||
.pipe(sourceTypeConfig.compiler())
|
||||
.pipe(gulp.dest(sourceTypeConfig.outputDir));
|
||||
var copy = start(sourceTypeConfig.copySrc)
|
||||
.pipe(rename(renameSrcToLib))
|
||||
.pipe(gulp.dest(sourceTypeConfig.outputDir));
|
||||
// TODO: provide the list of files to the template
|
||||
// automatically!
|
||||
var html = start(sourceTypeConfig.htmlSrc)
|
||||
.pipe(rename(renameSrcToLib))
|
||||
.pipe(ejs({
|
||||
type: sourceTypeConfig.outputExt
|
||||
}))
|
||||
.pipe(gulp.dest(sourceTypeConfig.outputDir));
|
||||
var transpile = start(sourceTypeConfig.transpileSrc)
|
||||
.pipe(rename({extname: '.'+sourceTypeConfig.outputExt}))
|
||||
.pipe(rename(renameSrcToLib))
|
||||
.pipe(sourceTypeConfig.compiler())
|
||||
.pipe(gulp.dest(sourceTypeConfig.outputDir));
|
||||
var copy = start(sourceTypeConfig.copySrc)
|
||||
.pipe(rename(renameSrcToLib))
|
||||
.pipe(gulp.dest(sourceTypeConfig.outputDir));
|
||||
// TODO: provide the list of files to the template
|
||||
// automatically!
|
||||
var html = start(sourceTypeConfig.htmlSrc)
|
||||
.pipe(rename(renameSrcToLib))
|
||||
.pipe(ejs({
|
||||
type: sourceTypeConfig.outputExt
|
||||
}))
|
||||
.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
|
||||
gulp.task('serve', connect.server({
|
||||
|
@ -155,7 +193,7 @@ gulp.task('watch', function() {
|
|||
['jsRuntime/build', 'modules/build.dart', 'modules/build.js'],
|
||||
done);
|
||||
});
|
||||
var dartModuleWatch = createModuleTask(sourceTypeConfigs.dart, true)();
|
||||
var jsModuleWatch = createModuleTask(sourceTypeConfigs.js, true)();
|
||||
return mergeStreams(js2dartWatch, dartModuleWatch, jsModuleWatch, jsRuntime(true));
|
||||
var dartModuleWatch = createModuleTask(sourceTypeConfigs.dart, true);
|
||||
var jsModuleWatch = createModuleTask(sourceTypeConfigs.js, true);
|
||||
return mergeStreams(js2dartWatch, dartModuleWatch, jsModuleWatch, createJsRuntimeTask(true));
|
||||
});
|
||||
|
|
|
@ -2,5 +2,7 @@ name: di
|
|||
environment:
|
||||
sdk: '>=1.4.0'
|
||||
dependencies:
|
||||
facade:
|
||||
path: ../facade
|
||||
dev_dependencies:
|
||||
unittest: '>=0.10.1 <0.12.0'
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import {Type} from 'facade/lang';
|
||||
import {Map, MapWrapper wraps Map} from 'facade/collection';
|
||||
|
||||
/// becouse we need to know when toValue was not set.
|
||||
/// (it could be that toValue is set to null or undefined in js)
|
||||
var _UNDEFINED = {}
|
||||
/// becouse we need to know when toValue was not set.
|
||||
/// (it could be that toValue is set to null or undefined in js)
|
||||
var _UNDEFINED = {}
|
||||
|
||||
export class Module {
|
||||
|
||||
|
@ -12,12 +12,12 @@ export class Module {
|
|||
this.bindings = new MapWrapper();
|
||||
}
|
||||
|
||||
bind(type:Type,
|
||||
{toValue=_UNDEFINED, toFactory, toImplementation, inject, toInstanceOf, withAnnotation}/*:
|
||||
bind(type:Type,
|
||||
{toValue/*=_UNDEFINED*/, toFactory, toImplementation, inject, toInstanceOf, withAnnotation}/*:
|
||||
{toFactory:Function, toImplementation: Type, inject: Array, toInstanceOf:Type}*/) {}
|
||||
|
||||
bindByKey(key:Key,
|
||||
{toValue=_UNDEFINED, toFactory, toImplementation, inject, toInstanceOf}/*:
|
||||
bindByKey(key:Key,
|
||||
{toValue/*=_UNDEFINED*/, toFactory, toImplementation, inject, toInstanceOf}/*:
|
||||
{toFactory:Function, toImplementation: Type, inject: Array, toInstanceOf:Type}*/) {}
|
||||
|
||||
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