Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

faster-webpack-upload-plugin

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

faster-webpack-upload-plugin - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

README.md

2

package.json
{
"name": "faster-webpack-upload-plugin",
"version": "1.0.4",
"version": "1.0.5",
"author": "WangTieZhu92",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -28,3 +28,5 @@ 'use strict'

options.port = options.port || '22';
options.firstEmit = true;
options.firstEmit = options.firstEmit === undefined ? true : options.firstEmit;
this.upload = this.upload.bind(this);
}

@@ -35,5 +37,5 @@

if (compiler.hooks) {
compiler.hooks.afterEmit.tap('after-emit', this.upload(this.options));
compiler.hooks.afterEmit.tap('after-emit', this.upload);
} else {
compiler.plugin('after-emit', this.upload(this.options));
compiler.plugin('after-emit', this.upload);
}

@@ -43,67 +45,67 @@ }

upload(options) {
return async function (compilation) {
const {localPath, remotePath, log, clearFolder, ...others} = options;
const folders = [];
const files = [];
const uploadedFiles = [];
async upload(compilation) {
const {localPath, remotePath, log, clearFolder, ...others} = this.options;
const folders = [];
const files = [];
const uploadedFiles = [];
const sftp = new Client();
await sftp.connect({...others});
const sftp = new Client();
await sftp.connect({...others});
if (options.firstEmit) {
try {
await sftp.exists(remotePath);
if (clearFolder) {
log && console.log(chalk.red('clearing remote folder...'));
await sftp.rmdir(remotePath, true);
await sftp.mkdir(remotePath, true);
}
} catch (e) {
if (this.options.firstEmit) {
try {
await sftp.exists(remotePath);
if (clearFolder) {
log && console.log(chalk.red('Clearing remote folder...'));
await sftp.rmdir(remotePath, true);
await sftp.mkdir(remotePath, true);
}
} catch (e) {
await sftp.mkdir(remotePath, true);
}
getFolderNFiles(folders, files, localPath, remotePath);
getFolderNFiles(folders, files, localPath, remotePath);
options.firstEmit = false;
} else {
const assets = compilation.assets;
for (const file in assets) {
if (assets[file].emitted) {
files.push({
local: assets[file].existsAt,
remote: formatRemotePath(remotePath, file),
size: assets[file].size(),
})
}
this.options.firstEmit = false;
} else {
const assets = compilation.assets;
for (const file in assets) {
if (assets[file].emitted) {
files.push({
local: assets[file].existsAt,
remote: formatRemotePath(remotePath, file),
size: assets[file].size(),
})
}
}
}
if (folders.length > 0) {
log && console.log(chalk.green('creating remote folders...'));
await Promise.all(folders.map(folder => sftp.mkdir(folder).catch(() => log && console.log(chalk.yellow('folder create failed,it might exists')))));
}
if (folders.length > 0) {
log && console.log(chalk.green('Creating remote folders...'));
await Promise.all(folders.map(folder => sftp.mkdir(folder).catch(() => log && console.log(chalk.yellow('Folder create failed,it might exists')))));
}
const pb = new ProgressBar('', 50);
const pb = new ProgressBar('', 50);
if (files.length > 0) {
await Promise.all(files.map(file =>
sftp.fastPut(file.local, file.remote)
.catch(log && console.log)
.then(result => {
if (result) {
uploadedFiles.push(file);
pb.render({
percent: (uploadedFiles.length / files.length).toFixed(4),
completed: uploadedFiles.length,
total: files.length,
})
}
})));
if (files.length > 0) {
await Promise.all(files.map(file =>
sftp.fastPut(file.local, file.remote)
.catch(log && console.log)
.then(result => {
if (result) {
uploadedFiles.push(file);
pb.render({
percent: (uploadedFiles.length / files.length).toFixed(4),
completed: uploadedFiles.length,
total: files.length,
})
}
})));
log && console.log('\n' + chalk.green('upload done! files size: ' + (uploadedFiles.reduce((pre, next) => ({size: pre.size + next.size}), {size: 0}).size / 1000).toFixed(2) + ' KB'));
}
log && console.log('\n' + chalk.green('Upload done! Files size: ' + (uploadedFiles.reduce((pre, next) => ({size: pre.size + next.size}), {size: 0}).size / 1000).toFixed(2) + ' KB'));
}
await sftp.end();
}

@@ -110,0 +112,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc