Skip to content

Instantly share code, notes, and snippets.

@rizqyhi
Last active Jun 16, 2021
Embed
What would you like to do?
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

alvaro-canepa commented Jun 16, 2021

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