-
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.
Path checks and version update. (#189)
This PR adds checking before starting a `StaticServer` and prepares for a new release.
- Loading branch information
Showing
12 changed files
with
147 additions
and
27 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
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@this/fs-util | ||
============= | ||
|
||
Filesystem utility classes. | ||
|
||
- - - - - - - - - - | ||
``` | ||
Copyright 2022-2023 the Lactoserv Authors (Dan Bornstein et alia). | ||
SPDX-License-Identifier: Apache-2.0 | ||
``` |
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,83 @@ | ||
// Copyright 2022-2023 the Lactoserv Authors (Dan Bornstein et alia). | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import * as fs from 'node:fs/promises'; | ||
|
||
import { MustBe } from '@this/typey'; | ||
|
||
|
||
/** | ||
* General filesystem utility class. | ||
*/ | ||
export class FsUtil { | ||
/** | ||
* Checks to see if the given path exists in the filesystem, and is a | ||
* directory (not a regular or special file). | ||
* | ||
* @param {string} path Path to check. | ||
* @returns {boolean} The answer. | ||
*/ | ||
static async directoryExists(path) { | ||
const stats = await this.#statOrNull(path); | ||
|
||
return stats && stats.isDirectory(); | ||
} | ||
|
||
/** | ||
* Checks to see if the given path exists in the filesystem, and is a regular | ||
* file (not a directory or special file). | ||
* | ||
* @param {string} path Path to check. | ||
* @returns {boolean} The answer. | ||
*/ | ||
static async fileExists(path) { | ||
const stats = await this.#statOrNull(path); | ||
|
||
return stats && stats.isFile(); | ||
} | ||
|
||
/** | ||
* Checks to see if the given path exists in the filesystem. | ||
* | ||
* @param {string} path Path to check. | ||
* @returns {boolean} The answer. | ||
*/ | ||
static async pathExists(path) { | ||
const stats = await this.#statOrNull(path); | ||
|
||
return (stats !== null); | ||
} | ||
|
||
/** | ||
* Checks to see if the given path exists in the filesystem, and is a socket. | ||
* | ||
* @param {string} path Path to check. | ||
* @returns {boolean} The answer. | ||
*/ | ||
static async socketExists(path) { | ||
const stats = await this.#statOrNull(path); | ||
|
||
return stats && stats.isSocket(); | ||
} | ||
|
||
/** | ||
* Gets the `fs.Stats` of the path if it exists, or returns `null` if the | ||
* path does not exist in the filesystem. | ||
* | ||
* @param {string} path Path to check. | ||
* @returns {?fs.Stats} The stats, if the path exists, or `null` if not. | ||
*/ | ||
static async #statOrNull(path) { | ||
MustBe.string(path); | ||
|
||
try { | ||
return await fs.stat(path); | ||
} catch (e) { | ||
if (e.code === 'ENOENT') { | ||
// Not found. Not a real error in this case. | ||
return null; | ||
} | ||
throw e; | ||
} | ||
} | ||
} |
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,4 @@ | ||
// Copyright 2022-2023 the Lactoserv Authors (Dan Bornstein et alia). | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export * from '#x/FsUtil'; |
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,17 @@ | ||
{ | ||
"name": "@this/fs-util", | ||
"version": "0.0.1", | ||
"type": "module", | ||
"private": true, | ||
"license": "Apache-2.0", | ||
|
||
"exports": "./index.js", | ||
"imports": { | ||
"#x/*": "./export/*.js", | ||
"#p/*": "./private/*.js" | ||
}, | ||
|
||
"dependencies": { | ||
"@this/typey": "*" | ||
} | ||
} |
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