forked from a597873885/webfunny-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.js
105 lines (96 loc) · 3.06 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
* 复制目录中的所有文件包括子目录
* @param{ String } 需要复制的目录
* @param{ String } 复制到指定的目录
*/
var copy = function( src, dst ){
// 读取目录中的所有文件/目录
fs.readdir( src, function( err, paths ){
if( err ){ throw err; }
paths.forEach(function( path ){
var _src = src + '/' + path,
_dst = dst + '/' + path,
readable, writable;
stat( _src, function( err, st ){
if( err ){ throw err; }
// 判断是否为文件
if( st.isFile() ){
// 创建读取流
readable = fs.createReadStream( _src );
// 创建写入流
writable = fs.createWriteStream( _dst );
// 通过管道来传输流
readable.pipe( writable );
}
// 如果是目录则递归调用自身
else if( st.isDirectory() ){
exists( _src, _dst, copy );
}
});
});
});
};
// 在复制目录前需要判断该目录是否存在,不存在需要先创建目录
var exists = function( src, dst, callback ){
fs.exists( dst, function( exists ){
// 已存在
if( exists ){
callback( src, dst );
}
// 不存在
else{
fs.mkdir( dst, function(){
callback( src, dst );
});
}
});
};
/**
* 请先配置您的域名!!!
*/
/**
* 请求接口域名 webfunny-servers 的服务的部署域名
* 本地请使用 "//localhost:8011"
*/
const default_api_server_url = "//localhost:8011"
/**
* 静态资源域名 webfunny-admin 的部署域名
* 本地请使用 "//localhost:8010"
*/
const default_assets_url = "//localhost:8010"
/** 重要! 重要! 重要! 这里一定要配置的*/
const customerConfig = {
default_api_server_url,
default_assets_url
}
var fs = require('fs');
stat = fs.stat;
fs.mkdir( "./webfunny", function(err){
if ( err ) {
console.log("文件夹 webfunny 已经存在")
} else {
console.log("创建文件夹 webfunny")
}
});
copy("./resource/", "./webfunny")
console.log("===========================")
console.log("= 正在执行编译,请等待... =")
console.log("===========================")
setTimeout(function() {
let path = './webfunny';
let files = fs.readdirSync(path);
for(let i = 0; i < files.length; i++){
if ( !(files[i].indexOf(".js") >= 0 || files[i].indexOf(".html") >= 0) ) {
continue
}
fs.readFile(`${path}/${files[i]}`,function(err, data){
if (data.indexOf("default_api_server_url") >= 0 || data.indexOf("default_assets_url") >= 0 ) {
let newString = data.toString().replace(/default_api_server_url/g, customerConfig.default_api_server_url).replace(/default_assets_url/g, customerConfig.default_assets_url)
fs.writeFile(`${path}/${files[i]}`, newString, (err) => {
if (err) throw err;
console.log(files[i] + " 接口域名配置成功!");
});
}
})
}
}, 3000)