@involvex/magic-pwa-core 0.1.1 → 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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. 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.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",
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
- version: z.string().min(1),
23
- template: PwaTemplateSchema,
24
- targets: z.object({
25
- web: z.boolean(),
26
- electron: z.boolean(),
27
- chrome: z.boolean(),
28
- android: z.boolean(),
29
- }),
30
- pwa: z.object({
31
- startUrl: z.string().min(1),
32
- display: z.enum(["standalone", "minimal-ui", "fullscreen"]),
33
- themeColor: z.string().min(1),
34
- backgroundColor: z.string().min(1),
35
- outDir: z.string().min(1),
36
- }),
37
- electron: z.object({
38
- outDir: z.string().min(1),
39
- windowTitle: z.string().min(1),
40
- width: z.number().int().positive(),
41
- height: z.number().int().positive(),
42
- minWidth: z.number().int().positive().optional(),
43
- minHeight: z.number().int().positive().optional(),
44
- loadUrl: z.string().url().optional(),
45
- }),
46
- chrome: z.object({
47
- outDir: z.string().min(1),
48
- manifestVersion: z.literal(3),
49
- permissions: z.array(z.string()).max(64),
50
- hostPermissions: z.array(z.string()).max(64),
51
- }),
52
- android: z.object({
53
- outDir: z.string().min(1),
54
- packageName: z.string().min(1),
55
- mode: ExpoLoadModeSchema,
56
- url: z.string().url().optional(),
57
- statusBarStyle: z.enum(["auto", "light", "dark"]),
58
- enableHaptics: z.boolean(),
59
- }),
60
- });
61
-
62
- export type MagicPwaConfig = z.infer<typeof MagicPwaConfigSchema>;
63
-
64
- export function defineConfig(config: MagicPwaConfig): MagicPwaConfig {
65
- return MagicPwaConfigSchema.parse(config);
66
- }
67
-
68
- export function createDefaultConfig(overrides: {
69
- name: string;
70
- slug: string;
71
- appId: string;
72
- template: PwaTemplate;
73
- targets?: Partial<MagicPwaConfig["targets"]>;
74
- }): MagicPwaConfig {
75
- const targets = {
76
- web: true,
77
- electron: true,
78
- chrome: true,
79
- android: true,
80
- ...overrides.targets,
81
- };
82
-
83
- const isBlank = overrides.template === "blank";
84
-
85
- return defineConfig({
86
- name: overrides.name,
87
- slug: overrides.slug,
88
- appId: overrides.appId,
89
- version: "0.1.0",
90
- template: overrides.template,
91
- targets,
92
- pwa: {
93
- startUrl: "/",
94
- display: "standalone",
95
- themeColor: isBlank ? "#ffffff" : "#0f172a",
96
- backgroundColor: isBlank ? "#ffffff" : "#0f172a",
97
- outDir: "dist/web",
98
- },
99
- electron: {
100
- outDir: "dist/electron",
101
- windowTitle: overrides.name,
102
- width: 1200,
103
- height: 800,
104
- minWidth: 800,
105
- minHeight: 600,
106
- },
107
- chrome: {
108
- outDir: "dist/chrome",
109
- manifestVersion: 3,
110
- permissions: isBlank ? [] : ["storage", "sidePanel"],
111
- hostPermissions: [],
112
- },
113
- android: {
114
- outDir: "dist/android",
115
- packageName: overrides.appId,
116
- mode: "url",
117
- url: "http://localhost:5173",
118
- statusBarStyle: "auto",
119
- enableHaptics: !isBlank,
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
+ }