Skip to content

Commit 1f96f4c

Browse files
committed
reduces the amount of Promise.all and Array.map
1 parent 33b9b95 commit 1f96f4c

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

src/target/mm-preview.js

+10-15
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,17 @@ const preview = {
6969

7070
const allFiles = await globPromise(`${data.inputDir.replace(/\\/g, '/')}/**/*`);
7171

72-
const filesArray = await Promise.all(
73-
(await Promise.all(
74-
allFiles.map(async file => {
75-
if ((await fs.promises.lstat(file)).isFile()) {
76-
return file
77-
}
72+
const filesArray = (await Promise.all(allFiles.map(async file => {
73+
if ((await fs.promises.lstat(file)).isFile()) {
74+
return new PutObjectCommand({
75+
Bucket: data.bucket,
76+
Key: data.outputDir + path.relative(data.inputDir, file).replace(/\\/g, '/'),
77+
ContentType: mime.lookup(file),
78+
Body: await fs.promises.readFile(file),
7879
})
79-
))
80-
.filter(file => file !== undefined)
81-
.map(async file => new PutObjectCommand({
82-
Bucket: data.bucket,
83-
Key: data.outputDir + path.relative(data.inputDir, file).replace(/\\/g, '/'),
84-
ContentType: mime.lookup(file),
85-
Body: await fs.promises.readFile(file),
86-
}))
87-
)
80+
}
81+
})))
82+
.filter(file => file !== undefined)
8883

8984
const progressBar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);
9085
progressBar.start(filesArray.length, 0);

0 commit comments

Comments
 (0)