Skip to content

Commit

Permalink
Merge pull request #192 from divriots/chore/sequential-compress-opt
Browse files Browse the repository at this point in the history
chore: seq compress option
  • Loading branch information
muryoh authored Sep 17, 2024
2 parents e25ffce + 3d2d65a commit 0118ec6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/compress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,19 @@ export async function compressFolder(
if (exclude) globs.push('!' + exclude);
const paths = await globby(globs, { cwd: state.dir, absolute: true });

// "Parallel" processing
await Promise.all(
paths.map(async (file) => {
if (!state.compressedFiles.has(file)) {
await processFile(state, file, await fs.stat(file));
spinner.text = getProgressText(state);
}
})
);
async function compressFile(file: string) {
if (!state.compressedFiles.has(file)) {
await processFile(state, file, await fs.stat(file));
spinner.text = getProgressText(state);
}
}

if (!state.options.misc.sequential_compress) {
// "Parallel" processing
await Promise.all(paths.map(compressFile));
} else {
for (const file of paths) await compressFile(file);
}

spinner.text = getProgressText(state);
spinner.succeed();
Expand Down
1 change: 1 addition & 0 deletions src/config-default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const default_options: Options = {
},
misc: {
prefetch_links: 'off',
sequential_compress: false,
},
};

Expand Down
1 change: 1 addition & 0 deletions src/config-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,6 @@ export type Options = {
};
misc: {
prefetch_links: 'in-viewport' | 'off';
sequential_compress: boolean;
};
};

0 comments on commit 0118ec6

Please sign in to comment.