@involvex/magic-pwa-core 0.0.0-stage → 0.1.1

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 CHANGED
@@ -1,6 +1,44 @@
1
1
  {
2
2
  "name": "@involvex/magic-pwa-core",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "Shared config schema and helpers for Magic-PWA",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "main": "./src/index.ts",
8
+ "types": "./src/index.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./src/index.ts",
12
+ "import": "./src/index.ts",
13
+ "default": "./src/index.ts"
14
+ }
15
+ },
16
+ "files": [
17
+ "src"
18
+ ],
19
+ "scripts": {
20
+ "test": "bun test",
21
+ "pack:dry": "bun pm pack --dry-run"
22
+ },
23
+ "dependencies": {
24
+ "zod": "^4.6.7"
25
+ },
26
+ "devDependencies": {
27
+ "typescript": "^5.9.3"
28
+ },
29
+ "engines": {
30
+ "bun": ">=1.1.0"
31
+ },
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/involvex/magic-pwa.git",
35
+ "directory": "packages/core"
36
+ },
37
+ "homepage": "https://github.com/involvex/magic-pwa#readme",
38
+ "bugs": {
39
+ "url": "https://github.com/involvex/magic-pwa/issues"
40
+ },
41
+ "publishConfig": {
42
+ "access": "public"
43
+ }
44
+ }
package/src/index.ts ADDED
@@ -0,0 +1,44 @@
1
+ export {
2
+ BuildTargetSchema,
3
+ ExpoLoadModeSchema,
4
+ MagicPwaConfigSchema,
5
+ PwaTemplateSchema,
6
+ createDefaultConfig,
7
+ defineConfig,
8
+ type BuildTarget,
9
+ type ExpoLoadMode,
10
+ type MagicPwaConfig,
11
+ type PwaTemplate,
12
+ } from "./schema";
13
+
14
+ export {
15
+ ALL_TARGETS,
16
+ parseBuildArgs,
17
+ parseNoTargetFlags,
18
+ resolveTargets,
19
+ type TargetFlags,
20
+ } from "./targets";
21
+
22
+ export { logger } from "./logger";
23
+
24
+ export function toKebabCase(input: string): string {
25
+ let value = input
26
+ .trim()
27
+ .toLowerCase()
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;
32
+ }
33
+
34
+ export function toAppId(slug: string, prefix = "com.example"): string {
35
+ const clean = slug.replace(/-/g, "");
36
+ return `${prefix}.${clean || "app"}`;
37
+ }
38
+
39
+ export function serializeConfig(config: import("./schema").MagicPwaConfig): string {
40
+ return `import { defineConfig } from '@involvex/magic-pwa';
41
+
42
+ export default defineConfig(${JSON.stringify(config, null, 2)});
43
+ `;
44
+ }
package/src/logger.ts ADDED
@@ -0,0 +1,20 @@
1
+ export const logger = {
2
+ info(message: string) {
3
+ console.log(`ℹ ${message}`);
4
+ },
5
+ success(message: string) {
6
+ console.log(`✔ ${message}`);
7
+ },
8
+ warn(message: string) {
9
+ console.warn(`⚠ ${message}`);
10
+ },
11
+ error(message: string) {
12
+ console.error(`✖ ${message}`);
13
+ },
14
+ step(message: string) {
15
+ console.log(message);
16
+ },
17
+ dim(message: string) {
18
+ console.log(message);
19
+ },
20
+ };
@@ -0,0 +1,76 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { createDefaultConfig, MagicPwaConfigSchema } from "./schema";
3
+ import { parseBuildArgs, parseNoTargetFlags, resolveTargets } from "./targets";
4
+ import { toAppId, toKebabCase } from "./index";
5
+
6
+ describe("schema", () => {
7
+ test("createDefaultConfig produces a valid config", () => {
8
+ const config = createDefaultConfig({
9
+ name: "Demo",
10
+ slug: "demo",
11
+ appId: "com.example.demo",
12
+ template: "basic",
13
+ });
14
+ expect(MagicPwaConfigSchema.parse(config).slug).toBe("demo");
15
+ expect(config.targets.electron).toBe(true);
16
+ });
17
+
18
+ test("defineConfig rejects bad slug", () => {
19
+ expect(() =>
20
+ MagicPwaConfigSchema.parse({
21
+ ...createDefaultConfig({
22
+ name: "X",
23
+ slug: "ok-slug",
24
+ appId: "com.example.x",
25
+ template: "blank",
26
+ }),
27
+ slug: "Bad_Slug",
28
+ }),
29
+ ).toThrow();
30
+ });
31
+
32
+ test("--no-* flags disable targets", () => {
33
+ const flags = parseNoTargetFlags(["--no-chrome", "--no-android"]);
34
+ const config = createDefaultConfig({
35
+ name: "Demo",
36
+ slug: "demo",
37
+ appId: "com.example.demo",
38
+ template: "blank",
39
+ targets: flags,
40
+ });
41
+ expect(config.targets.chrome).toBe(false);
42
+ expect(config.targets.android).toBe(false);
43
+ expect(config.targets.web).toBe(true);
44
+ });
45
+ });
46
+
47
+ describe("targets", () => {
48
+ test("parseBuildArgs reads target and portable", () => {
49
+ expect(parseBuildArgs(["electron", "--portable"])).toEqual({
50
+ target: "electron",
51
+ portable: true,
52
+ rest: [],
53
+ });
54
+ });
55
+
56
+ test("resolveTargets filters disabled", () => {
57
+ const config = createDefaultConfig({
58
+ name: "Demo",
59
+ slug: "demo",
60
+ appId: "com.example.demo",
61
+ template: "basic",
62
+ targets: { chrome: false },
63
+ });
64
+ expect(resolveTargets(config)).toEqual(["web", "electron", "android"]);
65
+ expect(resolveTargets(config, "web")).toEqual(["web"]);
66
+ expect(() => resolveTargets(config, "chrome")).toThrow();
67
+ });
68
+ });
69
+
70
+ describe("helpers", () => {
71
+ test("toKebabCase and toAppId", () => {
72
+ expect(toKebabCase("My Cool App")).toBe("my-cool-app");
73
+ expect(toKebabCase("---edge---")).toBe("edge");
74
+ expect(toAppId("my-cool-app")).toBe("com.example.mycoolapp");
75
+ });
76
+ });
package/src/schema.ts ADDED
@@ -0,0 +1,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
+ 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
+ }
package/src/targets.ts ADDED
@@ -0,0 +1,65 @@
1
+ import type { BuildTarget, MagicPwaConfig } from "./schema";
2
+ import { BuildTargetSchema } from "./schema";
3
+
4
+ export const ALL_TARGETS: BuildTarget[] = ["web", "electron", "chrome", "android"];
5
+
6
+ export type TargetFlags = {
7
+ web: boolean;
8
+ electron: boolean;
9
+ chrome: boolean;
10
+ android: boolean;
11
+ };
12
+
13
+ export function parseNoTargetFlags(args: string[]): Partial<TargetFlags> {
14
+ const result: Partial<TargetFlags> = {};
15
+ for (const arg of args) {
16
+ if (arg === "--no-web") result.web = false;
17
+ if (arg === "--no-electron") result.electron = false;
18
+ if (arg === "--no-chrome") result.chrome = false;
19
+ if (arg === "--no-android") result.android = false;
20
+ }
21
+ return result;
22
+ }
23
+
24
+ export function resolveTargets(config: MagicPwaConfig, requested?: string | null): BuildTarget[] {
25
+ if (requested) {
26
+ const target = BuildTargetSchema.parse(requested);
27
+ if (!config.targets[target]) {
28
+ throw new Error(`Target "${target}" is disabled in magic-pwa.config.ts`);
29
+ }
30
+ return [target];
31
+ }
32
+
33
+ return ALL_TARGETS.filter((target) => config.targets[target]);
34
+ }
35
+
36
+ export function parseBuildArgs(argv: string[]): {
37
+ target: BuildTarget | null;
38
+ portable: boolean;
39
+ rest: string[];
40
+ } {
41
+ const rest: string[] = [];
42
+ let target: BuildTarget | null = null;
43
+ let portable = false;
44
+
45
+ for (const arg of argv) {
46
+ if (arg === "--portable") {
47
+ portable = true;
48
+ continue;
49
+ }
50
+ if (arg.startsWith("-")) {
51
+ rest.push(arg);
52
+ continue;
53
+ }
54
+ if (!target) {
55
+ const parsed = BuildTargetSchema.safeParse(arg);
56
+ if (parsed.success) {
57
+ target = parsed.data;
58
+ continue;
59
+ }
60
+ }
61
+ rest.push(arg);
62
+ }
63
+
64
+ return { target, portable, rest };
65
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.