-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
45 lines (42 loc) · 1.21 KB
/
index.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
36
37
38
39
40
41
42
43
44
45
import { readFile } from "node:fs/promises";
/**
* Joins path segments into a single path string.
*
* @param {...string} segments - The path segments to join.
* @returns {string} The joined path string.
*/
const join = (...segments) => {
return segments.join("/").replace(/[\/]+/g, "/");
};
/**
* Returns the configuration object for the eik-podlet-server-extension.
*
* @param {Object} options - The options object.
* @param {string} options.cwd - The current working directory.
* @param {boolean} options.development - Whether the server is running in development mode.
* @returns {Promise<Object>} The configuration object.
* @throws {Error} If the eik.json file cannot be read.
*/
export const config = async ({ cwd, development }) => {
try {
const eik = JSON.parse(
await readFile(join(cwd, "eik.json"), {
encoding: "utf8",
})
);
return {
assets: {
base: {
format: String,
default: development
? "/static"
: new URL(join("pkg", eik.name, eik.version), eik.server).href,
},
},
};
} catch (error) {
throw new Error(
"Could not read eik.json, Is there one present in the project root?"
);
}
};