UNPKG

gulp-include-sources

Version:

Includes source files listed in HTML comments

42 lines (29 loc) 1.05 kB
'use strict'; /** * Created by Georgi Yanev on 28.01.2017. */ var gutil = require("gulp-util"), PluginError = gutil.PluginError, through = require("through2"), includeSource = require("./src/includeSource.js"), path = require("path"); const PLUGIN_NAME = "gulp-include-sources"; function includeSources(options) { return through.obj(function(file, encoding, callback) { if(file.isNull()) { return callback(null, file); // Einen leeren File zurückgeben } if(file.isBuffer()) { // Alocate AoT file.contents = new Buffer(includeSource(file.path, options)); // Change extension var newBaseName = path.basename(file.path).split(".")[0] + ".html"; file.path = path.resolve( path.dirname(file.path), newBaseName ); } if(file.isStream()) { throw new PluginError(PLUGIN_NAME, "Streams are not yet supported"); } callback(null, file); }); } module.exports = includeSources;