Tobias Bosch 05ffdc9b44 refactor(build): explicitly mention src folder in imports
Export files are now directly under the module folder,
e.g. `core/core.js`. With this, an import like `core/core`
won’t need a path mapping (e.g. via `System.paths`) any more.
This adds the `src` folder to all other import statements as well.
2015-02-05 11:55:48 -08:00

33 lines
1.2 KiB
JavaScript

var util = require('./util');
var file2moduleName = require('./file2modulename');
var through2 = require('through2');
var path = require('path');
module.exports = function(gulp, plugins, config) {
return function() {
return gulp.src(config.src)
.pipe(util.insertSrcFolder(plugins, config.srcFolderInsertion, config.modulesFolder))
.pipe(through2.obj(function(file, enc, done) {
var fileName = file.relative;
var moduleName = file2moduleName(fileName);
var moduleNameWithoutPath = path.basename(moduleName);
var scripts = util.filterByFile(config.scriptsPerFolder, fileName).map(function(script) {
var scriptTag;
if (script.src) {
scriptTag = '<script src="'+script.src+'" type="'+script.mimeType+'"></script>';
} else {
scriptTag = '<script type="'+script.mimeType+'">'+script.inline+'</script>';
}
return scriptTag
.replace('$MODULENAME_WITHOUT_PATH$', moduleNameWithoutPath)
.replace('$MODULENAME$', moduleName)
}).join('\n');
file.contents = new Buffer(file.contents.toString().replace('$SCRIPTS$', scripts));
this.push(file);
done();
}))
.pipe(gulp.dest(config.dest));
};
};