@involvex/magic-pwa-core 0.1.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/schema.test.ts +24 -0
- package/src/schema.ts +136 -128
package/package.json
CHANGED
package/src/schema.test.ts
CHANGED
|
@@ -15,6 +15,30 @@ describe("schema", () => {
|
|
|
15
15
|
expect(config.targets.electron).toBe(true);
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
+
test("android.staticServer defaults to false", () => {
|
|
19
|
+
const config = createDefaultConfig({
|
|
20
|
+
name: "Demo",
|
|
21
|
+
slug: "demo",
|
|
22
|
+
appId: "com.example.demo",
|
|
23
|
+
template: "basic",
|
|
24
|
+
});
|
|
25
|
+
expect(config.android.staticServer).toBe(false);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("vue and svelte templates parse with basic-style defaults", () => {
|
|
29
|
+
for (const template of ["vue", "svelte"] as const) {
|
|
30
|
+
const config = createDefaultConfig({
|
|
31
|
+
name: "Demo",
|
|
32
|
+
slug: "demo",
|
|
33
|
+
appId: "com.example.demo",
|
|
34
|
+
template,
|
|
35
|
+
});
|
|
36
|
+
expect(MagicPwaConfigSchema.parse(config).template).toBe(template);
|
|
37
|
+
expect(config.pwa.themeColor).toBe("#0f172a");
|
|
38
|
+
expect(config.android.enableHaptics).toBe(true);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
18
42
|
test("defineConfig rejects bad slug", () => {
|
|
19
43
|
expect(() =>
|
|
20
44
|
MagicPwaConfigSchema.parse({
|
package/src/schema.ts
CHANGED
|
@@ -1,128 +1,136 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
|
|
3
|
-
export const PwaTemplateSchema = z.enum(["basic", "blank"]);
|
|
4
|
-
export type PwaTemplate = z.infer<typeof PwaTemplateSchema>;
|
|
5
|
-
|
|
6
|
-
export const BuildTargetSchema = z.enum(["web", "electron", "chrome", "android"]);
|
|
7
|
-
export type BuildTarget = z.infer<typeof BuildTargetSchema>;
|
|
8
|
-
|
|
9
|
-
export const ExpoLoadModeSchema = z.enum(["bundle", "url"]);
|
|
10
|
-
export type ExpoLoadMode = z.infer<typeof ExpoLoadModeSchema>;
|
|
11
|
-
|
|
12
|
-
export const MagicPwaConfigSchema = z.object({
|
|
13
|
-
name: z.string().min(1),
|
|
14
|
-
slug: z
|
|
15
|
-
.string()
|
|
16
|
-
.min(1)
|
|
17
|
-
.regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "slug must be kebab-case"),
|
|
18
|
-
appId: z
|
|
19
|
-
.string()
|
|
20
|
-
.min(1)
|
|
21
|
-
.regex(/^[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*)+$/i, "appId must be reverse-domain"),
|
|
22
|
-
description: z.string().min(1),
|
|
23
|
-
author: z.string().min(1),
|
|
24
|
-
version: z.string().min(1),
|
|
25
|
-
template: PwaTemplateSchema,
|
|
26
|
-
targets: z.object({
|
|
27
|
-
web: z.boolean(),
|
|
28
|
-
electron: z.boolean(),
|
|
29
|
-
chrome: z.boolean(),
|
|
30
|
-
android: z.boolean(),
|
|
31
|
-
}),
|
|
32
|
-
pwa: z.object({
|
|
33
|
-
startUrl: z.string().min(1),
|
|
34
|
-
display: z.enum(["standalone", "minimal-ui", "fullscreen"]),
|
|
35
|
-
themeColor: z.string().min(1),
|
|
36
|
-
backgroundColor: z.string().min(1),
|
|
37
|
-
outDir: z.string().min(1),
|
|
38
|
-
}),
|
|
39
|
-
electron: z.object({
|
|
40
|
-
outDir: z.string().min(1),
|
|
41
|
-
windowTitle: z.string().min(1),
|
|
42
|
-
width: z.number().int().positive(),
|
|
43
|
-
height: z.number().int().positive(),
|
|
44
|
-
minWidth: z.number().int().positive().optional(),
|
|
45
|
-
minHeight: z.number().int().positive().optional(),
|
|
46
|
-
loadUrl: z.string().url().optional(),
|
|
47
|
-
}),
|
|
48
|
-
chrome: z.object({
|
|
49
|
-
outDir: z.string().min(1),
|
|
50
|
-
manifestVersion: z.literal(3),
|
|
51
|
-
permissions: z.array(z.string()).max(64),
|
|
52
|
-
hostPermissions: z.array(z.string()).max(64),
|
|
53
|
-
}),
|
|
54
|
-
android: z.object({
|
|
55
|
-
outDir: z.string().min(1),
|
|
56
|
-
packageName: z.string().min(1),
|
|
57
|
-
mode: ExpoLoadModeSchema,
|
|
58
|
-
url: z.string().url().optional(),
|
|
59
|
-
statusBarStyle: z.enum(["auto", "light", "dark"]),
|
|
60
|
-
enableHaptics: z.boolean(),
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
export const PwaTemplateSchema = z.enum(["basic", "blank", "vue", "svelte"]);
|
|
4
|
+
export type PwaTemplate = z.infer<typeof PwaTemplateSchema>;
|
|
5
|
+
|
|
6
|
+
export const BuildTargetSchema = z.enum(["web", "electron", "chrome", "android"]);
|
|
7
|
+
export type BuildTarget = z.infer<typeof BuildTargetSchema>;
|
|
8
|
+
|
|
9
|
+
export const ExpoLoadModeSchema = z.enum(["bundle", "url"]);
|
|
10
|
+
export type ExpoLoadMode = z.infer<typeof ExpoLoadModeSchema>;
|
|
11
|
+
|
|
12
|
+
export const MagicPwaConfigSchema = z.object({
|
|
13
|
+
name: z.string().min(1),
|
|
14
|
+
slug: z
|
|
15
|
+
.string()
|
|
16
|
+
.min(1)
|
|
17
|
+
.regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "slug must be kebab-case"),
|
|
18
|
+
appId: z
|
|
19
|
+
.string()
|
|
20
|
+
.min(1)
|
|
21
|
+
.regex(/^[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*)+$/i, "appId must be reverse-domain"),
|
|
22
|
+
description: z.string().min(1),
|
|
23
|
+
author: z.string().min(1),
|
|
24
|
+
version: z.string().min(1),
|
|
25
|
+
template: PwaTemplateSchema,
|
|
26
|
+
targets: z.object({
|
|
27
|
+
web: z.boolean(),
|
|
28
|
+
electron: z.boolean(),
|
|
29
|
+
chrome: z.boolean(),
|
|
30
|
+
android: z.boolean(),
|
|
31
|
+
}),
|
|
32
|
+
pwa: z.object({
|
|
33
|
+
startUrl: z.string().min(1),
|
|
34
|
+
display: z.enum(["standalone", "minimal-ui", "fullscreen"]),
|
|
35
|
+
themeColor: z.string().min(1),
|
|
36
|
+
backgroundColor: z.string().min(1),
|
|
37
|
+
outDir: z.string().min(1),
|
|
38
|
+
}),
|
|
39
|
+
electron: z.object({
|
|
40
|
+
outDir: z.string().min(1),
|
|
41
|
+
windowTitle: z.string().min(1),
|
|
42
|
+
width: z.number().int().positive(),
|
|
43
|
+
height: z.number().int().positive(),
|
|
44
|
+
minWidth: z.number().int().positive().optional(),
|
|
45
|
+
minHeight: z.number().int().positive().optional(),
|
|
46
|
+
loadUrl: z.string().url().optional(),
|
|
47
|
+
}),
|
|
48
|
+
chrome: z.object({
|
|
49
|
+
outDir: z.string().min(1),
|
|
50
|
+
manifestVersion: z.literal(3),
|
|
51
|
+
permissions: z.array(z.string()).max(64),
|
|
52
|
+
hostPermissions: z.array(z.string()).max(64),
|
|
53
|
+
}),
|
|
54
|
+
android: z.object({
|
|
55
|
+
outDir: z.string().min(1),
|
|
56
|
+
packageName: z.string().min(1),
|
|
57
|
+
mode: ExpoLoadModeSchema,
|
|
58
|
+
url: z.string().url().optional(),
|
|
59
|
+
statusBarStyle: z.enum(["auto", "light", "dark"]),
|
|
60
|
+
enableHaptics: z.boolean(),
|
|
61
|
+
/**
|
|
62
|
+
* Bundle mode only. When true, Expo shell starts a loopback HTTP server
|
|
63
|
+
* (SPA-friendly) via `@dr.pogodin/react-native-static-server`.
|
|
64
|
+
* Native Android builds of that package are not supported on Windows hosts —
|
|
65
|
+
* keep false there and fall back to `file:///android_asset/web-dist`.
|
|
66
|
+
*/
|
|
67
|
+
staticServer: z.boolean().default(false),
|
|
68
|
+
}),
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
export type MagicPwaConfig = z.infer<typeof MagicPwaConfigSchema>;
|
|
72
|
+
|
|
73
|
+
export function defineConfig(config: MagicPwaConfig): MagicPwaConfig {
|
|
74
|
+
return MagicPwaConfigSchema.parse(config);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function createDefaultConfig(overrides: {
|
|
78
|
+
name: string;
|
|
79
|
+
slug: string;
|
|
80
|
+
appId: string;
|
|
81
|
+
template: PwaTemplate;
|
|
82
|
+
description?: string;
|
|
83
|
+
author?: string;
|
|
84
|
+
targets?: Partial<MagicPwaConfig["targets"]>;
|
|
85
|
+
}): MagicPwaConfig {
|
|
86
|
+
const targets = {
|
|
87
|
+
web: true,
|
|
88
|
+
electron: true,
|
|
89
|
+
chrome: true,
|
|
90
|
+
android: true,
|
|
91
|
+
...overrides.targets,
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const isBlank = overrides.template === "blank";
|
|
95
|
+
|
|
96
|
+
return defineConfig({
|
|
97
|
+
name: overrides.name,
|
|
98
|
+
slug: overrides.slug,
|
|
99
|
+
appId: overrides.appId,
|
|
100
|
+
description: overrides.description ?? `${overrides.name} — multi-target PWA`,
|
|
101
|
+
author: overrides.author ?? "Unknown",
|
|
102
|
+
version: "0.1.0",
|
|
103
|
+
template: overrides.template,
|
|
104
|
+
targets,
|
|
105
|
+
pwa: {
|
|
106
|
+
startUrl: "/",
|
|
107
|
+
display: "standalone",
|
|
108
|
+
themeColor: isBlank ? "#ffffff" : "#0f172a",
|
|
109
|
+
backgroundColor: isBlank ? "#ffffff" : "#0f172a",
|
|
110
|
+
outDir: "dist/web",
|
|
111
|
+
},
|
|
112
|
+
electron: {
|
|
113
|
+
outDir: "dist/electron",
|
|
114
|
+
windowTitle: overrides.name,
|
|
115
|
+
width: 1200,
|
|
116
|
+
height: 800,
|
|
117
|
+
minWidth: 800,
|
|
118
|
+
minHeight: 600,
|
|
119
|
+
},
|
|
120
|
+
chrome: {
|
|
121
|
+
outDir: "dist/chrome",
|
|
122
|
+
manifestVersion: 3,
|
|
123
|
+
permissions: isBlank ? [] : ["storage", "sidePanel"],
|
|
124
|
+
hostPermissions: [],
|
|
125
|
+
},
|
|
126
|
+
android: {
|
|
127
|
+
outDir: "dist/android",
|
|
128
|
+
packageName: overrides.appId,
|
|
129
|
+
mode: "url",
|
|
130
|
+
url: "http://localhost:5173",
|
|
131
|
+
statusBarStyle: "auto",
|
|
132
|
+
enableHaptics: !isBlank,
|
|
133
|
+
staticServer: false,
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
}
|