@involvex/magic-pwa-core 0.1.0 → 0.1.2
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 +2 -2
- package/src/index.ts +5 -3
- package/src/schema.test.ts +1 -0
- package/src/schema.ts +128 -122
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@involvex/magic-pwa-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Shared config schema and helpers for Magic-PWA",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"pack:dry": "bun pm pack --dry-run"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"zod": "^
|
|
24
|
+
"zod": "^4.6.7"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"typescript": "^5.9.3"
|
package/src/index.ts
CHANGED
|
@@ -22,11 +22,13 @@ export {
|
|
|
22
22
|
export { logger } from "./logger";
|
|
23
23
|
|
|
24
24
|
export function toKebabCase(input: string): string {
|
|
25
|
-
|
|
25
|
+
let value = input
|
|
26
26
|
.trim()
|
|
27
27
|
.toLowerCase()
|
|
28
|
-
.replace(/[^a-z0-9]+/g, "-")
|
|
29
|
-
|
|
28
|
+
.replace(/[^a-z0-9]+/g, "-");
|
|
29
|
+
while (value.startsWith("-")) value = value.slice(1);
|
|
30
|
+
while (value.endsWith("-")) value = value.slice(0, -1);
|
|
31
|
+
return value;
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
export function toAppId(slug: string, prefix = "com.example"): string {
|
package/src/schema.test.ts
CHANGED
|
@@ -70,6 +70,7 @@ describe("targets", () => {
|
|
|
70
70
|
describe("helpers", () => {
|
|
71
71
|
test("toKebabCase and toAppId", () => {
|
|
72
72
|
expect(toKebabCase("My Cool App")).toBe("my-cool-app");
|
|
73
|
+
expect(toKebabCase("---edge---")).toBe("edge");
|
|
73
74
|
expect(toAppId("my-cool-app")).toBe("com.example.mycoolapp");
|
|
74
75
|
});
|
|
75
76
|
});
|
package/src/schema.ts
CHANGED
|
@@ -1,122 +1,128 @@
|
|
|
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
|
-
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
export
|
|
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
|
-
outDir: "dist/
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
+
export type MagicPwaConfig = z.infer<typeof MagicPwaConfigSchema>;
|
|
65
|
+
|
|
66
|
+
export function defineConfig(config: MagicPwaConfig): MagicPwaConfig {
|
|
67
|
+
return MagicPwaConfigSchema.parse(config);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function createDefaultConfig(overrides: {
|
|
71
|
+
name: string;
|
|
72
|
+
slug: string;
|
|
73
|
+
appId: string;
|
|
74
|
+
template: PwaTemplate;
|
|
75
|
+
description?: string;
|
|
76
|
+
author?: string;
|
|
77
|
+
targets?: Partial<MagicPwaConfig["targets"]>;
|
|
78
|
+
}): MagicPwaConfig {
|
|
79
|
+
const targets = {
|
|
80
|
+
web: true,
|
|
81
|
+
electron: true,
|
|
82
|
+
chrome: true,
|
|
83
|
+
android: true,
|
|
84
|
+
...overrides.targets,
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const isBlank = overrides.template === "blank";
|
|
88
|
+
|
|
89
|
+
return defineConfig({
|
|
90
|
+
name: overrides.name,
|
|
91
|
+
slug: overrides.slug,
|
|
92
|
+
appId: overrides.appId,
|
|
93
|
+
description: overrides.description ?? `${overrides.name} — multi-target PWA`,
|
|
94
|
+
author: overrides.author ?? "Unknown",
|
|
95
|
+
version: "0.1.0",
|
|
96
|
+
template: overrides.template,
|
|
97
|
+
targets,
|
|
98
|
+
pwa: {
|
|
99
|
+
startUrl: "/",
|
|
100
|
+
display: "standalone",
|
|
101
|
+
themeColor: isBlank ? "#ffffff" : "#0f172a",
|
|
102
|
+
backgroundColor: isBlank ? "#ffffff" : "#0f172a",
|
|
103
|
+
outDir: "dist/web",
|
|
104
|
+
},
|
|
105
|
+
electron: {
|
|
106
|
+
outDir: "dist/electron",
|
|
107
|
+
windowTitle: overrides.name,
|
|
108
|
+
width: 1200,
|
|
109
|
+
height: 800,
|
|
110
|
+
minWidth: 800,
|
|
111
|
+
minHeight: 600,
|
|
112
|
+
},
|
|
113
|
+
chrome: {
|
|
114
|
+
outDir: "dist/chrome",
|
|
115
|
+
manifestVersion: 3,
|
|
116
|
+
permissions: isBlank ? [] : ["storage", "sidePanel"],
|
|
117
|
+
hostPermissions: [],
|
|
118
|
+
},
|
|
119
|
+
android: {
|
|
120
|
+
outDir: "dist/android",
|
|
121
|
+
packageName: overrides.appId,
|
|
122
|
+
mode: "url",
|
|
123
|
+
url: "http://localhost:5173",
|
|
124
|
+
statusBarStyle: "auto",
|
|
125
|
+
enableHaptics: !isBlank,
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
}
|