From 0cb40bceb254bbdda4a6c07f724399a190f24771 Mon Sep 17 00:00:00 2001 From: Carl Mathisen Date: Fri, 18 Mar 2016 13:52:35 +0100 Subject: [PATCH 1/2] Support for a custom mode w/template string replacement --- index.js | 3 ++- modes/custom.js | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 modes/custom.js diff --git a/index.js b/index.js index 59bd3d0..483820f 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,8 @@ var fs = require('fs'); var modes = { 'expand': require('./modes/expand'), 'hash': require('./modes/hash'), - 'list': require('./modes/list') + 'list': require('./modes/list'), + 'custom': require('./modes/custom') }; module.exports = require('browserify-transform-tools').makeRequireTransform( diff --git a/modes/custom.js b/modes/custom.js new file mode 100644 index 0000000..a504cd2 --- /dev/null +++ b/modes/custom.js @@ -0,0 +1,10 @@ +module.exports = function(base, files, config) { + if (files.length === 0) { + return ''; + } + return files.reduce( + function(acc, file, idx, arr) { + config.template = config.template.replace(new RegExp('{file}', 'g'), file); + return (acc ? acc + ";" : "") + config.template; + }, false); +}; \ No newline at end of file From c983ab3a850b842e51b3d3ee0c125f6ee795ef52 Mon Sep 17 00:00:00 2001 From: Carl Mathisen Date: Sat, 19 Mar 2016 18:41:42 +0100 Subject: [PATCH 2/2] Fixed bug causing all to equal to the first one --- modes/custom.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modes/custom.js b/modes/custom.js index a504cd2..59c222c 100644 --- a/modes/custom.js +++ b/modes/custom.js @@ -4,7 +4,7 @@ module.exports = function(base, files, config) { } return files.reduce( function(acc, file, idx, arr) { - config.template = config.template.replace(new RegExp('{file}', 'g'), file); - return (acc ? acc + ";" : "") + config.template; + var template = config.template.replace(new RegExp('{file}', 'g'), file); + return (acc ? acc + ";" : "") + template; }, false); -}; \ No newline at end of file +};