This repository has been archived by the owner on Jul 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
63 lines (58 loc) · 2.92 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
// 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: 'app/code/Vendor/MyModule/',
dev: {
src: 'src/**/*',
www: 'www/magento/'
},
docker: {
container: 'magento2_instance',
basepath: '/var/www/magento/'
}
};
gulp.task('docker-deploy', function () {
exec('cd ' + options.dev.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(options.dev.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);
});
});
});