« get me outta code hell

let gen-thumbs be run directly - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2022-02-27 11:14:54 -0400
committer(quasar) nebula <qznebula@protonmail.com>2022-02-27 11:14:54 -0400
commit7ffc79f9c891becdcf778ab6e5faf4c8ca3b14da (patch)
treec20e14d8de7802a5fe0e6b45be15a250f0c7495b /src/util
parent1d5078c972c8b2f625aa341cf75cead82323f909 (diff)
let gen-thumbs be run directly
Diffstat (limited to 'src/util')
-rw-r--r--src/util/node-utils.js10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/util/node-utils.js b/src/util/node-utils.js
index d660612e..a46d6141 100644
--- a/src/util/node-utils.js
+++ b/src/util/node-utils.js
@@ -1,5 +1,7 @@
 // Utility functions which are only relevant to particular Node.js constructs.
 
+import { fileURLToPath } from 'url';
+
 // Very cool function origin8ting in... http-music pro8a8ly!
 // Sorry if we happen to 8e violating past-us's copyright, lmao.
 export function promisifyProcess(proc, showLogging = true) {
@@ -25,3 +27,11 @@ export function promisifyProcess(proc, showLogging = true) {
         })
     })
 }
+
+// Handy-dandy utility function for detecting whether the passed URL is the
+// running JavaScript file. This takes `import.meta.url` from ES6 modules, which
+// is great 'cuz (module === require.main) doesn't work without CommonJS
+// modules.
+export function isMain(importMetaURL) {
+    return (process.argv[1] === fileURLToPath(importMetaURL));
+}