@@ -6,70 +6,67 @@ const gulp = require('gulp');
6
6
const _ = require ( 'lodash' ) ;
7
7
const del = require ( 'del' ) ;
8
8
const ftp = require ( 'gulp-ftp' ) ;
9
+ const gutil = require ( 'gulp-util' ) ;
9
10
const Common = require ( path . join ( __dirname , '../common' ) ) ;
10
11
11
12
module . exports = function ( projectPath , log , callback ) {
12
13
13
- let projectConfigPath = path . join ( projectPath , 'weflow.config.json' ) ;
14
- let config = null ;
14
+ let distDir = path . join ( projectPath , './dist' ) ;
15
15
16
- if ( Common . fileExist ( projectConfigPath ) ) {
17
- config = Common . requireUncached ( projectConfigPath ) ;
18
- } else {
19
- config = Common . requireUncached ( path . join ( __dirname , '../../weflow.config.json' ) ) ;
20
- }
16
+ let projectConfigPath = path . join ( projectPath , 'weflow.config.json' ) ;
17
+ let config = null ;
21
18
22
- let configFTP = config . ftp ;
19
+ if ( Common . fileExist ( projectConfigPath ) ) {
20
+ config = Common . requireUncached ( projectConfigPath ) ;
21
+ } else {
22
+ config = Common . requireUncached ( path . join ( __dirname , '../../weflow.config.json' ) ) ;
23
+ }
23
24
24
- if ( configFTP . host === '' || configFTP . pass === '' || configFTP . user === '' ) {
25
- callback ( 'ftp config' ) ;
26
- return ;
27
- }
25
+ let configFTP = config . ftp ;
28
26
29
- let projectName = path . basename ( projectPath ) ;
27
+ if ( configFTP . host === '' || configFTP . pass === '' || configFTP . user === '' ) {
28
+ callback ( 'ftp config' ) ;
29
+ return ;
30
+ }
30
31
31
- //清除目标目录
32
- function delDist ( cb ) {
33
- del ( path . join ( projectPath , './dist' ) , { force : true } ) . then ( function ( ) {
34
- cb && cb ( ) ;
35
- } )
36
- }
32
+ let projectName = path . basename ( projectPath ) ;
33
+
34
+ //清除目标目录
35
+ function delDist ( cb ) {
36
+ del ( path . join ( projectPath , './dist' ) , { force : true } ) . then ( function ( ) {
37
+ cb && cb ( ) ;
38
+ } )
39
+ }
37
40
38
- function remoteFtp ( cb ) {
39
- let remotePath = config [ 'ftp' ] [ 'remotePath' ] || "" ;
40
- let ftpConfig = _ . extend ( config [ 'ftp' ] , {
41
- remotePath : path . join ( remotePath , projectName )
42
- } ) ;
43
- let distPath = config [ 'ftp' ] [ 'includeHtml' ] ? path . join ( projectPath , './dist/**/*' ) : [ path . join ( projectPath , './dist/**/*' ) , path . join ( projectPath , '!./dist/html/**/*.html' ) ] ;
41
+ function remoteFtp ( cb ) {
42
+ let remotePath = config [ 'ftp' ] [ 'remotePath' ] || "" ;
43
+ let ftpConfig = _ . extend ( config [ 'ftp' ] , {
44
+ remotePath : path . join ( remotePath , projectName )
45
+ } ) ;
46
+ let distPath = config [ 'ftp' ] [ 'includeHtml' ] ? path . join ( projectPath , './dist/**/*' ) : [ path . join ( projectPath , './dist/**/*' ) , path . join ( projectPath , '!./dist/html/**/*.html' ) ] ;
44
47
45
- console . log ( ftpConfig )
46
- console . log ( distPath ) ;
48
+ gulp . src ( distPath )
49
+ . pipe ( ftp ( ftpConfig ) )
50
+ . pipe ( gutil . noop ( ) )
51
+ . pipe ( gulp . dest ( distDir ) )
52
+ . on ( 'end' , function ( ) {
53
+ console . log ( 'ftp success.' ) ;
54
+ log ( 'ftp success.' ) ;
55
+ cb && cb ( ) ;
56
+ } )
57
+ }
47
58
48
- gulp . src ( distPath )
49
- . pipe ( ftp ( ftpConfig ) )
50
- . on ( 'finish' , function ( ) {
51
- console . log ( 'sftp success.' ) ;
52
- log ( 'sftp success.' ) ;
53
- cb && cb ( ) ;
54
- } )
55
- . on ( 'end' , function ( ) {
56
- console . log ( 'ftp success.' ) ;
57
- log ( 'ftp success.' ) ;
58
- cb && cb ( ) ;
59
- } ) ;
59
+ async . series ( [
60
+ function ( next ) {
61
+ remoteFtp ( next ) ;
62
+ }
63
+ ] , function ( err ) {
64
+ if ( err ) {
65
+ throw new Error ( err ) ;
60
66
}
61
67
62
- async . series ( [
63
- function ( next ) {
64
- remoteFtp ( next ) ;
65
- }
66
- ] , function ( err ) {
67
- if ( err ) {
68
- throw new Error ( err ) ;
69
- }
70
-
71
- delDist ( ) ;
68
+ delDist ( ) ;
72
69
73
- callback && callback ( ) ;
74
- } ) ;
70
+ callback && callback ( ) ;
71
+ } ) ;
75
72
} ;
0 commit comments