Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rizqyhi
Last active June 16, 2021 10:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rizqyhi/020c4932401a48b64b87baed701797d3 to your computer and use it in GitHub Desktop.
Save rizqyhi/020c4932401a48b64b87baed701797d3 to your computer and use it in GitHub Desktop.
Deploy via FTP with Yarn dan ftp-deploy
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();
});
@alvaro-canepa
Copy link

Thanks to share!
BTW progressSpinner and fileSpinner has never used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment