-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
executable file
·175 lines (172 loc) · 6.77 KB
/
Gruntfile.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
'use strict';
module.exports = function(grunt) {
// load all grunt tasks matching the `grunt-*` pattern
require('load-grunt-tasks')(grunt);
grunt.initConfig({
// watch for changes and trigger sass and livereload (install livereload extension on your browser)
mysql: grunt.file.readJSON('site_settings.json'),
//timestamp: grunt.template.today('mm-dd-yyyy_HH-MM-ss'),
watch: {
options: {
livereload: true,
},
sass: {
files: ['scss/*.scss'],
tasks: ['sass']
}
},
// sass - automatically compiles sass
sass: {
dist: {
options: {
// I like my css compressed. You can change this to 'expand' for easier to read css
style: 'compressed',
},
files: {
'css/main.css': 'scss/main.scss'
}
}
},
//rsync commands for pulling and pushing to local, staging and production websites
rsync: {
options: {
args: ["--verbose"],
//Be sure to exclude any files that pose a security risk if published, or simply
//aren't needed for your site to function.
exclude: [".git*", "site_settings.json", "node_modules", "Gruntfile.js", "package.json", ".sass-cache*", "main.css.map"],
recursive: true
},
//Pushes wp-content from local to remote website
push_wp: {
options: {
src: "../../",
dest: "<%= mysql.remote.wpcontent_dir %>",
host: "<%= mysql.remote.username %>@<%= mysql.remote.host %>",
port: "<%= mysql.remote.port %>", //default SSH port is 22, some hosts move it
dryRun: false, //To test the rsync operation before performing a real transfer, change this to true
args: ["--links"],
delete: false // Careful this option could cause data loss, read the docs!
}
},
//Pushes theme from local to remote website
push_theme: {
options: {
src: "./",
dest: "<%= mysql.remote.theme_dir %>",
host: "<%= mysql.remote.username %>@<%= mysql.remote.host %>",
port: "<%= mysql.remote.port %>", //default SSH port is 22, some hosts move it
dryRun: false, //To test the rsync operation before performing a real transfer, change this to true
args: ["--links"],
delete: false // Careful this option could cause data loss, read the docs!
}
},
//Pulls wp-content from remote site
pull: {
options: {
ssh: true,
src: "<%= mysql.remote.username %>@<%= mysql.remote.host %>:<%= mysql.remote.wpcontent_dir %>",
dest: "../../",
port: "<%= mysql.remote.port %>", //default SSH port is 22, some hosts move it
dryRun: false, //To test the rsync operation before performing a real transfer, change this to true
args: ["--links"],
delete: false // Careful this option could cause data loss, read the docs!
}
}
},
sshexec: {
dump_remote_db: {
options: {
host: '<%= mysql.remote.host %>',
username: '<%= mysql.remote.username %>',
password: '<%= mysql.remote.password %>',
port: '<%= mysql.remote.port %>'
},
command: 'cd <%= mysql.remote.db_save_path %> && mysqldump <%= mysql.remote.dbname %> -u <%= mysql.remote.dbuser %> -p<%= mysql.remote.dbpass %> > remote.sql'
},
cleanup_remote: {
options: {
host: '<%= mysql.remote.host %>',
username: '<%= mysql.remote.username %>',
password: '<%= mysql.remote.password %>',
port: '<%= mysql.remote.port %>'
},
command: 'cd <%= mysql.remote.db_save_path %> && rm local_migrated.sql'
},
cleanup_remote_dump: {
options: {
host: '<%= mysql.remote.host %>',
username: '<%= mysql.remote.username %>',
password: '<%= mysql.remote.password %>',
port: '<%= mysql.remote.port %>'
},
command: 'cd <%= mysql.remote.db_save_path %> && rm remote.sql'
},
import_migrated_local_dump: {
options: {
host: '<%= mysql.remote.host %>',
username: '<%= mysql.remote.username %>',
password: '<%= mysql.remote.password %>',
port: '<%= mysql.remote.port %>'
},
command: 'cd <%= mysql.remote.db_save_path %> && mysql -u <%= mysql.remote.dbuser %> -p<%= mysql.remote.dbpass %> <%= mysql.remote.dbname %> < local_migrated.sql'
},
search_replace_remote: {
options: {
host: '<%= mysql.remote.host %>',
username: '<%= mysql.remote.username %>',
password: '<%= mysql.remote.password %>',
port: '<%= mysql.remote.port %>'
},
command: 'cd <%= mysql.remote.db_save_path %> && mysql -u <%= mysql.remote.dbuser %> -p<%= mysql.remote.dbpass %> <%= mysql.remote.dbname %> < local.sql'
}
},
exec: {
wget_remote_dump: {
command: 'wget -nv <%= mysql.remote.db_save_url %>/remote.sql'
},
import_migrated_remote_dump: {
command: 'vagrant ssh -c "cd <%= mysql.local.db_dump_dir %> && mysql -u <%= mysql.local.dbuser %> -p<%= mysql.local.dbpass %> <%= mysql.local.dbname %> < remote_migrated.sql"'
},
cleanup_local: {
command: 'rm -rf local.sql && rm -rf local_migrated.sql'
},
cleanup_local_from_remote: {
command: 'rm -rf remote.sql remote.sql && rm -rf remote_migrated.sql'
},
dump_local_db: {
command: 'vagrant ssh -c "mysqldump -u <%= mysql.local.dbuser %> -p<%= mysql.local.dbpass %> <%= mysql.local.dbname %> > <%= mysql.local.db_dump_dir %>local.sql"'
},
scp_local_dump: {
command: 'scp -P <%= mysql.remote.port %> <%= mysql.local.db_local_dump_dir %>local_migrated.sql <%= mysql.remote.username %>@<%= mysql.remote.host %>:<%= mysql.remote.db_save_path %>'
},
search_replace_local: {
command: 'sed "s/<%= mysql.remote.sr_remote %>/<%= mysql.local.sr_local %>/g" remote.sql > remote_migrated.sql'
},
search_replace_remote: {
command: 'sed "s/<%= mysql.local.sr_local %>/<%= mysql.remote.sr_remote %>/g" local.sql > local_migrated.sql'
}
}
});
// register tasks, change names of default grunt commands.
grunt.registerTask('default', ['sass', 'watch']);
grunt.registerTask('stage', ['rsync:stage']);
grunt.registerTask('push_wp', ['rsync:push_wp']);
grunt.registerTask('push_theme', ['rsync:push_theme']);
grunt.registerTask('pull', ['rsync:pull']);
grunt.registerTask('pull_db', [
'sshexec:dump_remote_db', //dump remote database
'exec:wget_remote_dump', //download remote dump
'sshexec:cleanup_remote_dump', //delete remote dump
'exec:search_replace_local', //search replace local
'exec:import_migrated_remote_dump', //import the migrated database
'exec:cleanup_local_from_remote' //delete local database dump files
]);
grunt.registerTask('push_db', [
'exec:dump_local_db', //dump local database
'exec:search_replace_remote', //search replace remote
'exec:scp_local_dump', //upload local dump
'exec:cleanup_local', //delete local database dump files
'sshexec:import_migrated_local_dump', //import the migrated database
'sshexec:cleanup_remote' //delete remote database dump file
]);
};