Skip to content

Commit

Permalink
chore: format code
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jul 17, 2023
1 parent 92e94fb commit 5590480
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
8 changes: 4 additions & 4 deletions src/cert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface SSLCertOptions {
}

export async function generateSSLCert(
options: SSLCertOptions
options: SSLCertOptions,
): Promise<Certificate> {
// Certificate Attributes (https://git.io/fptna)
const attributes = [
Expand Down Expand Up @@ -75,7 +75,7 @@ export interface CAOptions {
}

export async function generateCA(
options: CAOptions = {}
options: CAOptions = {},
): Promise<Certificate> {
// Certificate Attributes: https://git.io/fptna
const attributes = [
Expand Down Expand Up @@ -117,7 +117,7 @@ export async function generateCert(options: CertOptions): Promise<Certificate> {
// Create serial from and integer between 50000 and 99999
const serial = Math.floor(Math.random() * 95_000 + 50_000).toString();
const generateKeyPair = promisify(
forge.pki.rsa.generateKeyPair.bind(forge.pki.rsa)
forge.pki.rsa.generateKeyPair.bind(forge.pki.rsa),
);
const keyPair = await generateKeyPair({ bits: 2048, workers: 4 });
const cert = forge.pki.createCertificate();
Expand All @@ -127,7 +127,7 @@ export async function generateCert(options: CertOptions): Promise<Certificate> {
cert.validity.notBefore = new Date();
cert.validity.notAfter = new Date();
cert.validity.notAfter.setDate(
cert.validity.notAfter.getDate() + options.validityDays
cert.validity.notAfter.getDate() + options.validityDays,
);
cert.setSubject(options.subject);
cert.setIssuer(options.issuer);
Expand Down
16 changes: 9 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export interface Listener {

export async function listen(
handle: RequestListener,
options_: Partial<ListenOptions> = {}
options_: Partial<ListenOptions> = {},
): Promise<Listener> {
options_ = defu(options_, {
port: process.env.PORT || 3000,
Expand Down Expand Up @@ -104,7 +104,7 @@ export async function listen(
if (options_.https) {
const { key, cert } = await resolveCert(
{ ...(options_.https as any) },
options_.hostname
options_.hostname,
);
https = { key, cert };
server = createHTTPSServer({ key, cert }, handle);
Expand Down Expand Up @@ -148,16 +148,18 @@ export async function listen(
const anyV6 = addr?.addr === "[::]";
if (anyV4 || anyV6) {
lines.push(
` > Local${name}: ${formatURL(getURL("localhost", baseURL))} ${add}`
` > Local${name}: ${formatURL(
getURL("localhost", baseURL),
)} ${add}`,
);
for (const addr of getNetworkInterfaces(anyV4)) {
lines.push(` > Network${name}: ${formatURL(getURL(addr, baseURL))}`);
}
} else {
lines.push(
` > Listening${name}: ${formatURL(
getURL(undefined, baseURL)
)} ${add}`
getURL(undefined, baseURL),
)} ${add}`,
);
}
// eslint-disable-next-line no-console
Expand Down Expand Up @@ -191,7 +193,7 @@ export async function listen(

async function resolveCert(
options: HTTPSOptions,
host?: string
host?: string,
): Promise<Certificate> {
// Use cert if provided
if (options.key && options.cert) {
Expand Down Expand Up @@ -244,6 +246,6 @@ function formatAddress(addr: { family: string | number; address: string }) {

function formatURL(url: string) {
return cyan(
underline(decodeURI(url).replace(/:(\d+)\//g, `:${bold("$1")}/`))
underline(decodeURI(url).replace(/:(\d+)\//g, `:${bold("$1")}/`)),
);
}
26 changes: 13 additions & 13 deletions src/lib/open/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const getWslDrivesMountPoint = (() => {
encoding: "utf8",
});
const configMountPoint = /(?<!#.*)root\s*=\s*(?<mountPoint>.*)/g.exec(
configContent
configContent,
);

if (!configMountPoint) {
Expand Down Expand Up @@ -96,7 +96,7 @@ const baseOpen = async (options) => {
baseOpen({
...options,
app: singleApp,
})
}),
);
}

Expand All @@ -112,7 +112,7 @@ const baseOpen = async (options) => {
name: appName,
arguments: appArguments,
},
})
}),
);
}

Expand Down Expand Up @@ -150,7 +150,7 @@ const baseOpen = async (options) => {
"-NonInteractive",
"–ExecutionPolicy",
"Bypass",
"-EncodedCommand"
"-EncodedCommand",
);

if (!isWsl()) {
Expand Down Expand Up @@ -182,7 +182,7 @@ const baseOpen = async (options) => {
// Using Base64-encoded command, accepted by PowerShell, to allow special characters.
options.target = Buffer.from(
encodedArguments.join(" "),
"utf16le"
"utf16le",
).toString("base64");
} else {
if (app) {
Expand All @@ -198,7 +198,7 @@ const baseOpen = async (options) => {
writeFileSync(
join(os.tmpdir(), "xdg-open"),
await import("./xdg-open").then((r) => r.xdgOpenScript()),
"utf8"
"utf8",
);
chmodSync(command, 0o755 /* rwx r-x r-x */);
} catch {
Expand Down Expand Up @@ -231,7 +231,7 @@ const baseOpen = async (options) => {
const subprocess = childProcess.spawn(
command,
cliArguments,
childProcessOptions
childProcessOptions,
);

if (options.wait) {
Expand Down Expand Up @@ -331,8 +331,8 @@ defineLazyProperty(apps, "chrome", () =>
"/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe",
],
},
}
)
},
),
);

defineLazyProperty(apps, "firefox", () =>
Expand All @@ -344,8 +344,8 @@ defineLazyProperty(apps, "firefox", () =>
},
{
wsl: "/mnt/c/Program Files/Mozilla Firefox/firefox.exe",
}
)
},
),
);

defineLazyProperty(apps, "edge", () =>
Expand All @@ -357,8 +357,8 @@ defineLazyProperty(apps, "edge", () =>
},
{
wsl: "/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe",
}
)
},
),
);

open.apps = apps;
Expand Down
4 changes: 2 additions & 2 deletions test/fixture/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ listen(
},
{
open: process.argv.some(
(argument) => argument === "-o" || argument === "--open"
(argument) => argument === "-o" || argument === "--open",
),
https: process.argv.includes("--https"),
}
},
);

0 comments on commit 5590480

Please sign in to comment.