Skip to content

Commit

Permalink
chore: fsm -> fs.promises
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushmanchhabra committed Jul 10, 2024
1 parent cbb596c commit 08d79bf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
40 changes: 20 additions & 20 deletions src/bld.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import child_process from "node:child_process";
import console from "node:console";
import fs from "node:fs";
import path from "node:path";
import fsm from "node:fs/promises";
import process from "node:process";

import compressing from "compressing";
Expand Down Expand Up @@ -129,15 +129,15 @@ async function bld({
}-${arch}`,
);

await fsm.rm(outDir, { force: true, recursive: true });
await fsm.cp(nwDir, outDir, { recursive: true, verbatimSymlinks: true });
await fs.promises.rm(outDir, { force: true, recursive: true });
await fs.promises.cp(nwDir, outDir, { recursive: true, verbatimSymlinks: true });

const files = await util.globFiles({ srcDir, glob });
const manifest = await util.getNodeManifest({ srcDir, glob });

if (glob) {
for (let file of files) {
await fsm.cp(
await fs.promises.cp(
file,
path.resolve(
outDir,
Expand All @@ -150,7 +150,7 @@ async function bld({
);
}
} else {
await fsm.cp(
await fs.promises.cp(
files,
path.resolve(
outDir,
Expand Down Expand Up @@ -208,15 +208,15 @@ const manageManifest = async ({ nwPkg, managedManifest, outDir, platform }) => {
}

if (typeof managedManifest === "string") {
manifest = JSON.parse(await fsm.readFile(managedManifest));
manifest = JSON.parse(await fs.promises.readFile(managedManifest));
}

if (manifest.devDependencies) {
manifest.devDependencies = undefined;
}
manifest.packageManager = manifest.packageManager ?? "npm@*";

await fsm.writeFile(
await fs.promises.writeFile(
path.resolve(
outDir,
platform !== "osx"
Expand Down Expand Up @@ -279,7 +279,7 @@ const setLinuxConfig = async ({ app, outDir }) => {
SingleMainWindow: app.singleMainWindow,
};

await fsm.rename(`${outDir}/nw`, `${outDir}/${app.name}`);
await fs.promises.rename(`${outDir}/nw`, `${outDir}/${app.name}`);

let fileContent = `[Desktop Entry]\n`;
Object.keys(desktopEntryFile).forEach((key) => {
Expand All @@ -288,7 +288,7 @@ const setLinuxConfig = async ({ app, outDir }) => {
}
});
let filePath = `${outDir}/${app.name}.desktop`;
await fsm.writeFile(filePath, fileContent);
await fs.promises.writeFile(filePath, fileContent);
};

const setWinConfig = async ({ app, outDir }) => {
Expand All @@ -314,13 +314,13 @@ const setWinConfig = async ({ app, outDir }) => {
});

const outDirAppExe = path.resolve(outDir, `${app.name}.exe`);
await fsm.rename(path.resolve(outDir, "nw.exe"), outDirAppExe);
const exe = peLibrary.NtExecutable.from(await fsm.readFile(outDirAppExe));
await fs.promises.rename(path.resolve(outDir, "nw.exe"), outDirAppExe);
const exe = peLibrary.NtExecutable.from(await fs.promises.readFile(outDirAppExe));
const res = peLibrary.NtExecutableResource.from(exe);
// English (United States)
const EN_US = 1033;
if (app.icon) {
const iconBuffer = await fsm.readFile(path.resolve(app.icon));
const iconBuffer = await fs.promises.readFile(path.resolve(app.icon));
const iconFile = resedit.Data.IconFile.from(iconBuffer);
resedit.Resource.IconGroupEntry.replaceIconsForResource(
res.entries,
Expand All @@ -340,7 +340,7 @@ const setWinConfig = async ({ app, outDir }) => {
vi.outputToResourceEntries(res.entries);
res.outputResource(exe);
const outBuffer = Buffer.from(exe.generate());
await fsm.writeFile(outDirAppExe, outBuffer);
await fs.promises.writeFile(outDirAppExe, outBuffer);
};

const setOsxConfig = async ({ outDir, app }) => {
Expand All @@ -352,16 +352,16 @@ const setOsxConfig = async ({ outDir, app }) => {

try {
const outApp = path.resolve(outDir, `${app.name}.app`);
await fsm.rename(path.resolve(outDir, "nwjs.app"), outApp);
await fs.promises.rename(path.resolve(outDir, "nwjs.app"), outApp);
if (app.icon !== undefined) {
await fsm.copyFile(
await fs.promises.copyFile(
path.resolve(app.icon),
path.resolve(outApp, "Contents", "Resources", "app.icns"),
);
}

const infoPlistPath = path.resolve(outApp, "Contents", "Info.plist");
const infoPlistJson = plist.parse(await fsm.readFile(infoPlistPath, "utf-8"));
const infoPlistJson = plist.parse(await fs.promises.readFile(infoPlistPath, "utf-8"));

const infoPlistStringsPath = path.resolve(
outApp,
Expand All @@ -370,7 +370,7 @@ const setOsxConfig = async ({ outDir, app }) => {
"en.lproj",
"InfoPlist.strings",
);
const infoPlistStringsData = await fsm.readFile(
const infoPlistStringsData = await fs.promises.readFile(
infoPlistStringsPath,
"utf-8",
);
Expand Down Expand Up @@ -398,8 +398,8 @@ const setOsxConfig = async ({ outDir, app }) => {
}
});

await fsm.writeFile(infoPlistPath, plist.build(infoPlistJson));
await fsm.writeFile(
await fs.promises.writeFile(infoPlistPath, plist.build(infoPlistJson));
await fs.promises.writeFile(
infoPlistStringsPath,
infoPlistStringsDataArray.toString().replace(/,/g, "\n"),
);
Expand Down Expand Up @@ -434,7 +434,7 @@ const compress = async ({
await compressing.tgz.compressDir(outDir, `${outDir}.tgz`);
}

await fsm.rm(outDir, { recursive: true, force: true });
await fs.promises.rm(outDir, { recursive: true, force: true });
};

export default bld;
5 changes: 2 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import console from "node:console";
import fs from "node:fs";
import fsm from "node:fs/promises";

import bld from "./bld.js";
import get from "./get/index.js";
Expand Down Expand Up @@ -59,13 +58,13 @@ async function nwbuild(options) {

built = fs.existsSync(options.cacheDir);
if (built === false) {
await fsm.mkdir(options.cacheDir, { recursive: true });
await fs.promises.mkdir(options.cacheDir, { recursive: true });
}

if (options.mode === "build") {
built = fs.existsSync(options.outDir);
if (built === false) {
await fsm.mkdir(options.outDir, { recursive: true });
await fs.promises.mkdir(options.outDir, { recursive: true });
}
}

Expand Down

0 comments on commit 08d79bf

Please sign in to comment.