generated from cawa-93/vite-electron-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test read hosts file from main script, implement safe api
- Loading branch information
Showing
7 changed files
with
76 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,6 @@ | |
|
||
`npm run watch` | ||
|
||
`npm run typecheck` | ||
`npm run typecheck` | ||
|
||
`npm run lint` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { accessSync, constants, readFile } from 'fs'; | ||
|
||
//const hostsFilePath = '/etc/hosts'; | ||
//const hostsDelimiterStart = '# ----- HostsFileEdit config - Do not delete -----'; | ||
//const hostsDelimiterEnd = '# ----- HostsFileEdit config - End -----'; | ||
//const regex = /(?:# ----- HostsFileEdit config - Do not delete -----\n)([\s\S]*)(?:# ----- HostsFileEdit config - End -----\n?)/g; | ||
const hostsFilePaths: Record<string, string> = { | ||
'linux': '/etc/hosts', | ||
'darwin': '/etc/hosts', | ||
'win32': 'C:\\Windows\\System32\\drivers\\etc\\hosts', // TODO: What if Windows is not on C:? | ||
// Might be able to support others? https://nodejs.org/api/process.html#process_process_platform | ||
}; | ||
|
||
export const readHostsFile = function(): Promise<string> { | ||
return new Promise((resolve, reject) => { | ||
const path = hostsFilePaths[process.platform]; | ||
if (!path) { | ||
reject(`Platform ${process.platform} not supported`); | ||
} else { | ||
try { | ||
accessSync(path, constants.R_OK); | ||
} catch (error) { | ||
reject(`Tried to read file ${path} but file is not readable`); | ||
} | ||
|
||
readFile(path, 'utf-8', (err, data) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(data); | ||
} | ||
}); | ||
} | ||
|
||
// try { | ||
// accessSync(path, constants.R_OK); | ||
// } catch (error) { | ||
// throw `Tried to read file ${path} but file is not readable`; | ||
// } | ||
|
||
// const content = readFileSync(path); | ||
|
||
// return content; | ||
|
||
|
||
|
||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.