|
1 | | -import * as fs from 'node:fs' |
| 1 | +import * as fs from "node:fs"; |
2 | 2 |
|
3 | 3 | export function fileExists(filename: string): boolean { |
4 | | - return fs.existsSync(filename) |
| 4 | + return fs.existsSync(filename); |
5 | 5 | } |
6 | 6 |
|
7 | | -export function readFile(filename: string, encoding: BufferEncoding = 'utf-8'): string { |
| 7 | +export function readFile( |
| 8 | + filename: string, |
| 9 | + encoding: BufferEncoding = "utf-8", |
| 10 | +): string { |
8 | 11 | try { |
9 | | - return fs.readFileSync(filename, encoding) |
| 12 | + return fs.readFileSync(filename, encoding); |
10 | 13 | } catch (error) { |
11 | | - if (isFsError(error) && error.code === 'ENOENT') { |
12 | | - console.error(`Not found: "${filename}"`) |
13 | | - process.exit(1) |
| 14 | + if (isFsError(error) && error.code === "ENOENT") { |
| 15 | + console.error(`Not found: "${filename}"`); |
| 16 | + process.exit(1); |
14 | 17 | } else { |
15 | | - throw error |
| 18 | + throw error; |
16 | 19 | } |
17 | 20 | } |
18 | 21 | } |
19 | 22 |
|
20 | 23 | function isFsError(error: unknown): error is { code: string } { |
21 | 24 | return ( |
22 | | - typeof error === 'object' && error != null && 'code' in error && typeof error.code === 'string' |
23 | | - ) |
| 25 | + typeof error === "object" && |
| 26 | + error != null && |
| 27 | + "code" in error && |
| 28 | + typeof error.code === "string" |
| 29 | + ); |
24 | 30 | } |
25 | 31 |
|
26 | 32 | export function writeFile(filename: string, data: string): void { |
27 | | - fs.writeFileSync(filename, data) |
| 33 | + fs.writeFileSync(filename, data); |
28 | 34 | } |
29 | 35 |
|
30 | 36 | export function readJson(filename: string): any { |
31 | | - return JSON.parse(readFile(filename)) |
| 37 | + return JSON.parse(readFile(filename)); |
32 | 38 | } |
33 | 39 |
|
34 | 40 | export function writeJson(filename: string, data: any): void { |
35 | | - writeFile(filename, JSON.stringify(data, null, 2) + '\n') |
| 41 | + writeFile(filename, JSON.stringify(data, null, 2) + "\n"); |
36 | 42 | } |
0 commit comments