Skip to content

Commit

Permalink
Merge pull request #561 from doug-wade/fix-12
Browse files Browse the repository at this point in the history
Fix #12 Support configurable tokens for the gulp module tagger
  • Loading branch information
doug-wade authored Aug 17, 2016
2 parents 92d41ba + 059cea6 commit 7f61d9b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
12 changes: 11 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,19 @@ var replace = require("gulp-replace")
// - "__LOGGER__"
// - "__LOGGER__({ /* options */ })"
var isWindows = ('win32' === process.platform)
, REPLACE_TOKEN = /(?:__LOGGER__|__CHANNEL__|__CACHE__)(?:\(\s*(\{[\s\S]*?\})\s*\))?/g
, DEFAULT_REPLACE_TOKEN = tokenToRegExp("__LOGGER__|__CHANNEL__|__CACHE__")
, 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 = DEFAULT_REPLACE_TOKEN;
}
config.basePath = module.filename.replace(THIS_MODULE,'');
return forEach(function(stream, file){
return stream.pipe(replace(REPLACE_TOKEN, (match, optString) => {
Expand All @@ -24,3 +30,7 @@ module.exports = function(config) {
}));
});
}

function tokenToRegExp(token) {
return new RegExp("(?:" + token + ")(?:\\(\\s*(\\{[\\s\\S]*?\\})\\s*\\))?", 'g');
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var logger = require('react-server').logging.getLogger(__OZZIE_ALONSO__);
var fooLogger = logging.getLogger(__OZZIE_ALONSO__({ label: "foo" }));
var barLogger = logging.getLogger(__OZZIE_ALONSO__({ label: "bar" }));

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const gulp = require('gulp');
const tagger = require('../../..');

gulp.task('default', () => {
gulp.src('actual.js')
.pipe(tagger({
token: "__OZZIE_ALONSO__",
}))
.pipe(gulp.dest('build'));
});

0 comments on commit 7f61d9b

Please sign in to comment.