gulp-pseudoconcat-js
Advanced tools
Comparing version 1.0.0 to 1.1.0
10
index.js
@@ -8,3 +8,5 @@ var Buffer = require('buffer').Buffer; | ||
module.exports = function(fileName, opt, remoteFiles) { | ||
var URL_SEPARATOR = '/'; | ||
module.exports = function(fileName, opt, remoteFiles) { | ||
remoteFiles = remoteFiles || []; | ||
@@ -49,3 +51,7 @@ | ||
var scripts = buffer.map(function(file) { | ||
return '<script src="' + path.relative(opt.webRoot, file.path) + '"></script>'; | ||
var scriptPath = path.relative(opt.webRoot, file.path); | ||
if (path.sep !== URL_SEPARATOR) { | ||
scriptPath = scriptPath.split(path.sep).join(URL_SEPARATOR); | ||
} | ||
return '<script src="' + scriptPath + '"></script>'; | ||
}); | ||
@@ -52,0 +58,0 @@ |
{ | ||
"name": "gulp-pseudoconcat-js", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Transform javascript files into <script> includes", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/MilanLempera/gulp-pseudoconcat-js", |
40
test.js
@@ -9,5 +9,5 @@ /* jshint node: true */ | ||
PassThrough = require('stream').PassThrough, | ||
path = require('path'), | ||
pseudoconcat = require('./index'); | ||
describe('gulp-pseudoconcat-js', function() { | ||
@@ -90,3 +90,2 @@ var onDataCalled; | ||
it('should not work in stream mode', function(done) { | ||
@@ -111,2 +110,39 @@ var stream = pseudoconcat('file.js'); | ||
}); | ||
describe('on windows', function() { | ||
var path_sep_original = path.sep; | ||
before(function(done) { | ||
path.sep = '\\'; | ||
done(); | ||
}); | ||
after(function(done) { | ||
path.sep = path_sep_original; | ||
done(); | ||
}); | ||
it('convert path to url', function(done) { | ||
var stream = pseudoconcat('file.js'); | ||
var fakeFile = new gutil.File({ | ||
path: 'src\\frontend\\first.js', | ||
contents: new Buffer('file1-content') | ||
}); | ||
stream.on('data', function(newFile) { | ||
onDataCalled = true; | ||
assert.equal('document.write(\'<script src="src/frontend/first.js"></script>\');', newFile.contents.toString()); | ||
}); | ||
stream.on('end', function() { | ||
assert.ok(onDataCalled, 'on data was called'); | ||
done(); | ||
}); | ||
stream.write(fakeFile); | ||
stream.end(); | ||
}); | ||
}); | ||
}); |
9924
172