3
3
*/
4
4
var fs = require ( 'fs' ) ,
5
5
path = require ( 'path' ) ,
6
- format = function ( ) {
7
- } ;
6
+ os = require ( 'os' ) ;
7
+
8
+ var getIp = function ( ) {
9
+ var platform = os . platform ( ) ;
10
+ var interfaces = os . networkInterfaces ( ) ;
11
+ var IPv4 = '127.0.0.1' ;
12
+
13
+ if ( platform === 'win32' ) {
14
+ var addressMes = interfaces [ '本地连接' ] ;
15
+ if ( addressMes && addressMes . length ) {
16
+ for ( var i = 0 ; i < addressMes . length ; i ++ ) {
17
+ if ( addressMes [ i ] [ 'family' ] && addressMes [ i ] [ 'family' ] === 'IPv4' ) {
18
+ return addressMes [ i ] [ 'address' ] ;
19
+ }
20
+ }
21
+ }
22
+ } else {
23
+ for ( var key in interfaces ) {
24
+ interfaces [ key ] . forEach ( function ( details ) {
25
+ if ( details . family == 'IPv4' && key == 'en0' ) {
26
+ IPv4 = details . address ;
27
+ }
28
+ } ) ;
29
+ }
30
+ }
31
+
32
+ return IPv4 ;
33
+ }
8
34
9
35
module . exports = function ( config ) {
10
36
var html = [
@@ -30,7 +56,8 @@ module.exports = function (config) {
30
56
] . join ( '' ) ,
31
57
tmpHtml = '' ,
32
58
length = '/dev/html/' . length ,
33
- collector = listdir ( './dev/html' ) ;
59
+ collector = listdir ( './dev/html' ) ,
60
+ ip = getIp ( ) ;
34
61
35
62
36
63
showdir ( collector , 0 ) ;
@@ -99,7 +126,7 @@ module.exports = function (config) {
99
126
100
127
html = html + tmpHtml ;
101
128
102
- html += '</tbody></table><div id="qrcode"></div><script src="http://wximg.gtimg.com/tmt/tools/file-list/js/jquery-2.1.3.min.js"></script><script src="http://wximg.gtimg.com/tmt/tools/file-list/js/qrcode.min.js"></script><script type="text/javascript">$(document).ready(function(){document.title= "' + config . projectName + ' 资源列表"; $(".level1").prependTo(".table-body"); $(".td-qrcode i").bind("mouseenter ",function(){$("#qrcode").show().empty();new QRCode(document.getElementById("qrcode"), encodeURI(window.location.href .split("TmTIndex.html")[0]+$(this).parent().parent().find("a").attr("href")));});$("body").bind("click",function(){$("#qrcode").hide();});});</script></body></html>' ;
129
+ html += '</tbody></table><div id="qrcode"></div><script src="http://wximg.gtimg.com/tmt/tools/file-list/js/jquery-2.1.3.min.js"></script><script src="http://wximg.gtimg.com/tmt/tools/file-list/js/qrcode.min.js"></script><script type="text/javascript">$(document).ready(function(){ var url = location.href.replace("localhost", "' + ip + '"); document.title= "' + config . projectName + ' 资源列表"; $(".level1").prependTo(".table-body"); $(".td-qrcode i").bind("mouseenter ",function(){$("#qrcode").show().empty();new QRCode(document.getElementById("qrcode"), encodeURI(url .split("TmTIndex.html")[0]+$(this).parent().parent().find("a").attr("href")));});$("body").bind("click",function(){$("#qrcode").hide();});});</script></body></html>' ;
103
130
104
131
var out = fs . createWriteStream ( './dev/html/TmTIndex.html' , { encoding : "utf8" } ) ;
105
132
out . write ( html , function ( err ) {
0 commit comments