Skip to content

Commit fc35579

Browse files
committed
feature(spawnify) add support of "~" and "." directory in options.cwd
1 parent f2c7f46 commit fc35579

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

lib/spawnify.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929

3030
assert(command, 'command could not be empty!');
3131

32-
if (!options)
32+
if (options && options.cwd)
33+
options.cwd = parseDir(options.cwd);
34+
else
3335
options = {
3436
cwd: process.cwd()
3537
};
@@ -39,6 +41,20 @@
3941
return spawnify;
4042
};
4143

44+
function parseDir(dir) {
45+
var HOME_WIN = process.env.HOMEPATH,
46+
HOME_UNIX = process.env.HOME,
47+
HOME = HOME_WIN || HOME_UNIX,
48+
cwd = process.cwd();
49+
50+
assert(dir, 'dir should be string!');
51+
52+
dir = dir.replace(/^~/, HOME)
53+
.replace(/^\./, cwd);
54+
55+
return dir;
56+
}
57+
4258
function Spawnify(command, options) {
4359
var self = this;
4460

0 commit comments

Comments
 (0)