From 23ec8a5f71da703edb02434853bef2a1421a1984 Mon Sep 17 00:00:00 2001 From: Doug Wade Date: Fri, 12 Aug 2016 11:06:55 -0700 Subject: [PATCH 1/2] Add failing test --- .../test/fixtures/custom-token/actual.js | 3 +++ .../test/fixtures/custom-token/expected.js | 3 +++ .../test/fixtures/custom-token/gulpfile.js | 10 ++++++++++ 3 files changed, 16 insertions(+) create mode 100644 packages/react-server-gulp-module-tagger/test/fixtures/custom-token/actual.js create mode 100644 packages/react-server-gulp-module-tagger/test/fixtures/custom-token/expected.js create mode 100644 packages/react-server-gulp-module-tagger/test/fixtures/custom-token/gulpfile.js diff --git a/packages/react-server-gulp-module-tagger/test/fixtures/custom-token/actual.js b/packages/react-server-gulp-module-tagger/test/fixtures/custom-token/actual.js new file mode 100644 index 000000000..bd20584a5 --- /dev/null +++ b/packages/react-server-gulp-module-tagger/test/fixtures/custom-token/actual.js @@ -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" })); diff --git a/packages/react-server-gulp-module-tagger/test/fixtures/custom-token/expected.js b/packages/react-server-gulp-module-tagger/test/fixtures/custom-token/expected.js new file mode 100644 index 000000000..b3afe9e3e --- /dev/null +++ b/packages/react-server-gulp-module-tagger/test/fixtures/custom-token/expected.js @@ -0,0 +1,3 @@ +var logger = require('react-server').logging.getLogger({"name":"react-server-gulp-module-tagger.test.fixtures.custom-token.actual","color":{"server":219,"client":"rgb(212,127,212)"}}); +var fooLogger = logging.getLogger({"label":"foo","name":"react-server-gulp-module-tagger.test.fixtures.custom-token.actual.foo","color":{"server":219,"client":"rgb(212,127,212)"}}); +var barLogger = logging.getLogger({"label":"bar","name":"react-server-gulp-module-tagger.test.fixtures.custom-token.actual.bar","color":{"server":219,"client":"rgb(212,127,212)"}}); diff --git a/packages/react-server-gulp-module-tagger/test/fixtures/custom-token/gulpfile.js b/packages/react-server-gulp-module-tagger/test/fixtures/custom-token/gulpfile.js new file mode 100644 index 000000000..08dccd80d --- /dev/null +++ b/packages/react-server-gulp-module-tagger/test/fixtures/custom-token/gulpfile.js @@ -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')); +}); From 059cea6b7032d5742cfcd0f6a8be0b37bbf8ffa3 Mon Sep 17 00:00:00 2001 From: Doug Wade Date: Fri, 12 Aug 2016 11:26:43 -0700 Subject: [PATCH 2/2] Fix #12 Support configurable tokens --- packages/react-server-gulp-module-tagger/index.js | 12 +++++++++++- .../test/fixtures/custom-token/expected.js | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/react-server-gulp-module-tagger/index.js b/packages/react-server-gulp-module-tagger/index.js index 647d4f47c..af3118a45 100644 --- a/packages/react-server-gulp-module-tagger/index.js +++ b/packages/react-server-gulp-module-tagger/index.js @@ -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) => { @@ -24,3 +30,7 @@ module.exports = function(config) { })); }); } + +function tokenToRegExp(token) { + return new RegExp("(?:" + token + ")(?:\\(\\s*(\\{[\\s\\S]*?\\})\\s*\\))?", 'g'); +} diff --git a/packages/react-server-gulp-module-tagger/test/fixtures/custom-token/expected.js b/packages/react-server-gulp-module-tagger/test/fixtures/custom-token/expected.js index b3afe9e3e..12853bd4f 100644 --- a/packages/react-server-gulp-module-tagger/test/fixtures/custom-token/expected.js +++ b/packages/react-server-gulp-module-tagger/test/fixtures/custom-token/expected.js @@ -1,3 +1,3 @@ var logger = require('react-server').logging.getLogger({"name":"react-server-gulp-module-tagger.test.fixtures.custom-token.actual","color":{"server":219,"client":"rgb(212,127,212)"}}); -var fooLogger = logging.getLogger({"label":"foo","name":"react-server-gulp-module-tagger.test.fixtures.custom-token.actual.foo","color":{"server":219,"client":"rgb(212,127,212)"}}); -var barLogger = logging.getLogger({"label":"bar","name":"react-server-gulp-module-tagger.test.fixtures.custom-token.actual.bar","color":{"server":219,"client":"rgb(212,127,212)"}}); +var fooLogger = logging.getLogger({"label":"foo","name":"react-server-gulp-module-tagger.test.fixtures.custom-token.actual.foo","color":{"server":83,"client":"rgb(42,212,42)"}}); +var barLogger = logging.getLogger({"label":"bar","name":"react-server-gulp-module-tagger.test.fixtures.custom-token.actual.bar","color":{"server":71,"client":"rgb(42,127,42)"}});