1 | var fileUtil = require('./fileUtil');
|
2 |
|
3 | var defaultConfigPath = './.autocode/config.json';
|
4 |
|
5 |
|
6 | function initConfig() {
|
7 | var defaultConfig = {
|
8 | author: 'yourname',
|
9 | email: 'youremail',
|
10 | tplDir: './.autocode/tpl',
|
11 | destDir: {
|
12 | 'modname': 'yourdestdir'
|
13 | }
|
14 | };
|
15 |
|
16 | fileUtil.writeFile(defaultConfigPath, JSON.stringify(defaultConfig, null, 4));
|
17 | fileUtil.createDir(defaultConfig.tplDir);
|
18 | }
|
19 |
|
20 | function hasConfig(){
|
21 | return fileUtil.has(defaultConfigPath);
|
22 | }
|
23 |
|
24 | function getConfig() {
|
25 | if (!fileUtil.has(defaultConfigPath)) {
|
26 | console.error('file: `' + defaultConfigPath + '` not exists!');
|
27 | }
|
28 | var content = fileUtil.readFile(defaultConfigPath);
|
29 | return JSON.parse(content);
|
30 | }
|
31 |
|
32 |
|
33 | module.exports = {
|
34 | initConfig: initConfig,
|
35 | getConfig: getConfig,
|
36 | hasConfig: hasConfig
|
37 | }; |
\ | No newline at end of file |