Skip to content

Commit 7eb6af0

Browse files
committed
Modernize bootstrap package
1 parent f6e031d commit 7eb6af0

File tree

6 files changed

+572
-1207
lines changed

6 files changed

+572
-1207
lines changed

bootstrap/index.js renamed to bootstrap/index.ts

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,27 @@
1-
const { exec } = require("child_process");
2-
const fs = require("fs");
3-
const os = require("os");
4-
const service = require("os-service");
5-
const path = require("path");
6-
const sudo = require("sudo-prompt");
1+
import service from "@neuralegion/os-service";
2+
import { exec } from "child_process";
3+
import fs from "fs";
4+
import os from "os";
5+
import path from "path";
6+
import sudo from "sudo-prompt";
77

88
const isWindows = os.platform() === "win32";
99

1010
const sudoOptions = {
1111
name: "Aorus Laptop Fan Control",
1212
};
1313

14-
const errorHandler = (onSuccess) => (error) => {
15-
if (error) {
16-
throw error;
17-
}
18-
19-
onSuccess();
20-
};
21-
22-
function sudoOutputHandler(error, stdout) {
14+
const sudoOutputHandler: Parameters<(typeof sudo)["exec"]>[2] = (
15+
error,
16+
stdout,
17+
) => {
2318
if (error) {
2419
console.error(error);
2520
return;
2621
}
2722

2823
console.log(stdout);
29-
}
24+
};
3025

3126
switch (process.argv[2]) {
3227
case "install":
@@ -43,25 +38,30 @@ switch (process.argv[2]) {
4338
service.add(
4439
"alfc",
4540
{
46-
programArgs: ["run"],
41+
args: ["run"],
4742
dependencies: isWindows ? ["Winmgmt"] : ["acpi_call"],
4843
},
49-
errorHandler(() => {
44+
(error) => {
45+
if (error) {
46+
throw error;
47+
}
48+
5049
const serviceStartCommand = isWindows
5150
? "net start alfc"
5251
: "service alfc start";
53-
exec(
54-
serviceStartCommand,
55-
errorHandler(async () => {
56-
if (isWindows) {
57-
await new Promise((resolve) => setTimeout(resolve, 1000 * 25));
58-
}
52+
exec(serviceStartCommand, async (error) => {
53+
if (error) {
54+
throw error;
55+
}
56+
57+
if (isWindows) {
58+
await new Promise((resolve) => setTimeout(resolve, 1000 * 25));
59+
}
5960

60-
console.log("Done.");
61-
require("react-dev-utils/openBrowser")("http://localhost:5522");
62-
}),
63-
);
64-
}),
61+
console.log("Done.");
62+
require("react-dev-utils/openBrowser")("http://localhost:5522");
63+
});
64+
},
6565
);
6666
break;
6767
case "uninstall":
@@ -82,12 +82,13 @@ switch (process.argv[2]) {
8282
// exec would possibly error if the service is already stopped.
8383
// But we don't care about that and will simply attempt to remove the serivce.
8484

85-
service.remove(
86-
"alfc",
87-
errorHandler(() => {
88-
console.log("Done.");
89-
}),
90-
);
85+
service.remove("alfc", (error) => {
86+
if (error) {
87+
throw error;
88+
}
89+
90+
console.log("Done.");
91+
});
9192
});
9293
break;
9394
}
@@ -100,6 +101,7 @@ switch (process.argv[2]) {
100101
// On Linux, it'll go to the systemd logs.
101102
if (isWindows) {
102103
const access = fs.createWriteStream(path.join(__dirname, "service.log"));
104+
// @ts-expect-error Undefined/null type mismatch: Type 'Error | null | undefined' is not assignable to type 'Error | undefined'.
103105
process.stdout.write = process.stderr.write = access.write.bind(access);
104106
process.on("uncaughtException", function (err) {
105107
console.error(err && err.stack ? err.stack : err);

bootstrap/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"name": "service",
33
"version": "1.0.0",
4-
"main": "index.js",
4+
"main": "index.ts",
55
"license": "MIT",
66
"scripts": {
7-
"build": "rimraf dist && ncc build index.js"
7+
"build": "rimraf dist && ncc build index.ts"
88
},
99
"dependencies": {
10-
"os-service": "2.2.0",
11-
"react-dev-utils": "10.2.1",
10+
"@neuralegion/os-service": "^1.2.6",
11+
"react-dev-utils": "12.0.1",
1212
"sudo-prompt": "9.2.1"
1313
},
1414
"devDependencies": {
15-
"@vercel/ncc": "0.38.1",
16-
"rimraf": "3.0.2"
15+
"@vercel/ncc": "0.38.3",
16+
"rimraf": "6.0.1"
1717
}
1818
}

0 commit comments

Comments
 (0)