Skip to content

Commit

Permalink
fix a url march bug
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoluming committed May 11, 2016
1 parent 12fd791 commit 4ffda9b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
15 changes: 7 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ var fs = require("fs")

module.exports = function (options) {
return through.obj(function (file, enc, cb) {
var baseArr = file.base.split(/\/|\\/)
baseArr.pop()
var pathArr = file.path.split(/\/|\\/)
pathArr.pop()
var contents = file.contents.toString(enc).replace(/require\((["'])([\.\w\d\/]+)\1\)/g, function(req, quote, rawUrl) {
var urlArr = rawUrl.split("/")
var fileName = urlArr[urlArr.length-1]
Expand All @@ -18,27 +18,26 @@ module.exports = function (options) {
var url
switch (urlArr[0]) {
case ".." :
baseArr.pop()
pathArr.pop()
for (var i = 1; i < urlArr.length; i++) {
if (urlArr[i] == "..") {
baseArr.pop()
pathArr.pop()
} else {
baseArr.push(urlArr[i])
pathArr.push(urlArr[i])
}
}
url = baseArr.join("/")
url = pathArr.join("/")
break;
case "." :
urlArr.shift()
url = file.base + urlArr.join("/")
url = pathArr.join("/") + "/" + urlArr.join("/")
break;
default :
new gutil.PluginError({
plugin: 'module-bundler',
message: 'unsupported url'
});
}
gutil.log(url)
if (url) {
var text = fs.readFileSync(url, "utf8")
switch (suffix) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gulp-module-bundler",
"version": "0.1.1",
"version": "0.1.2",
"description": "A gulp plugin for bundle up the html files, css files and javascript file",
"keywords": [
"gulpplugin",
Expand Down

0 comments on commit 4ffda9b

Please sign in to comment.