gulp-mixpanel
Advanced tools
Comparing version 0.1.0 to 0.2.0
13
index.js
@@ -16,9 +16,16 @@ var through = require('through2'); | ||
var stream = through.obj(function (file, enc, cb) { | ||
var | ||
script = config.template.replace(config.key, mixpanelToken), | ||
content = undefined | ||
; | ||
if (file.isBuffer()) { | ||
this.emit('error', new PluginError(PLUGIN_NAME, 'Buffers not supported!')); | ||
return cb(); | ||
content = file.contents.toString('utf8'); | ||
content = content.replace('</body>', script + '</body>'); | ||
file.contents = new Buffer(content); | ||
} | ||
if (file.isStream()) { | ||
file.contents = file.contents.pipe(rs('</body>', config.template.replace(config.key, mixpanelToken) + '</body>')); | ||
file.contents = file.contents.pipe(rs('</body>', script + '</body>')); | ||
} | ||
@@ -25,0 +32,0 @@ |
{ | ||
"name": "gulp-mixpanel", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Adds mixpanel analytics into your html file", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
35
test.js
@@ -9,6 +9,6 @@ var assert = require('assert'); | ||
describe('gulp-mixpanel', function () { | ||
describe('in streaming mode', function () { | ||
it('should prepend mixpanel script', function (done) { | ||
it('should prepend mixpanel script', function (done) { | ||
var token = "MY_TOKEN"; | ||
@@ -19,6 +19,6 @@ var html = new File({ | ||
}); | ||
var mixpanel = plugin(token); | ||
mixpanel.write(html); | ||
mixpanel.once('data', function (file) { | ||
@@ -32,5 +32,26 @@ assert(file.isStream()); | ||
}); | ||
}); | ||
describe('in buffer mode', function () { | ||
it('should prepend mixpanel script', function (done) { | ||
var token = "MY_TOKEN"; | ||
var html = new File({ | ||
cwd: '/', | ||
contents: new Buffer("<html><head></head><body></body></html>") | ||
}); | ||
var mixpanel = plugin(token); | ||
mixpanel.write(html); | ||
mixpanel.once('data', function (file) { | ||
assert(file.isBuffer()); | ||
assert.equal(file.contents.toString('utf8'), '<html><head></head><body>' + config.template.replace(config.key, token) + '</body></html>'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5644
76