1
|
'use strict';
|
2
|
const path = require('path');
|
3
|
const commonDir = require('commondir');
|
4
|
const pkgDir = require('pkg-dir');
|
5
|
const makeDir = require('make-dir');
|
6
|
|
7
|
module.exports = options => {
|
8
|
const name = options.name;
|
9
|
let dir = options.cwd;
|
10
|
|
11
|
if (options.files) {
|
12
|
dir = commonDir(dir, options.files);
|
13
|
} else {
|
14
|
dir = dir || process.cwd();
|
15
|
}
|
16
|
|
17
|
dir = pkgDir.sync(dir);
|
18
|
|
19
|
if (dir) {
|
20
|
dir = path.join(dir, 'node_modules', '.cache', name);
|
21
|
|
22
|
if (dir && options.create) {
|
23
|
makeDir.sync(dir);
|
24
|
}
|
25
|
|
26
|
if (options.thunk) {
|
27
|
return function () {
|
28
|
return path.join.apply(path, [dir].concat(Array.prototype.slice.call(arguments)));
|
29
|
};
|
30
|
}
|
31
|
}
|
32
|
|
33
|
return dir;
|
34
|
};
|