From 1d9b5da742a97b318d88287bf4c9e96bc0c1942a Mon Sep 17 00:00:00 2001 From: tjbo Date: Fri, 21 Aug 2015 22:49:18 -0700 Subject: [PATCH 1/2] fixed addPrefix, is broken when also using addSlashRoot = false --- src/inject/index.js | 415 ++++++++++++++++++++++---------------------- 1 file changed, 212 insertions(+), 203 deletions(-) diff --git a/src/inject/index.js b/src/inject/index.js index b0cdedd..3af72a9 100644 --- a/src/inject/index.js +++ b/src/inject/index.js @@ -18,53 +18,53 @@ var red = gutil.colors.red; */ var PLUGIN_NAME = 'gulp-inject'; -module.exports = exports = function(sources, opt){ - if (!sources) { - throw error('Missing sources stream!'); - } - if (!opt) { - opt = {}; - } - - if (opt.sort) { - throw error('sort option is deprecated! Use `sort-stream` module instead!'); - } - if (opt.templateString) { - throw error('`templateString` option is deprecated! Create a virtual `vinyl` file instead!'); - } - if (opt.transform && typeof opt.transform !== 'function') { - throw error('transform option must be a function'); - } - - // Notify people of common mistakes... - if (opt.read) { - warn('There is no ' + magenta('`read`') + ' option. Did you mean to provide it for ' + magenta('`gulp.src`') + ' perhaps?'); - } - - // Defaults: - opt.quiet = bool(opt, 'quiet', false); - opt.ignorePath = toArray(opt.ignorePath).map(unixify); - opt.relative = bool(opt, 'relative', false); - opt.addRootSlash = bool(opt, 'addRootSlash', !opt.relative); - opt.transform = defaults(opt, 'transform', transform); - opt.tags = tags(); - opt.tags.name = defaults(opt, 'name', 'inject'); - transform.selfClosingTag = bool(opt, 'selfClosingTag', false); - - // Is the first parameter a Vinyl File Stream: - if (typeof sources.on === 'function' && typeof sources.pipe === 'function') { - return handleVinylStream(sources, opt); - } - - throw error('passing target file as a string is deprecated! Pass a vinyl file stream (i.e. use `gulp.src`)!'); +module.exports = exports = function(sources, opt) { + if (!sources) { + throw error('Missing sources stream!'); + } + if (!opt) { + opt = {}; + } + + if (opt.sort) { + throw error('sort option is deprecated! Use `sort-stream` module instead!'); + } + if (opt.templateString) { + throw error('`templateString` option is deprecated! Create a virtual `vinyl` file instead!'); + } + if (opt.transform && typeof opt.transform !== 'function') { + throw error('transform option must be a function'); + } + + // Notify people of common mistakes... + if (opt.read) { + warn('There is no ' + magenta('`read`') + ' option. Did you mean to provide it for ' + magenta('`gulp.src`') + ' perhaps?'); + } + + // Defaults: + opt.quiet = bool(opt, 'quiet', false); + opt.ignorePath = toArray(opt.ignorePath).map(unixify); + opt.relative = bool(opt, 'relative', false); + opt.addRootSlash = bool(opt, 'addRootSlash', !opt.relative); + opt.transform = defaults(opt, 'transform', transform); + opt.tags = tags(); + opt.tags.name = defaults(opt, 'name', 'inject'); + transform.selfClosingTag = bool(opt, 'selfClosingTag', false); + + // Is the first parameter a Vinyl File Stream: + if (typeof sources.on === 'function' && typeof sources.pipe === 'function') { + return handleVinylStream(sources, opt); + } + + throw error('passing target file as a string is deprecated! Pass a vinyl file stream (i.e. use `gulp.src`)!'); }; -function defaults (options, prop, defaultValue) { - return options[prop] || defaultValue; +function defaults(options, prop, defaultValue) { + return options[prop] || defaultValue; } -function bool (options, prop, defaultVal) { - return typeof options[prop] !== 'undefined' ? !!options[prop] : defaultVal; +function bool(options, prop, defaultVal) { + return typeof options[prop] !== 'undefined' ? !!options[prop] : defaultVal; } /** @@ -75,18 +75,18 @@ function bool (options, prop, defaultVal) { * @param {Object} opt * @returns {Stream} */ -function handleVinylStream (sources, opt) { - var collected = collectFilesToInject(sources, opt); - - return es.map(function (target, cb) { - if (target.isStream()) { - return cb(error('Streams not supported for target templates!')); - } - collected(function (collection) { - target.contents = getNewContent(target, collection, opt); - cb(null, target); +function handleVinylStream(sources, opt) { + var collected = collectFilesToInject(sources, opt); + + return es.map(function(target, cb) { + if (target.isStream()) { + return cb(error('Streams not supported for target templates!')); + } + collected(function(collection) { + target.contents = getNewContent(target, collection, opt); + cb(null, target); + }); }); - }); } /** @@ -100,29 +100,31 @@ function handleVinylStream (sources, opt) { * @param {Object} opt * @returns {Function} */ -function collectFilesToInject (sources, opt) { - var collection = [], done = false, queue = []; - - sources.pipe(es.through(collector(collection, opt), function () { - done = true; - while (queue.length) { - resolve(queue.shift()); +function collectFilesToInject(sources, opt) { + var collection = [], + done = false, + queue = []; + + sources.pipe(es.through(collector(collection, opt), function() { + done = true; + while (queue.length) { + resolve(queue.shift()); + } + })); + + function resolve(cb) { + setImmediate(function() { + cb(collection); + }); } - })); - - function resolve (cb) { - setImmediate(function () { - cb(collection); - }); - } - return function (cb) { - if (done) { - resolve(cb); - } else { - queue.push(cb); - } - }; + return function(cb) { + if (done) { + resolve(cb); + } else { + queue.push(cb); + } + }; } /** @@ -133,14 +135,14 @@ function collectFilesToInject (sources, opt) { * @param {Object} opt * @returns {Function} */ -function collector (collection, opt) { - return function (file) { - if (!file.path) { - return; - } - - collection.push(file); - }; +function collector(collection, opt) { + return function(file) { + if (!file.path) { + return; + } + + collection.push(file); + }; } /** @@ -152,160 +154,167 @@ function collector (collection, opt) { * @param {Object} opt * @returns {Buffer} */ -function getNewContent (target, collection, opt) { - var oldContent = target.contents; - if (!collection.length) { - if (!opt.quiet) { - log('Nothing to inject into ' + magenta(target.relative) + '.'); +function getNewContent(target, collection, opt) { + var oldContent = target.contents; + if (!collection.length) { + if (!opt.quiet) { + log('Nothing to inject into ' + magenta(target.relative) + '.'); + } + return oldContent; } - return oldContent; - } - var tags = {}; - var targetExt = extname(target.path); - - var filesPerTags = groupBy(collection, function (file) { - var ext = extname(file.path); - var startTag = opt.tags.start(targetExt, ext, opt.starttag); - var endTag = opt.tags.end(targetExt, ext, opt.endtag); - var tag = startTag + endTag; - if (!tags[tag]) { - tags[tag] = {start: startTag, end: endTag}; + var tags = {}; + var targetExt = extname(target.path); + + var filesPerTags = groupBy(collection, function(file) { + var ext = extname(file.path); + var startTag = opt.tags.start(targetExt, ext, opt.starttag); + var endTag = opt.tags.end(targetExt, ext, opt.endtag); + var tag = startTag + endTag; + if (!tags[tag]) { + tags[tag] = { + start: startTag, + end: endTag + }; + } + return tag; + }); + + var startAndEndTags = Object.keys(filesPerTags); + + if (!opt.quiet) { + log(cyan(collection.length) + ' files into ' + magenta(target.relative) + '.'); } - return tag; - }); - - var startAndEndTags = Object.keys(filesPerTags); - - if (!opt.quiet) { - log(cyan(collection.length) + ' files into ' + magenta(target.relative) + '.'); - } - - return new Buffer(startAndEndTags.reduce(function eachInCollection (contents, tag) { - var files = filesPerTags[tag]; - var startTag = tags[tag].start; - var endTag = tags[tag].end; - - return contents.replace( - getInjectorTagsRegExp(startTag, endTag), - function injector (match, starttag, indent, content, endtag) { - var starttagArray = opt.removeTags ? [] : [starttag]; - var endtagArray = opt.removeTags ? [] : [endtag]; - return starttagArray - .concat(files.reduce(function transformFile (lines, file, i) { - var filepath = getFilepath(file, target, opt); - var transformedContents = opt.transform(filepath, file, i, files.length, target); - if (typeof transformedContents !== 'string') { - return lines; + + return new Buffer(startAndEndTags.reduce(function eachInCollection(contents, tag) { + var files = filesPerTags[tag]; + var startTag = tags[tag].start; + var endTag = tags[tag].end; + + return contents.replace( + getInjectorTagsRegExp(startTag, endTag), + function injector(match, starttag, indent, content, endtag) { + var starttagArray = opt.removeTags ? [] : [starttag]; + var endtagArray = opt.removeTags ? [] : [endtag]; + return starttagArray + .concat(files.reduce(function transformFile(lines, file, i) { + var filepath = getFilepath(file, target, opt); + var transformedContents = opt.transform(filepath, file, i, files.length, target); + if (typeof transformedContents !== 'string') { + return lines; + } + return lines.concat(transformedContents); + }, [])) + .concat(endtagArray) + .join(indent); } - return lines.concat(transformedContents); - }, [])) - .concat(endtagArray) - .join(indent); - } - ); - }, String(oldContent))); + ); + }, String(oldContent))); } -function getFilepath (sourceFile, targetFile, opt) { - var base = opt.relative ? path.dirname(targetFile.path) : sourceFile.cwd; +function getFilepath(sourceFile, targetFile, opt) { + var base = opt.relative ? path.dirname(targetFile.path) : sourceFile.cwd; - var filepath = unixify(path.relative(base, sourceFile.path)); + var filepath = unixify(path.relative(base, sourceFile.path)); - if (opt.ignorePath.length) { - filepath = removeBasePath(opt.ignorePath, filepath); - } + if (opt.ignorePath.length) { + filepath = removeBasePath(opt.ignorePath, filepath); + } - if (opt.addPrefix) { - filepath = addPrefix(filepath, opt.addPrefix); - } + if (opt.addPrefix) { + filepath = addPrefix(filepath, opt.addPrefix); + } - if (opt.addRootSlash) { - filepath = addRootSlash(filepath); - } else if(!opt.addPrefix) { - filepath = removeRootSlash(filepath); - } - - if (opt.addSuffix) { - filepath = addSuffix(filepath, opt.addSuffix); - } + if (opt.addRootSlash) { + filepath = addRootSlash(filepath); + } else if (!opt.addPrefix) { + filepath = removeRootSlash(filepath); + } - return filepath; -} + if (opt.addSuffix) { + filepath = addSuffix(filepath, opt.addSuffix); + } -function getTag (tag, ext) { - return tag.replace('{{ext}}', ext); + return filepath; } -function getInjectorTagsRegExp (starttag, endtag) { - return new RegExp('(' + makeWhiteSpaceOptional(escapeForRegExp(starttag)) + ')(\\s*)(\\n|\\r|.)*?(' + makeWhiteSpaceOptional(escapeForRegExp(endtag)) + ')', 'gi'); +function getTag(tag, ext) { + return tag.replace('{{ext}}', ext); } -function makeWhiteSpaceOptional (str) { - return str.replace(/\s+/g, '\\s*'); +function getInjectorTagsRegExp(starttag, endtag) { + return new RegExp('(' + makeWhiteSpaceOptional(escapeForRegExp(starttag)) + ')(\\s*)(\\n|\\r|.)*?(' + makeWhiteSpaceOptional(escapeForRegExp(endtag)) + ')', 'gi'); } -function escapeForRegExp (str) { - return str.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); +function makeWhiteSpaceOptional(str) { + return str.replace(/\s+/g, '\\s*'); } -function unixify (filepath) { - return filepath.replace(/\\/g, '/'); +function escapeForRegExp(str) { + return str.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); } -function addRootSlash (filepath) { - return filepath.replace(/^\/*([^\/])/, '/$1'); + +function unixify(filepath) { + return filepath.replace(/\\/g, '/'); } -function removeRootSlash (filepath) { - return filepath.replace(/^\/+/, ''); + +function addRootSlash(filepath) { + return filepath.replace(/^\/*([^\/])/, '/$1'); } -function addPrefix (filepath, prefix) { - return prefix + addRootSlash(filepath); + +function removeRootSlash(filepath) { + return filepath.replace(/^\/+/, ''); } -function addSuffix (filepath, suffix) { - return filepath + suffix; + +function addPrefix(filepath, prefix) { + return prefix + filepath; } -function removeBasePath (basedir, filepath) { - return toArray(basedir).reduce(function (path, remove) { - if (path[0] === '/' && remove[0] !== '/') { - remove = '/' + remove; - } - if (path[0] !== '/' && remove[0] === '/') { - path = '/' + path; - } - if (remove && path.indexOf(remove) === 0) { - return path.slice(remove.length); - } - return path; - }, filepath); +function addSuffix(filepath, suffix) { + return filepath + suffix; } -function toArray (arr) { - if (!Array.isArray(arr)) { - return arr ? [arr] : []; - } - return arr; +function removeBasePath(basedir, filepath) { + return toArray(basedir).reduce(function(path, remove) { + if (path[0] === '/' && remove[0] !== '/') { + remove = '/' + remove; + } + if (path[0] !== '/' && remove[0] === '/') { + path = '/' + path; + } + if (remove && path.indexOf(remove) === 0) { + return path.slice(remove.length); + } + return path; + }, filepath); } -function groupBy (arr, cb) { - var result = {}; - for (var i = 0; i < arr.length; i++) { - var key = cb(arr[i]); - if (!result[key]) { - result[key] = []; +function toArray(arr) { + if (!Array.isArray(arr)) { + return arr ? [arr] : []; } - result[key].push(arr[i]); - } - return result; + return arr; } -function log (message) { - gutil.log(magenta(PLUGIN_NAME), message); +function groupBy(arr, cb) { + var result = {}; + for (var i = 0; i < arr.length; i++) { + var key = cb(arr[i]); + if (!result[key]) { + result[key] = []; + } + result[key].push(arr[i]); + } + return result; } -function warn (message) { - log(red('WARNING') + ' ' + message); +function log(message) { + gutil.log(magenta(PLUGIN_NAME), message); } -function error (message) { - return new PluginError(PLUGIN_NAME, message); +function warn(message) { + log(red('WARNING') + ' ' + message); } + +function error(message) { + return new PluginError(PLUGIN_NAME, message); +} \ No newline at end of file From 8d245ad77cdcf418599fefe75753d229b8215004 Mon Sep 17 00:00:00 2001 From: tjbo Date: Fri, 21 Aug 2015 22:55:57 -0700 Subject: [PATCH 2/2] fixed addPrefix --- src/inject/index.js | 415 ++++++++++++++++++++++---------------------- 1 file changed, 203 insertions(+), 212 deletions(-) diff --git a/src/inject/index.js b/src/inject/index.js index 3af72a9..9240c69 100644 --- a/src/inject/index.js +++ b/src/inject/index.js @@ -18,53 +18,53 @@ var red = gutil.colors.red; */ var PLUGIN_NAME = 'gulp-inject'; -module.exports = exports = function(sources, opt) { - if (!sources) { - throw error('Missing sources stream!'); - } - if (!opt) { - opt = {}; - } - - if (opt.sort) { - throw error('sort option is deprecated! Use `sort-stream` module instead!'); - } - if (opt.templateString) { - throw error('`templateString` option is deprecated! Create a virtual `vinyl` file instead!'); - } - if (opt.transform && typeof opt.transform !== 'function') { - throw error('transform option must be a function'); - } - - // Notify people of common mistakes... - if (opt.read) { - warn('There is no ' + magenta('`read`') + ' option. Did you mean to provide it for ' + magenta('`gulp.src`') + ' perhaps?'); - } - - // Defaults: - opt.quiet = bool(opt, 'quiet', false); - opt.ignorePath = toArray(opt.ignorePath).map(unixify); - opt.relative = bool(opt, 'relative', false); - opt.addRootSlash = bool(opt, 'addRootSlash', !opt.relative); - opt.transform = defaults(opt, 'transform', transform); - opt.tags = tags(); - opt.tags.name = defaults(opt, 'name', 'inject'); - transform.selfClosingTag = bool(opt, 'selfClosingTag', false); - - // Is the first parameter a Vinyl File Stream: - if (typeof sources.on === 'function' && typeof sources.pipe === 'function') { - return handleVinylStream(sources, opt); - } - - throw error('passing target file as a string is deprecated! Pass a vinyl file stream (i.e. use `gulp.src`)!'); +module.exports = exports = function(sources, opt){ + if (!sources) { + throw error('Missing sources stream!'); + } + if (!opt) { + opt = {}; + } + + if (opt.sort) { + throw error('sort option is deprecated! Use `sort-stream` module instead!'); + } + if (opt.templateString) { + throw error('`templateString` option is deprecated! Create a virtual `vinyl` file instead!'); + } + if (opt.transform && typeof opt.transform !== 'function') { + throw error('transform option must be a function'); + } + + // Notify people of common mistakes... + if (opt.read) { + warn('There is no ' + magenta('`read`') + ' option. Did you mean to provide it for ' + magenta('`gulp.src`') + ' perhaps?'); + } + + // Defaults: + opt.quiet = bool(opt, 'quiet', false); + opt.ignorePath = toArray(opt.ignorePath).map(unixify); + opt.relative = bool(opt, 'relative', false); + opt.addRootSlash = bool(opt, 'addRootSlash', !opt.relative); + opt.transform = defaults(opt, 'transform', transform); + opt.tags = tags(); + opt.tags.name = defaults(opt, 'name', 'inject'); + transform.selfClosingTag = bool(opt, 'selfClosingTag', false); + + // Is the first parameter a Vinyl File Stream: + if (typeof sources.on === 'function' && typeof sources.pipe === 'function') { + return handleVinylStream(sources, opt); + } + + throw error('passing target file as a string is deprecated! Pass a vinyl file stream (i.e. use `gulp.src`)!'); }; -function defaults(options, prop, defaultValue) { - return options[prop] || defaultValue; +function defaults (options, prop, defaultValue) { + return options[prop] || defaultValue; } -function bool(options, prop, defaultVal) { - return typeof options[prop] !== 'undefined' ? !!options[prop] : defaultVal; +function bool (options, prop, defaultVal) { + return typeof options[prop] !== 'undefined' ? !!options[prop] : defaultVal; } /** @@ -75,18 +75,18 @@ function bool(options, prop, defaultVal) { * @param {Object} opt * @returns {Stream} */ -function handleVinylStream(sources, opt) { - var collected = collectFilesToInject(sources, opt); - - return es.map(function(target, cb) { - if (target.isStream()) { - return cb(error('Streams not supported for target templates!')); - } - collected(function(collection) { - target.contents = getNewContent(target, collection, opt); - cb(null, target); - }); +function handleVinylStream (sources, opt) { + var collected = collectFilesToInject(sources, opt); + + return es.map(function (target, cb) { + if (target.isStream()) { + return cb(error('Streams not supported for target templates!')); + } + collected(function (collection) { + target.contents = getNewContent(target, collection, opt); + cb(null, target); }); + }); } /** @@ -100,31 +100,29 @@ function handleVinylStream(sources, opt) { * @param {Object} opt * @returns {Function} */ -function collectFilesToInject(sources, opt) { - var collection = [], - done = false, - queue = []; - - sources.pipe(es.through(collector(collection, opt), function() { - done = true; - while (queue.length) { - resolve(queue.shift()); - } - })); - - function resolve(cb) { - setImmediate(function() { - cb(collection); - }); +function collectFilesToInject (sources, opt) { + var collection = [], done = false, queue = []; + + sources.pipe(es.through(collector(collection, opt), function () { + done = true; + while (queue.length) { + resolve(queue.shift()); } + })); + + function resolve (cb) { + setImmediate(function () { + cb(collection); + }); + } - return function(cb) { - if (done) { - resolve(cb); - } else { - queue.push(cb); - } - }; + return function (cb) { + if (done) { + resolve(cb); + } else { + queue.push(cb); + } + }; } /** @@ -135,14 +133,14 @@ function collectFilesToInject(sources, opt) { * @param {Object} opt * @returns {Function} */ -function collector(collection, opt) { - return function(file) { - if (!file.path) { - return; - } - - collection.push(file); - }; +function collector (collection, opt) { + return function (file) { + if (!file.path) { + return; + } + + collection.push(file); + }; } /** @@ -154,167 +152,160 @@ function collector(collection, opt) { * @param {Object} opt * @returns {Buffer} */ -function getNewContent(target, collection, opt) { - var oldContent = target.contents; - if (!collection.length) { - if (!opt.quiet) { - log('Nothing to inject into ' + magenta(target.relative) + '.'); - } - return oldContent; - } - var tags = {}; - var targetExt = extname(target.path); - - var filesPerTags = groupBy(collection, function(file) { - var ext = extname(file.path); - var startTag = opt.tags.start(targetExt, ext, opt.starttag); - var endTag = opt.tags.end(targetExt, ext, opt.endtag); - var tag = startTag + endTag; - if (!tags[tag]) { - tags[tag] = { - start: startTag, - end: endTag - }; - } - return tag; - }); - - var startAndEndTags = Object.keys(filesPerTags); - +function getNewContent (target, collection, opt) { + var oldContent = target.contents; + if (!collection.length) { if (!opt.quiet) { - log(cyan(collection.length) + ' files into ' + magenta(target.relative) + '.'); + log('Nothing to inject into ' + magenta(target.relative) + '.'); } - - return new Buffer(startAndEndTags.reduce(function eachInCollection(contents, tag) { - var files = filesPerTags[tag]; - var startTag = tags[tag].start; - var endTag = tags[tag].end; - - return contents.replace( - getInjectorTagsRegExp(startTag, endTag), - function injector(match, starttag, indent, content, endtag) { - var starttagArray = opt.removeTags ? [] : [starttag]; - var endtagArray = opt.removeTags ? [] : [endtag]; - return starttagArray - .concat(files.reduce(function transformFile(lines, file, i) { - var filepath = getFilepath(file, target, opt); - var transformedContents = opt.transform(filepath, file, i, files.length, target); - if (typeof transformedContents !== 'string') { - return lines; - } - return lines.concat(transformedContents); - }, [])) - .concat(endtagArray) - .join(indent); + return oldContent; + } + var tags = {}; + var targetExt = extname(target.path); + + var filesPerTags = groupBy(collection, function (file) { + var ext = extname(file.path); + var startTag = opt.tags.start(targetExt, ext, opt.starttag); + var endTag = opt.tags.end(targetExt, ext, opt.endtag); + var tag = startTag + endTag; + if (!tags[tag]) { + tags[tag] = {start: startTag, end: endTag}; + } + return tag; + }); + + var startAndEndTags = Object.keys(filesPerTags); + + if (!opt.quiet) { + log(cyan(collection.length) + ' files into ' + magenta(target.relative) + '.'); + } + + return new Buffer(startAndEndTags.reduce(function eachInCollection (contents, tag) { + var files = filesPerTags[tag]; + var startTag = tags[tag].start; + var endTag = tags[tag].end; + + return contents.replace( + getInjectorTagsRegExp(startTag, endTag), + function injector (match, starttag, indent, content, endtag) { + var starttagArray = opt.removeTags ? [] : [starttag]; + var endtagArray = opt.removeTags ? [] : [endtag]; + return starttagArray + .concat(files.reduce(function transformFile (lines, file, i) { + var filepath = getFilepath(file, target, opt); + var transformedContents = opt.transform(filepath, file, i, files.length, target); + if (typeof transformedContents !== 'string') { + return lines; } - ); - }, String(oldContent))); + return lines.concat(transformedContents); + }, [])) + .concat(endtagArray) + .join(indent); + } + ); + }, String(oldContent))); } -function getFilepath(sourceFile, targetFile, opt) { - var base = opt.relative ? path.dirname(targetFile.path) : sourceFile.cwd; +function getFilepath (sourceFile, targetFile, opt) { + var base = opt.relative ? path.dirname(targetFile.path) : sourceFile.cwd; - var filepath = unixify(path.relative(base, sourceFile.path)); + var filepath = unixify(path.relative(base, sourceFile.path)); - if (opt.ignorePath.length) { - filepath = removeBasePath(opt.ignorePath, filepath); - } + if (opt.ignorePath.length) { + filepath = removeBasePath(opt.ignorePath, filepath); + } - if (opt.addPrefix) { - filepath = addPrefix(filepath, opt.addPrefix); - } + if (opt.addPrefix) { + filepath = addPrefix(filepath, opt.addPrefix); + } - if (opt.addRootSlash) { - filepath = addRootSlash(filepath); - } else if (!opt.addPrefix) { - filepath = removeRootSlash(filepath); - } - - if (opt.addSuffix) { - filepath = addSuffix(filepath, opt.addSuffix); - } + if (opt.addRootSlash) { + filepath = addRootSlash(filepath); + } else if(!opt.addPrefix) { + filepath = removeRootSlash(filepath); + } + + if (opt.addSuffix) { + filepath = addSuffix(filepath, opt.addSuffix); + } - return filepath; + return filepath; } -function getTag(tag, ext) { - return tag.replace('{{ext}}', ext); +function getTag (tag, ext) { + return tag.replace('{{ext}}', ext); } -function getInjectorTagsRegExp(starttag, endtag) { - return new RegExp('(' + makeWhiteSpaceOptional(escapeForRegExp(starttag)) + ')(\\s*)(\\n|\\r|.)*?(' + makeWhiteSpaceOptional(escapeForRegExp(endtag)) + ')', 'gi'); +function getInjectorTagsRegExp (starttag, endtag) { + return new RegExp('(' + makeWhiteSpaceOptional(escapeForRegExp(starttag)) + ')(\\s*)(\\n|\\r|.)*?(' + makeWhiteSpaceOptional(escapeForRegExp(endtag)) + ')', 'gi'); } -function makeWhiteSpaceOptional(str) { - return str.replace(/\s+/g, '\\s*'); +function makeWhiteSpaceOptional (str) { + return str.replace(/\s+/g, '\\s*'); } -function escapeForRegExp(str) { - return str.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); +function escapeForRegExp (str) { + return str.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); } -function unixify(filepath) { - return filepath.replace(/\\/g, '/'); +function unixify (filepath) { + return filepath.replace(/\\/g, '/'); } - -function addRootSlash(filepath) { - return filepath.replace(/^\/*([^\/])/, '/$1'); +function addRootSlash (filepath) { + return filepath.replace(/^\/*([^\/])/, '/$1'); } - -function removeRootSlash(filepath) { - return filepath.replace(/^\/+/, ''); +function removeRootSlash (filepath) { + return filepath.replace(/^\/+/, ''); } - -function addPrefix(filepath, prefix) { - return prefix + filepath; +function addPrefix (filepath, prefix) { + return prefix + filepath; } - -function addSuffix(filepath, suffix) { - return filepath + suffix; +function addSuffix (filepath, suffix) { + return filepath + suffix; } -function removeBasePath(basedir, filepath) { - return toArray(basedir).reduce(function(path, remove) { - if (path[0] === '/' && remove[0] !== '/') { - remove = '/' + remove; - } - if (path[0] !== '/' && remove[0] === '/') { - path = '/' + path; - } - if (remove && path.indexOf(remove) === 0) { - return path.slice(remove.length); - } - return path; - }, filepath); +function removeBasePath (basedir, filepath) { + return toArray(basedir).reduce(function (path, remove) { + if (path[0] === '/' && remove[0] !== '/') { + remove = '/' + remove; + } + if (path[0] !== '/' && remove[0] === '/') { + path = '/' + path; + } + if (remove && path.indexOf(remove) === 0) { + return path.slice(remove.length); + } + return path; + }, filepath); } -function toArray(arr) { - if (!Array.isArray(arr)) { - return arr ? [arr] : []; - } - return arr; +function toArray (arr) { + if (!Array.isArray(arr)) { + return arr ? [arr] : []; + } + return arr; } -function groupBy(arr, cb) { - var result = {}; - for (var i = 0; i < arr.length; i++) { - var key = cb(arr[i]); - if (!result[key]) { - result[key] = []; - } - result[key].push(arr[i]); +function groupBy (arr, cb) { + var result = {}; + for (var i = 0; i < arr.length; i++) { + var key = cb(arr[i]); + if (!result[key]) { + result[key] = []; } - return result; + result[key].push(arr[i]); + } + return result; } -function log(message) { - gutil.log(magenta(PLUGIN_NAME), message); +function log (message) { + gutil.log(magenta(PLUGIN_NAME), message); } -function warn(message) { - log(red('WARNING') + ' ' + message); +function warn (message) { + log(red('WARNING') + ' ' + message); } -function error(message) { - return new PluginError(PLUGIN_NAME, message); -} \ No newline at end of file +function error (message) { + return new PluginError(PLUGIN_NAME, message); +}