forked from weblee-co/weblee-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.js
More file actions
60 lines (52 loc) · 1.8 KB
/
config.js
File metadata and controls
60 lines (52 loc) · 1.8 KB
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
53
54
55
56
57
58
59
60
const path = require('path');
const fs = require('fs');
const utils = require('./lib/utils');
const rootDirectory = utils.getPackageJSONDir();
const jsonConfig = (function getProjectConfig() {
const projectConfigNames = [
'weblee.config.json',
'weblee-config.json'
];
try {
const projectRootFiles = fs.readdirSync(rootDirectory);
const projectConfigName = projectRootFiles.find(filename => {
return projectConfigNames.includes(filename);
});
if (!projectConfigName) {
throw new Error(`Could not find a valid weblee-utils config file (${projectConfigNames.join('|')}) in path '${rootDirectory}'`);
}
return JSON.parse(fs.readFileSync(path.resolve(rootDirectory, projectConfigName), 'utf8'));
} catch (err) {
console.error(err);
return {tasks: []};
}
})();
const avocodeDefaults = {
userSelector: null,
projectSelector: 'boilerplate'
};
const avocodeConfig = Object.assign({}, avocodeDefaults,jsonConfig.avocode);
const wordpressConfig = Object.assign({}, jsonConfig.wordpress);
const projectName = jsonConfig.name || 'boilerplate';
const paths = {
rootDir: rootDirectory,
tmpDir: jsonConfig.tmp || path.resolve(rootDirectory, 'tmp/')
};
switch (jsonConfig.workingDir) {
case 'default':
paths.workingDir = rootDirectory;
break;
case 'wordpress':
const themeDir = jsonConfig.wordpress && jsonConfig.wordpress.themeDir;
paths.workingDir = path.join(rootDirectory, `wp-content/themes/${themeDir || projectName}/`);
break;
default:
paths.workingDir = path.normalize(jsonConfig.workingDir || rootDirectory);
}
module.exports = {
raw: jsonConfig,
wordpress: wordpressConfig,
avocode: avocodeConfig,
projectName,
paths
};