refactor: follow suggesion to make methods read a bit more sync

This commit is contained in:
Waldemar Reusch 2023-01-26 22:00:31 +01:00
parent 1a0e05d073
commit ae3bfb28ed

View File

@ -1,11 +1,17 @@
import { getProjectRoot } from "./getProjectRoot";
import { join as pathJoin } from "path";
import { chmodSync, statSync, constants } from "fs";
import { constants } from "fs";
import { chmod, stat } from "fs/promises";
import(pathJoin(getProjectRoot(), "package.json")).then(({ bin }) => {
Object.entries<string>(bin).forEach(([, scriptPath]) => {
async () => {
var { bin } = await import(pathJoin(getProjectRoot(), "package.json"));
var promises = Object.values<string>(bin).map(async scriptPath => {
const fullPath = pathJoin(getProjectRoot(), scriptPath);
const newMode = statSync(fullPath).mode | constants.S_IXUSR | constants.S_IXGRP | constants.S_IXOTH;
chmodSync(fullPath, newMode);
const oldMode = (await stat(fullPath)).mode;
const newMode = oldMode | constants.S_IXUSR | constants.S_IXGRP | constants.S_IXOTH;
await chmod(fullPath, newMode);
});
});
await Promise.all(promises);
};