-
Notifications
You must be signed in to change notification settings - Fork 66
/
gallery.js
executable file
·35 lines (29 loc) · 942 Bytes
/
gallery.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env node
import { readFile } from 'fs/promises'
import path from 'path'
import url from 'url'
const readBuildInfo = async () => {
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
const buildFile = path.resolve(__dirname, '.build.json')
return readFile(buildFile, 'utf8').then(data => JSON.parse(data))
}
const run = async () => {
const { Logger } = await import('@home-gallery/logger')
Logger() // Initiate root logger
const { cli } = await import('@home-gallery/cli')
const buildInfo = await readBuildInfo().catch(() => ({}))
return cli(buildInfo)
}
const isMain = () => {
if (process.argv.length < 2) {
return false
}
const script = process.argv[1]
const normalizedScript = script.endsWith('.js') ? script : script + '.js'
const scriptUrl = url.pathToFileURL(normalizedScript)
return import.meta.url.endsWith(scriptUrl.href)
}
if (isMain()) {
run()
}
export default run;