1 | (function(){
|
2 | var fs=require('fs');
|
3 | var $=require('./$');
|
4 | var syspath=require('path');
|
5 |
|
6 | var file=fs.readFileSync(syspath.join(__dirname, "../package.json"));
|
7 |
|
8 | $.extend(exports,JSON.parse(file.toString()));
|
9 |
|
10 | exports.getConfig=function(root){
|
11 | var path;
|
12 | if(root){
|
13 | path=syspath.join(root,'.config');
|
14 | }else{
|
15 | path=syspath.join(process.cwd(),'.config');
|
16 | }
|
17 |
|
18 | if(fs.existsSync(path)){
|
19 | try{
|
20 | return JSON.parse(fs.readFileSync(path).toString());
|
21 | }catch(e){
|
22 | console.info('[ERROR]'.red,path+' 格式有误');
|
23 | return false;
|
24 | }
|
25 | }else{
|
26 | console.info('[ERROR]'.red,path+' 不存在');
|
27 | return false;
|
28 | }
|
29 | };
|
30 | }).call(this); |
\ | No newline at end of file |