-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
83 lines (69 loc) · 2.14 KB
/
gulpfile.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
'use strict';
var gulp = require('gulp');
var gutil = require('gulp-util');
var ftp = require('vinyl-ftp');
/** Configuration **/
var user = 'MY_FTP_USER_ID';
var password = 'MY_FTP_PASSWORD';
var host = 'MY_FTP_SITE';
var port = 21;
var localFilesGlob = ['./**/*'];
var remoteFolder = '/site/wwwroot'
// helper function to build an FTP connection based on our configuration
function getFtpConnection() {
return ftp.create({
host: host,
port: port,
user: user,
password: password,
parallel: 1,
log: gutil.log,
secure: false
});
}
/**
* Deploy task.
* Copies the new files to the server
*
* Usage: `FTP_USER=someuser FTP_PWD=somepwd gulp ftp-deploy`
*/
gulp.task('ftp-deploy', function () {
try {
var conn = getFtpConnection();
}
catch (e) {
console.error(e);
}
return gulp.src(localFilesGlob, { base: '.', buffer: false })
.pipe(conn.newer(remoteFolder)) // only upload newer files
.pipe(conn.dest(remoteFolder))
;
});
gulp.task('ftp-test', function () {
var watcher = gulp.watch('{*.js,*.html,*.css}');
watcher.on('change', function (event) {
console.log('File ' + event.path + ' was ' + event.type);
var conn = getFtpConnection();
return gulp.src([event.path], { base: '.', buffer: false })
.pipe(conn.newer(remoteFolder)) // only upload newer files
.pipe(conn.dest(remoteFolder))
;
});
});
/**
* Watch deploy task.
* Watches the local copy for changes and copies the new files to the server whenever an update is detected
*
* Usage: `FTP_USER=someuser FTP_PWD=somepwd gulp ftp-deploy-watch`
*/
gulp.task('ftp-deploy-watch', function () {
var conn = getFtpConnection();
gulp.watch(localFilesGlob)
.on('change', function (event) {
console.log('Changes detected! Uploading file "' + event.path + '", ' + event.type);
return gulp.src([event.path], { base: '.', buffer: false })
.pipe(conn.newer(remoteFolder)) // only upload newer files
.pipe(conn.dest(remoteFolder))
;
});
});