-
-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
429 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
'use strict'; | ||
|
||
var assign = require('object-assign'); | ||
var path = require('path'); | ||
var through2 = require('through2'); | ||
var mkdirp = require('mkdirp'); | ||
var fs = require('graceful-fs'); | ||
|
||
function symlink(outFolder, opt) { | ||
opt = opt || {}; | ||
if (typeof outFolder !== 'string' && typeof outFolder !== 'function') { | ||
throw new Error('Invalid output folder'); | ||
} | ||
|
||
var options = assign({ | ||
cwd: process.cwd() | ||
}, opt); | ||
|
||
var cwd = path.resolve(options.cwd); | ||
|
||
function linkFile (file, enc, cb) { | ||
var basePath; | ||
if (typeof outFolder === 'string') { | ||
basePath = path.resolve(cwd, outFolder); | ||
} | ||
if (typeof outFolder === 'function') { | ||
basePath = path.resolve(cwd, outFolder(file)); | ||
} | ||
var writePath = path.resolve(basePath, file.relative); | ||
var writeFolder = path.dirname(writePath); | ||
var srcPath = file.path; | ||
|
||
// wire up new properties | ||
file.stat = file.stat ? file.stat : new fs.Stats(); | ||
file.stat.mode = (options.mode || file.stat.mode); | ||
file.cwd = cwd; | ||
file.base = basePath; | ||
file.path = writePath; | ||
|
||
// mkdirp the folder the file is going in | ||
mkdirp(writeFolder, function(err){ | ||
if (err) { | ||
return cb(err); | ||
} | ||
fs.symlink(srcPath, writePath, function (err) { | ||
if (err && err.code !== 'EEXIST') { | ||
return cb(err); | ||
} | ||
|
||
cb(null, file); | ||
}); | ||
}); | ||
} | ||
|
||
var stream = through2.obj(linkFile); | ||
// TODO: option for either backpressure or lossy | ||
stream.resume(); | ||
return stream; | ||
} | ||
|
||
module.exports = symlink; |
Oops, something went wrong.
so line 86 is essentially useless? I have a source js file in ./vendor/[module]/xx/yy/stuff/script.js that I want to place a symlink to inside ./pub/static/[completly_different_folder_structure]/script.js, I've managed to do this with the gulp-rename .. but now I want to place a symlink to the source file instead of copying it so I added vinyl-fs and changed:
but it seems this replaces the path.dirname so it becomes incorrect..