-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.environment.js
More file actions
62 lines (52 loc) · 1.71 KB
/
Copy pathapp.environment.js
File metadata and controls
62 lines (52 loc) · 1.71 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import path from 'node:path';
import { config as loadDotEnv } from 'dotenv';
const supportedPlatforms = new Set(['electron', 'web', 'mobile']);
const supportedSvelteKitAdapters = new Set(['static', 'node']);
const envFiles = ['.env', '.env.local'];
for (const envFile of envFiles) {
loadDotEnv({
path: path.resolve(process.cwd(), envFile),
quiet: true,
override: envFile.endsWith('.local')
});
}
function resolveSupportedValue(name, value, supportedValues) {
if (supportedValues.has(value)) {
return value;
}
throw new Error(`Unsupported ${name}: ${value}`);
}
export function resolveAppPlatform() {
return resolveSupportedValue('app platform', process.env.PLATFORM ?? 'electron', supportedPlatforms);
}
export function resolveSvelteKitAdapter() {
return resolveSupportedValue(
'SvelteKit adapter',
process.env.SVELTEKIT_ADAPTER ?? 'static',
supportedSvelteKitAdapters
);
}
export function createPlatformPaths(
platform = resolveAppPlatform(),
svelteKitAdapter = resolveSvelteKitAdapter()
) {
return {
build: `.build/svelte/${svelteKitAdapter}`,
dist: `.build/dist/${platform}`,
release: `.build/release/${platform}`
};
}
export function resolveAppEnvironment() {
const platform = resolveAppPlatform();
const svelteKitAdapter = resolveSvelteKitAdapter();
if (platform !== 'web' && svelteKitAdapter === 'node') {
throw new Error(
`SvelteKit adapter "node" is currently only supported for PLATFORM=web, received PLATFORM=${platform}`
);
}
return {
platform,
svelteKitAdapter,
directories: createPlatformPaths(platform, svelteKitAdapter)
};
}