-
Notifications
You must be signed in to change notification settings - Fork 82
/
config.js
63 lines (57 loc) · 1.27 KB
/
config.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
53
54
55
56
57
58
59
60
61
62
63
'use strict';
const path = require('path');
const lodash = require('lodash');
const out = require('./lib/out');
const cwd = process.cwd();
const token = process.env.YUQUE_TOKEN;
const defaultConfig = {
postPath: 'source/_posts/yuque',
cachePath: 'yuque.json',
lastGeneratePath: '',
mdNameFormat: 'title',
baseUrl: 'https://www.yuque.com/api/v2/',
token,
login: '',
repo: '',
adapter: 'hexo',
concurrency: 5,
onlyPublished: false,
onlyPublic: false,
imgCdn: {
concurrency: 0,
enabled: false,
imageBed: 'qiniu',
host: '',
bucket: '',
region: '',
prefixKey: '',
},
};
function loadConfig() {
const pkg = loadJson() || loadYaml();
if (!pkg) {
out.error('current directory should have a package.json');
return null;
}
const { yuqueConfig } = pkg;
if (!lodash.isObject(yuqueConfig)) {
out.error('package.yueConfig should be an object.');
return null;
}
const config = Object.assign({}, defaultConfig, yuqueConfig);
return config;
}
function loadJson() {
const pkgPath = path.join(cwd, 'package.json');
// out.info(`loading config: ${pkgPath}`);
try {
const pkg = require(pkgPath);
return pkg;
} catch (error) {
// do nothing
}
}
function loadYaml() {
// TODO
}
module.exports = loadConfig();