Skip to content

Commit

Permalink
Fix #12 Support configurable tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-wade committed Aug 17, 2016
1 parent bdea5c1 commit f716c06
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 10 additions & 1 deletion packages/react-server-gulp-module-tagger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ var replace = require("gulp-replace")
// - "__LOGGER__"
// - "__LOGGER__({ /* options */ })"
var isWindows = ('win32' === process.platform)
, REPLACE_TOKEN = /(?:__LOGGER__|__CHANNEL__|__CACHE__)(?:\(\s*(\{[\s\S]*?\})\s*\))?/g
, THIS_MODULE = isWindows
? /(?:[^\\]+\\node_modules\\)?react-server-gulp-module-tagger\\index\.js$/
: /(?:[^\/]+\/node_modules\/)?react-server-gulp-module-tagger\/index\.js$/

module.exports = function(config) {
config || (config = {});
var REPLACE_TOKEN;
if (config.token) {
REPLACE_TOKEN = tokenToRegExp(config.token);
} else {
REPLACE_TOKEN = tokenToRegExp("__LOGGER__|__CHANNEL__|__CACHE__");
}
config.basePath = module.filename.replace(THIS_MODULE,'');
return forEach(function(stream, file){
return stream.pipe(replace(REPLACE_TOKEN, (match, optString) => {
Expand All @@ -24,3 +29,7 @@ module.exports = function(config) {
}));
});
}

function tokenToRegExp(token) {
return new RegExp("(?:" + token + ")(?:\\(\\s*(\\{[\\s\\S]*?\\})\\s*\\))?", 'g');
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f716c06

Please sign in to comment.