-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathutils.js
52 lines (37 loc) · 1010 Bytes
/
utils.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
51
52
'use strict';
function getConfigPath(project) {
let configDir = 'config';
if (project.pkg['ember-addon'] && project.pkg['ember-addon']['configPath']) {
configDir = project.pkg['ember-addon']['configPath'];
}
return `./${configDir}/optional-features.json`;
}
function join(strings /*, ...args */) {
let parts = [];
for (let i = 0; i < strings.length - 1; i++) {
parts.push(strings[i], arguments[i + 1]);
}
parts.push(strings[strings.length - 1]);
return parts.join('');
}
function strip(/* strings, ...args */) {
let string = join.apply(undefined, arguments);
let lines = string.split('\n');
if (lines[0] === '') {
lines.shift();
}
if (lines.length === 0) {
return '';
}
let last = lines[lines.length - 1];
if (last.trim() === '') {
lines[lines.length - 1] = last.trim();
}
let indent = lines[0].match(/^ */)[0];
return lines.map((line) => line.replace(indent, '')).join('\n');
}
module.exports = {
getConfigPath,
join,
strip,
};