/
index.js
51 lines (42 loc) · 1.24 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict';
var path = require('path');
var normalizePath = require('normalize-path');
var isAbsolute = require('is-absolute');
var resolve = require('resolve');
exports.normalize = function(filepath) {
return filepath ? normalizePath(path.relative('.', filepath)) : null;
};
exports.chdir = function(dir) {
// store current cwd
var orig = process.cwd();
// set cwd to the given `dir`
process.chdir(dir);
return function() {
// restore original `cwd`
process.chdir(orig);
};
};
exports.npm = function npm(name) {
return path.dirname(resolve.sync(name));
};
exports.assert = function(assert) {
assert.isPath = function (filepath) {
assert(filepath);
assert.equal(typeof filepath, 'string');
};
assert.isAbsolute = function (filepath) {
assert(filepath);
assert.equal(typeof filepath, 'string');
assert(isAbsolute(filepath));
};
assert.basename = function (filepath, basename) {
assert(filepath);
assert.equal(typeof filepath, 'string');
assert.equal(path.basename(filepath), basename);
};
assert.dirname = function (filepath, dirname) {
assert(filepath);
assert.equal(typeof filepath, 'string');
assert.equal(path.dirname(path.resolve(filepath)), path.resolve(dirname));
};
};