Read-only mirror — the public repositories of the Forgejo instance, refreshed every 10 minutes. The live instance (fg.dieschoenewolke.de) is reachable only over the VPN; clone here with https://git.dieschoenewolke.de/git/<owner>/<repo>.git.
summaryrefslogtreecommitdiff
path: root/src/fs-helper.ts
diff options
context:
space:
mode:
authoreric sciple <ericsciple@users.noreply.github.com>2019-12-03 10:28:59 -0500
committerGitHub <noreply@github.com>2019-12-03 10:28:59 -0500
commite404ba5989baa550f631fb1262539d1375a856b7 (patch)
tree4cc911589e7c9a4c976bc99eb4dcb886d2b2d8a8 /src/fs-helper.ts
parent6a11491f2eea6739d1296d604c5402cffa43a1f1 (diff)
Convert checkout to a regular action (#70)
Diffstat (limited to 'src/fs-helper.ts')
-rw-r--r--src/fs-helper.ts77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/fs-helper.ts b/src/fs-helper.ts
new file mode 100644
index 0000000..c443404
--- /dev/null
+++ b/src/fs-helper.ts
@@ -0,0 +1,77 @@
+import * as fs from 'fs'
+
+export function directoryExistsSync(path: string, required?: boolean): boolean {
+ if (!path) {
+ throw new Error("Arg 'path' must not be empty")
+ }
+
+ let stats: fs.Stats
+ try {
+ stats = fs.statSync(path)
+ } catch (error) {
+ if (error.code === 'ENOENT') {
+ if (!required) {
+ return false
+ }
+
+ throw new Error(`Directory '${path}' does not exist`)
+ }
+
+ throw new Error(
+ `Encountered an error when checking whether path '${path}' exists: ${error.message}`
+ )
+ }
+
+ if (stats.isDirectory()) {
+ return true
+ } else if (!required) {
+ return false
+ }
+
+ throw new Error(`Directory '${path}' does not exist`)
+}
+
+export function existsSync(path: string): boolean {
+ if (!path) {
+ throw new Error("Arg 'path' must not be empty")
+ }
+
+ try {
+ fs.statSync(path)
+ } catch (error) {
+ if (error.code === 'ENOENT') {
+ return false
+ }
+
+ throw new Error(
+ `Encountered an error when checking whether path '${path}' exists: ${error.message}`
+ )
+ }
+
+ return true
+}
+
+export function fileExistsSync(path: string): boolean {
+ if (!path) {
+ throw new Error("Arg 'path' must not be empty")
+ }
+
+ let stats: fs.Stats
+ try {
+ stats = fs.statSync(path)
+ } catch (error) {
+ if (error.code === 'ENOENT') {
+ return false
+ }
+
+ throw new Error(
+ `Encountered an error when checking whether path '${path}' exists: ${error.message}`
+ )
+ }
+
+ if (!stats.isDirectory()) {
+ return true
+ }
+
+ return false
+}