Skip to content

Instantly share code, notes, and snippets.

@uselessdev
Created March 26, 2020 15:08
Show Gist options
  • Save uselessdev/1122e2ef7571d3708b1ee7cf904b8bd0 to your computer and use it in GitHub Desktop.
Save uselessdev/1122e2ef7571d3708b1ee7cf904b8bd0 to your computer and use it in GitHub Desktop.
Gist com tarefas de gulp onde fiz a gambiarra mais legal da minha vida.
'use strict';
const usrKey = process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME']
module.exports = {
styl: {
'src': './src/assets/stylus/*.styl',
'dist': './src/assets/styles',
'watch': './src/assets/stylus',
'compiled': './dist/assets/styles'
},
scripts: {
'src': ['./src/assets/scripts/*.js', '!./src/assets/scripts/*.min.js'],
'watch': './src/assets/scripts',
'dist': './src/assets/scripts',
'min': './src/assets/scripts/*.min.js',
'compiled': './dist/assets/scripts',
'options' : {
'transform': ['babelify']
}
},
pug: {
'src': './src/views/_pages/*.pug',
'watch': './src/views',
'dist': './src',
'compiled': './dist'
},
sync: {
src: './dist/*',
dest: 'user@host:path/to/deploy',
recursive: true,
args: ['--verbose'],
delete: true, // deleteAll
compare: 'checksum',
exclude: [],
include: [],
onStdout: data => console.log(data.toString())
},
roll: {
host: 'hostname',
user: 'username',
key: usrKey + '/.ssh/id_rsa',
path: 'remote/path'
}
};
/**
* \tasks\deploy
*/
'use strict'
const gulp = require('gulp')
, zip = require('gulp-zip')
, version = require('../package.json').version
, rsync = require('rsyncwrapper')
, options = require('./boost').sync
module.exports = gulp.task('zip', () => {
version = version || '0.1.0'
gulp.src(['./dist/**', '!./dist/*.zip'])
.pipe(zip(version + '.zip'))
.pipe(gulp.dest('./dist'))
})
module.exports = gulp.task('deploy', ['zip'], () => {
rsync(options, (error, stdout, stderr, cmd) => {
if (error) {
console.log('Error: ' + error.message)
} else {
console.log('Successfully deployed files')
}
})
})
/**
* \tasks\rollback
*/
'use strict'
const gulp = require('gulp')
, fs = require('fs')
, ssh = require('gulp-ssh')
, version = require('../package.json').version
, options = require('./boost').roll
, args = process.argv.splice(3, process.argv.length -1)
const config = {
host: options.host,
username: options.user,
privateKey: fs.readFileSync(options.key)
}
let gulpSSH = new ssh({
ignoreErrors: false,
sshConfig: config
})
module.exports = gulp.task('rollback', () => {
let target = args[1] + '.zip'
let commands = [
'cd' + options.path,
'find . -type f -not -name \'*.zip\' -print0 | xargs -0 rm --',
'find . -type d -print0 | xargs -0 rm -R',
'unzip ' + target
]
return gulpSSH.shell(commands, {filePath: 'test.log'})
.pipe(gulp.dest('./'))
.on('end', () => {
console.log(fs.readFileSync('./test.log').toString())
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment