Skip to content

Commit d1b5a8a

Browse files
committed
Clean up lint errors in .vscode file for test automation
1 parent 375a5b4 commit d1b5a8a

1 file changed

Lines changed: 65 additions & 54 deletions

File tree

‎.vscode/dev-server-cli.mjs‎

Lines changed: 65 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,112 @@
11
#!/usr/bin/env node
2-
import { accessSync, readFileSync, unlinkSync, writeFileSync } from "fs";
3-
import spawn from "cross-spawn";
4-
import tempDir from "temp-dir"; // /tmp
5-
import yargs from "yargs/yargs";
6-
import { hideBin } from "yargs/helpers";
2+
/* eslint-env node */
3+
/* global console, process */
4+
import { accessSync, readFileSync, unlinkSync, writeFileSync } from 'fs'
5+
import spawn from 'cross-spawn'
6+
import tempDir from 'temp-dir' // /tmp
7+
import yargs from 'yargs/yargs'
8+
import { hideBin } from 'yargs/helpers'
79

8-
const pidFile = `${tempDir}/debug-server-hmDAr917.pid`;
9-
const port = 3000;
10+
const pidFile = `${tempDir}/debug-server-hmDAr917.pid`
11+
const port = 3000
1012

13+
/**
14+
* Ensure we do not start a duplicate dev server instance
15+
*/
1116
const failOnPidFileExists = () => {
1217
try {
13-
accessSync(pidFile);
14-
} catch (err) {
15-
return false;
18+
accessSync(pidFile)
19+
} catch {
20+
return false
1621
}
1722
console.error(
1823
`[error] Server appears to be running, found PID file ${pidFile}`,
19-
);
20-
return process.exit(116);
21-
};
24+
)
25+
return process.exit(116)
26+
}
2227

23-
const writePidFile = (pid) => {
28+
/**
29+
* Persist the child process PID to allow stop command to find it later
30+
*/
31+
const writePidFile = pid => {
2432
try {
25-
writeFileSync(pidFile, pid.toString(10), { flag: "ax" });
33+
writeFileSync(pidFile, pid.toString(10), { flag: 'ax' })
2634
} catch (err) {
27-
console.error(`[error] Failed to write PID ${pid} PID file ${pidFile}: ${err.message}`);
28-
return process.exit(11);
35+
console.error(`[error] Failed to write PID ${pid} PID file ${pidFile}: ${err.message}`)
36+
return process.exit(11)
2937
}
3038
}
3139

40+
/**
41+
* Remove the PID file when the dev server stops
42+
*/
3243
const unlinkPidFile = () => {
3344
try {
34-
unlinkSync(pidFile);
45+
unlinkSync(pidFile)
3546
} catch (err) {
3647
console.error(
3748
`[error] Failed to delete PID file ${pidFile}: ${err.message}`,
38-
);
39-
return process.exit(11);
49+
)
50+
return process.exit(11)
4051
}
41-
};
52+
}
4253

4354
yargs(hideBin(process.argv))
4455
.command(
45-
"start",
46-
"Start the server",
56+
'start',
57+
'Start the server',
4758
{},
4859
() => {
49-
failOnPidFileExists();
60+
failOnPidFileExists()
5061

51-
const child = spawn(`${process.cwd()}/node_modules/.bin/vercel`, ["dev", "--listen", port], {
62+
const child = spawn(`${process.cwd()}/node_modules/.bin/vercel`, ['dev', '--listen', port], {
5263
detached: true,
53-
stdio: "pipe",
54-
});
64+
stdio: 'pipe',
65+
})
5566

56-
let isPidWritten = false;
67+
let isPidWritten = false
5768

58-
child.on("error", (err) => {
59-
console.log(err);
60-
});
69+
child.on('error', error => {
70+
console.error(error)
71+
})
6172

6273
/** Forward child stdout to VS Code Task */
63-
child.stdout.setEncoding("utf8");
64-
child.stdout.on("data", (data) => {
74+
child.stdout.setEncoding('utf8')
75+
child.stdout.on('data', data => {
6576
if (!isPidWritten) {
66-
writePidFile(child.pid);
67-
isPidWritten = true;
77+
writePidFile(child.pid)
78+
isPidWritten = true
6879
}
69-
console.log(data);
70-
});
80+
console.log(data)
81+
})
7182

72-
child.stderr.setEncoding("utf8");
73-
child.stderr.on("data", (error) => {
74-
console.error(error);
75-
});
83+
child.stderr.setEncoding('utf8')
84+
child.stderr.on('data', error => {
85+
console.error(error)
86+
})
7687

77-
child.on("close", (code) => {
78-
child.unref();
79-
return process.exit(code);
80-
});
88+
child.on('close', code => {
89+
child.unref()
90+
return process.exit(code)
91+
})
8192
},
8293
)
8394
.command(
84-
"stop",
85-
"Stop the server",
95+
'stop',
96+
'Stop the server',
8697
{},
8798
() => {
8899
try {
89-
const pid = readFileSync(pidFile, { encoding: "utf8", flag: "r" });
90-
process.kill(parseInt(pid, 10), "SIGINT");
91-
unlinkPidFile();
92-
return process.exit(0);
100+
const pid = readFileSync(pidFile, { encoding: 'utf8', flag: 'r' })
101+
process.kill(parseInt(pid, 10), 'SIGINT')
102+
unlinkPidFile()
103+
return process.exit(0)
93104
} catch (err) {
94105
console.error(
95106
`[error] Failed to shut down server, reading PID file ${pidFile}: ${err.message}`,
96-
);
97-
return process.exit(11);
107+
)
108+
return process.exit(11)
98109
}
99110
},
100111
)
101-
.parse();
112+
.parse()

0 commit comments

Comments
 (0)