-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
70 lines (64 loc) · 3.05 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
/**
* gulpfile for magento 1/2 watcher based deployment
*
* @author Johann Zelger <[email protected]>
* @copyright 2016 TechDivision GmbH <[email protected]>
*/
// define dependencies
var gulp = require('gulp');
gutil = require('gulp-util');
watch = require('gulp-watch');
del = require('del');
exec = require('child_process').exec;
// define options for task usage
var options = {
module: '',
dev: {
src: 'src/**/*',
www: 'www/magento'
},
docker: {
container: 'dockermagento2_web_1',
basepath: '/var/www/magento/'
}
};
gulp.task('docker-deploy', function() {
exec('cd src && docker cp . ' + options.docker.container + ':' + options.docker.basepath + options.module);
});
/**
* Default task which watches all files in src and linked magento_coresources files for instant deployment
*/
gulp.task('default', function () {
gutil.log('Watching ', gutil.colors.blue("'src/**/*'"), 'for changes...');
return watch(options.dev.src, { events: ['add', 'unlink', 'change', 'unlinkDir'] }, function(file) {
// check if directory unlink is going on
if (file.event === 'unlinkDir') {
exec('docker exec -t ' + options.docker.container + ' rm -rf ' + options.docker.basepath + options.module + file.relative, function () {
gutil.log('Deleted', gutil.colors.magenta(file.relative), 'on', gutil.colors.blue(options.docker.container));
gutil.log(options.docker.basepath + options.module + file.relative);
});
exec('rm -rf ' + options.dev.www + options.module + file.relative);
return;
}
// check if file unlink is going on
if (file.event === 'unlink') {
exec('docker exec -t ' + options.docker.container + ' unlink ' + options.docker.basepath + options.module + file.relative, function () {
gutil.log('Deleted', gutil.colors.magenta(file.relative), 'on', gutil.colors.blue(options.docker.container));
gutil.log(options.docker.basepath + options.module + file.relative);
});
exec('unlink ' + options.dev.www + options.module + file.relative);
return;
}
// create directory first due to problems with addDir event
exec('docker exec -t ' + options.docker.container + ' mkdir -p ' + options.docker.basepath + options.module + file.relative.replace(file.basename, ""), function() {
// copy file
exec('docker cp ' + file.path + ' ' + options.docker.container + ':' + options.docker.basepath + options.module + file.relative, function () {
gutil.log('Copied', gutil.colors.magenta(file.relative), 'to', gutil.colors.blue(options.docker.container));
gutil.log(options.docker.basepath + options.module + file.relative);
});
});
exec('mkdir -p ' + options.dev.www + options.module + file.relative.replace(file.basename, ""), function() {
exec('cp ' + file.path + ' ' + options.dev.www + options.module + file.relative);
});
});
});