-
Notifications
You must be signed in to change notification settings - Fork 25
/
bootstrapSassPath.js
40 lines (35 loc) · 1.01 KB
/
bootstrapSassPath.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
var fs = require('fs');
var path = require('path');
function bootstrapNotFound() {
var msg = 'Could not find path to bootstrap-sass. Check to see that it is in a parent ' +
'directory of config file containing node_modules/bootstrap-sass';
console.error('ERROR: ' + msg);
throw new Error(msg);
}
function createTestParentPath(configPath, nLevelsUp) {
var parentPath;
var i;
var levelsUp = configPath;
for (i = 0; i < nLevelsUp; i++) {
levelsUp += '/..';
}
parentPath = path.resolve(levelsUp);
if (parentPath === '/') {
bootstrapNotFound();
}
return path.resolve(path.join(levelsUp, 'node_modules', 'bootstrap-sass'));
}
module.exports = {
getPath: function(configPath) {
var bootstrapSassParentPath;
var i = 0;
do {
bootstrapSassParentPath = createTestParentPath(configPath, i);
i += 1;
} while (!fs.existsSync(bootstrapSassParentPath) && i < 10);
if (i === 10) {
bootstrapNotFound();
}
return path.join(bootstrapSassParentPath, 'assets');
}
};