-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #12 Support configurable tokens for the gulp module tagger #561
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So... it looks like this replaces the default. If I use the module tagger once with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new diff |
||
} else { | ||
REPLACE_TOKEN = DEFAULT_REPLACE_TOKEN; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like it masks the outer Needs a different name inside this function, right? var token = REPLACE_TOKEN;
if (config.token) {
token = rokenToRegExp(config.token);
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we want it to replace the outer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But... don't we still want the value of the outer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, which is why the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, it's been updated again since this comment thread started. :) |
||
config.basePath = module.filename.replace(THIS_MODULE,''); | ||
return forEach(function(stream, file){ | ||
return stream.pipe(replace(REPLACE_TOKEN, (match, optString) => { | ||
|
@@ -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__", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
})) | ||
.pipe(gulp.dest('build')); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gigabo like this?