-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutils.config.mjs
More file actions
31 lines (22 loc) · 815 Bytes
/
utils.config.mjs
File metadata and controls
31 lines (22 loc) · 815 Bytes
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
import path, { resolve } from 'node:path'
import { readFile } from 'fs/promises'
import { fileURLToPath } from 'url'
import { dirname } from 'path'
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
export const rel = (...args) => resolve(__dirname, ...args)
export const mode = process.env.NODE_ENV || 'development'
export const target = process.env.TARGET || 'firefox'
export const isDev = mode !== 'production'
export const outDir = isDev ? 'dev' : 'dist'
export function outputDir (dir = '') {
return path.join(__dirname, outDir, dir)
}
export async function readJsonFile (path) {
const file = await readFile(path)
const object = JSON.parse(file)
return object
}
export function urlPath (path) {
return new URL(path, import.meta.url).pathname
}