Skip to content

Instantly share code, notes, and snippets.

@tajidyakub
Last active July 9, 2018 13:00
Show Gist options
  • Save tajidyakub/46586ac7fb1821724c9b8557b5211f99 to your computer and use it in GitHub Desktop.
Save tajidyakub/46586ac7fb1821724c9b8557b5211f99 to your computer and use it in GitHub Desktop.
Grunt config file for deployment via rsync

Deploy with Grunt Rsync

Dengan asumsi workspace kita memiliki struktur direktori dengan source file di dalam src, contoh untuk WordPress themes development

.<workspace_root>
|--node_modules/
|  |--module_1/
|  |--module_2/
|--src/
|  |--assets/
|  |--scripts/
|  |--header.php
|  |--index.php
|--Gruntfile.js
|--package.json

Persiapan workspace

  • Lakukan initialisasi node project folder
  • Create src direktori dan pindahkan file kerja ke dalam direktori tersebut
  • Install module yang dibutuhkan yaitu grunt, grunt-cli, grunt-rsync
  • Definisikan task grunt di dalam Gruntfile
  • Pastikan bahwa yarn sudah terinstall secara global, untuk instalasi yarn silahkan jalankan perintah brew install yarn
$ mkdir project-wp-themes
$ cd project-wp-themes
$ yarn init -y
$ yarn add grunt grunt-cli grunt-rsync grunt-contrib-compress -D

Konfigurasi Grunt

File konfigurasi grunt khusus untuk keperluan ini dilampirkan, sesuaikan path yang didefinisikan. https://gist.githubusercontent.com/tajidyakub/46586ac7fb1821724c9b8557b5211f99/raw/9d88d8151dab36b20c88dc60d715e23041c9530e/Gruntfile.js

$ wget https://gist.githubusercontent.com/tajidyakub/46586ac7fb1821724c9b8557b5211f99/raw/9d88d8151dab36b20c88dc60d715e23041c9530e/Gruntfile.js

Setup SSH key untuk digunakan oleh rsync

Next

let remotepath = 'user@serveralias:/var/www/domain.tld/htdocs/wp-content/themes/projectname';
module.exports = function (grunt) {
grunt.initConfig({
rsync: {
options: {
args: ["--verbose"],
exclude: ["styles/*.*", ".git*", "*.scss", "node_modules"],
recursive: true
},
deploy: {
options: {
src: 'src/',
dest: remotepath,
delete: true
}
}
},
compress: {
main: {
options: {
archive: 'released/projectname.zip'
},
expand: true,
cwd: 'build/',
src: ['**/*'],
dest: '/'
}
}
});
// Next one would load plugins
grunt.loadNpmTasks('grunt-contrib-compress')
grunt.loadNpmTasks('grunt-rsync')
// Here is where we would define our task
grunt.registerTask('deploy', ['rsync:deploy'])
grunt.registerTask('release', ['compress'])
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment