@@ -6,6 +6,7 @@ var marked = require('marked');
66var watch = require ( 'watch' ) ;
77var stylus = require ( 'stylus' )
88var highlight = require ( 'highlight.js' )
9+ var UglifyJS = require ( "uglify-js" ) ;
910var renderer = new marked . Renderer ( ) ;
1011var color = require ( 'colors-cli/safe' ) ;
1112var error = color . red . bold ;
@@ -58,13 +59,10 @@ exec('rm -rf .deploy');
5859// 生成 项目所需的文件
5960CreateDatajs ( './.deploy/js/dt.js' , function ( dt_path , arr ) {
6061
61- cp ( path . join ( path_root , '/template/js/index.js' ) ,
62- path . join ( path_root , '/.deploy/js/index.js' ) , function ( err , r ) {
63- if ( err ) return console . log ( error ( " → error:" ) , err . errno ) ;
64- console . log ( success ( " → " ) + '/template/js/index.js' ) ;
65- } )
62+ CreateJS ( '/template/js/index.js' , '/.deploy/js/index.js' )
6663
6764 CreateStyl ( '/template/styl/index.styl' , '/.deploy/css/index.css' )
65+
6866 // 首页生成
6967 ReadTmpToHTML ( '/template/index.ejs' , '/.deploy/index.html' , null , {
7068 'p' :'/index.html' ,
@@ -102,11 +100,7 @@ watch.watchTree(path.join(path.dirname(__dirname),'/'), function (f, curr, prev)
102100 CreateStyl ( '/template/styl/index.styl' , '/.deploy/css/index.css' )
103101 } else if ( / \. j s $ / . test ( f ) ) {
104102
105- cp ( path . join ( path_root , '/template/js/index.js' ) ,
106- path . join ( path_root , '/.deploy/js/index.js' ) , function ( err , r ) {
107- if ( err ) return console . log ( error ( " → error:" ) , err . errno ) ;
108- console . log ( success ( " → " ) + '/template/js/index.js' ) ;
109- } )
103+ CreateJS ( '/template/js/index.js' , '/.deploy/js/index.js' )
110104
111105 } else if ( / \. e j s $ / . test ( f ) ) {
112106 // 首页生成
@@ -122,6 +116,18 @@ watch.watchTree(path.join(path.dirname(__dirname),'/'), function (f, curr, prev)
122116} )
123117
124118
119+ function CreateJS ( from_path , to_path ) {
120+
121+ // 生成到指定目录
122+ var new_to_path = path . join ( path . dirname ( __dirname ) , to_path ) ;
123+ // 循环创建目录
124+ mkdirsSync ( path . dirname ( new_to_path ) ) ;
125+ var js_code = UglifyJS . minify ( path . join ( path_root , from_path ) , { mangle : { toplevel : true } } ) ;
126+ fs . writeFileSync ( new_to_path , js_code . code ) ;
127+ console . log ( success ( " → " ) + to_path + '' ) ;
128+
129+ }
130+
125131/**
126132 * [ReadTmpToHTML ejs 模板转换成HTML]
127133 * @param {[type] } from_path [模版来源地址]
0 commit comments