faster-webpack-upload-plugin
Advanced tools
Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "faster-webpack-upload-plugin", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"author": "WangTieZhu92", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -41,66 +41,67 @@ 'use strict' | ||
upload = async (compilation) => { | ||
const {localPath, remotePath, log, clearFolder, ...others} = this.options; | ||
const folders = []; | ||
const files = []; | ||
const uploadedFiles = []; | ||
upload(options) { | ||
return async function (compilation) { | ||
const {localPath, remotePath, log, clearFolder, ...others} = options; | ||
const folders = []; | ||
const files = []; | ||
const uploadedFiles = []; | ||
const sftp = new Client(); | ||
await sftp.connect({...others}); | ||
const sftp = new Client(); | ||
await sftp.connect({...others}); | ||
if (this.firstEmit) { | ||
try { | ||
await sftp.exists(remotePath); | ||
if (clearFolder) { | ||
log && console.log(chalk.red('clearing remote folder...')); | ||
await sftp.rmdir(remotePath, true); | ||
if (this.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); | ||
} | ||
} catch (e) { | ||
await sftp.mkdir(remotePath, true); | ||
} | ||
getFolderNFiles(folders, files, localPath, remotePath); | ||
getFolderNFiles(folders, files, localPath, remotePath); | ||
this.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.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')); | ||
} | ||
} | ||
} | ||
@@ -107,0 +108,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6518
142