Last active
June 16, 2021 10:18
-
-
Save rizqyhi/020c4932401a48b64b87baed701797d3 to your computer and use it in GitHub Desktop.
Deploy via FTP with Yarn dan ftp-deploy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const FtpDeploy = require('ftp-deploy'); | |
const chalk = require('chalk'); | |
const ora = require('ora'); | |
const logSymbols = require('log-symbols'); | |
const deployer = new FtpDeploy(); | |
const config = { | |
username: 'your-ftp-username', | |
password: 'your-ftp-password', | |
host: 'your-server.com', | |
port: 21, | |
localRoot: __dirname + '/dist', | |
remoteRoot: '/', | |
exclude: ['.DS_Store'] | |
} | |
console.log(chalk.blue('Launching deploy ship...')); | |
console.log(chalk.blue('========================')); | |
const connectSpinner = ora('Contacting server').start(); | |
const progressSpinner = ora('Uploading'); | |
const fileSpinner = ora(); | |
deployer.deploy(config, function(err) { | |
if (err) { | |
connectSpinner.fail(chalk.red('ERROR') + ' ' + err.message); | |
process.exit(1); | |
} else { | |
console.log(chalk.green(logSymbols.success + ' DEPLOY SUCCESS')); | |
process.exit(); | |
} | |
}); | |
deployer.on('error', function(err) { | |
connectSpinner.fail(chalk.red('ERROR') + ' ' + err.message); | |
}); | |
const progress = {}; | |
deployer.on('uploading', function(data) { | |
if (data.transferredFileCount < 1) connectSpinner.succeed('Start uploading process'); | |
progress[data.filename] = ora('[ ' + (data.transferredFileCount + 1) + '/' + data.totalFileCount + ' ] ' + data.filename).start(); | |
}); | |
deployer.on('uploaded', function(data) { | |
progress[data.filename].succeed(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks to share!
BTW
progressSpinner
andfileSpinner
has never used.