@swoff/cli 0.3.7 → 0.3.9
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/README.md +53 -606
- package/dist/__tests__/assemble-sw.test.js +8 -38
- package/dist/__tests__/assemble-sw.test.js.map +1 -1
- package/dist/__tests__/cli-integration.test.js +119 -11
- package/dist/__tests__/cli-integration.test.js.map +1 -1
- package/dist/__tests__/config-types.test.js +38 -18
- package/dist/__tests__/config-types.test.js.map +1 -1
- package/dist/__tests__/file-generators.test.js +2 -2
- package/dist/__tests__/file-generators.test.js.map +1 -1
- package/dist/__tests__/glob-matcher.test.js +86 -0
- package/dist/__tests__/glob-matcher.test.js.map +1 -0
- package/dist/__tests__/invalidation-tags.test.js +207 -23
- package/dist/__tests__/invalidation-tags.test.js.map +1 -1
- package/dist/__tests__/loader.test.js +12 -12
- package/dist/__tests__/loader.test.js.map +1 -1
- package/dist/__tests__/validator.test.js +170 -74
- package/dist/__tests__/validator.test.js.map +1 -1
- package/dist/index.js +12 -11
- package/dist/index.js.map +1 -1
- package/dist/lib/cli/help.js +0 -5
- package/dist/lib/cli/help.js.map +1 -1
- package/dist/lib/commands/add.js +52 -33
- package/dist/lib/commands/add.js.map +1 -1
- package/dist/lib/commands/clean.js +1 -15
- package/dist/lib/commands/clean.js.map +1 -1
- package/dist/lib/commands/generate-guide.js +5 -5
- package/dist/lib/commands/generate-guide.js.map +1 -1
- package/dist/lib/commands/generate.js +7 -21
- package/dist/lib/commands/generate.js.map +1 -1
- package/dist/lib/commands/info.js +37 -12
- package/dist/lib/commands/info.js.map +1 -1
- package/dist/lib/commands/init.js +2 -10
- package/dist/lib/commands/init.js.map +1 -1
- package/dist/lib/commands/validate.js +3 -3
- package/dist/lib/commands/validate.js.map +1 -1
- package/dist/lib/config/loader.js +3 -6
- package/dist/lib/config/loader.js.map +1 -1
- package/dist/lib/config/validator.js +192 -42
- package/dist/lib/config/validator.js.map +1 -1
- package/dist/lib/generators/file-generators/cache.js +2 -10
- package/dist/lib/generators/file-generators/cache.js.map +1 -1
- package/dist/lib/generators/file-generators/client-injector.js +51 -12
- package/dist/lib/generators/file-generators/client-injector.js.map +1 -1
- package/dist/lib/generators/file-generators/fetch-wrapper.js +127 -58
- package/dist/lib/generators/file-generators/fetch-wrapper.js.map +1 -1
- package/dist/lib/generators/file-generators/generate-hooks.js +6 -2
- package/dist/lib/generators/file-generators/generate-hooks.js.map +1 -1
- package/dist/lib/generators/file-generators/gql-wrapper.js +139 -0
- package/dist/lib/generators/file-generators/gql-wrapper.js.map +1 -0
- package/dist/lib/generators/file-generators/guide-generator.js +6 -436
- package/dist/lib/generators/file-generators/guide-generator.js.map +1 -1
- package/dist/lib/generators/file-generators/invalidation-tags.js +206 -19
- package/dist/lib/generators/file-generators/invalidation-tags.js.map +1 -1
- package/dist/lib/generators/file-generators/manifest.js +2 -2
- package/dist/lib/generators/file-generators/manifest.js.map +1 -1
- package/dist/lib/generators/file-generators/mutation-queue.js +140 -52
- package/dist/lib/generators/file-generators/mutation-queue.js.map +1 -1
- package/dist/lib/generators/file-generators/mutation-state.js +126 -0
- package/dist/lib/generators/file-generators/mutation-state.js.map +1 -0
- package/dist/lib/generators/file-generators/push.js +6 -7
- package/dist/lib/generators/file-generators/push.js.map +1 -1
- package/dist/lib/generators/file-generators/quick-readme.js +8 -75
- package/dist/lib/generators/file-generators/quick-readme.js.map +1 -1
- package/dist/lib/generators/file-generators/server-push.js +146 -0
- package/dist/lib/generators/file-generators/server-push.js.map +1 -0
- package/dist/lib/generators/file-generators/sw-generator-build.js +8 -9
- package/dist/lib/generators/file-generators/sw-generator-build.js.map +1 -1
- package/dist/lib/generators/file-generators/sw-injector.js +2 -1
- package/dist/lib/generators/file-generators/sw-injector.js.map +1 -1
- package/dist/lib/generators/file-generators/type-definitions.js +26 -1
- package/dist/lib/generators/file-generators/type-definitions.js.map +1 -1
- package/dist/lib/generators/sw-generator.js +8 -18
- package/dist/lib/generators/sw-generator.js.map +1 -1
- package/dist/lib/generators/sw-sections/activate-handler.js.map +1 -1
- package/dist/lib/generators/sw-sections/assemble-sw.js +19 -11
- package/dist/lib/generators/sw-sections/assemble-sw.js.map +1 -1
- package/dist/lib/generators/sw-sections/background-sync-handler.js +80 -24
- package/dist/lib/generators/sw-sections/background-sync-handler.js.map +1 -1
- package/dist/lib/generators/sw-sections/config-header.js +2 -2
- package/dist/lib/generators/sw-sections/config-header.js.map +1 -1
- package/dist/lib/generators/sw-sections/default-template.js +2 -1
- package/dist/lib/generators/sw-sections/default-template.js.map +1 -1
- package/dist/lib/generators/sw-sections/fetch-handler.js +461 -121
- package/dist/lib/generators/sw-sections/fetch-handler.js.map +1 -1
- package/dist/lib/generators/sw-sections/message-handler.js +55 -15
- package/dist/lib/generators/sw-sections/message-handler.js.map +1 -1
- package/dist/lib/generators/sw-sections/server-push-handler.js +114 -0
- package/dist/lib/generators/sw-sections/server-push-handler.js.map +1 -0
- package/dist/lib/generators/sw-sections/sw-push.js +67 -0
- package/dist/lib/generators/sw-sections/sw-push.js.map +1 -0
- package/dist/lib/generators/sw-sections/tag-management.js +62 -21
- package/dist/lib/generators/sw-sections/tag-management.js.map +1 -1
- package/dist/lib/generators/swoff-files-generator.js +12 -16
- package/dist/lib/generators/swoff-files-generator.js.map +1 -1
- package/dist/lib/shared/config-types.js +133 -45
- package/dist/lib/shared/config-types.js.map +1 -1
- package/dist/lib/shared/glob-matcher.js +77 -0
- package/dist/lib/shared/glob-matcher.js.map +1 -0
- package/dist/lib/utils/tty-status.js +21 -0
- package/dist/lib/utils/tty-status.js.map +1 -0
- package/docs/API.md +565 -0
- package/docs/ARCHITECTURE.md +374 -0
- package/docs/CLI.md +148 -0
- package/docs/COMPARISON.md +192 -0
- package/docs/CONFIG.md +277 -0
- package/docs/ECOSYSTEM.md +33 -0
- package/package.json +2 -1
- package/templates/hooks/useAuth.jsx +2 -2
- package/templates/hooks/useAuth.tsx +2 -2
- package/templates/hooks/useCachedFetch.jsx +21 -7
- package/templates/hooks/useCachedFetch.tsx +23 -11
- package/templates/hooks/useMutation.jsx +76 -0
- package/templates/hooks/useMutation.tsx +109 -0
- package/templates/hooks/useMutationQueue.jsx +20 -11
- package/templates/hooks/useMutationQueue.tsx +31 -15
- package/templates/hooks/useMutationState.jsx +13 -0
- package/templates/hooks/useMutationState.tsx +25 -0
- package/templates/hooks/usePrefetch.jsx +10 -0
- package/templates/hooks/usePrefetch.tsx +25 -0
- package/templates/hooks/usePushSubscription.jsx +3 -3
- package/templates/hooks/usePushSubscription.tsx +3 -3
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates mutation-state.ts/js — per-mutation state tracking.
|
|
3
|
+
* Provides a lightweight store for tracking individual mutation lifecycle states,
|
|
4
|
+
* enabling useMutation-style hooks and fine-grained mutation status UI.
|
|
5
|
+
*/
|
|
6
|
+
import { writeFile } from "./context.js";
|
|
7
|
+
export function generateMutationState(ctx) {
|
|
8
|
+
const ext = ctx.ext;
|
|
9
|
+
const ts = ext === "ts";
|
|
10
|
+
const T = (type) => (ts ? `: ${type}` : "");
|
|
11
|
+
const R = (type) => (ts ? `: ${type}` : " ");
|
|
12
|
+
const code = `/**
|
|
13
|
+
* Swoff Mutation State
|
|
14
|
+
* Lightweight in-memory mutation state tracker.
|
|
15
|
+
* Enables per-mutation status UI (loading spinners, error states, success indicators).
|
|
16
|
+
*
|
|
17
|
+
* Usage:
|
|
18
|
+
* import { trackMutation, getMutationState, clearMutationState } from './swoff/mutation-state.${ext}';
|
|
19
|
+
*
|
|
20
|
+
* // After queueing a mutation
|
|
21
|
+
* const id = "mutation-" + crypto.randomUUID();
|
|
22
|
+
* trackMutation(id, "pending");
|
|
23
|
+
*
|
|
24
|
+
* // Check state later
|
|
25
|
+
* const state = getMutationState(id);
|
|
26
|
+
* if (state?.status === "error") { showError(state.error); }
|
|
27
|
+
*
|
|
28
|
+
* // Clear when done
|
|
29
|
+
* clearMutationState(id);
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
export type MutationStatus = "idle" | "pending" | "success" | "error";
|
|
33
|
+
|
|
34
|
+
export interface MutationState {
|
|
35
|
+
id${T("string")};
|
|
36
|
+
status${T("MutationStatus")};
|
|
37
|
+
error${T("Error | null")};
|
|
38
|
+
data${T("unknown")};
|
|
39
|
+
timestamp${T("number")};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const mutations = new Map<string, MutationState>();
|
|
43
|
+
|
|
44
|
+
let listenerId = 0;
|
|
45
|
+
const listeners = new Map<number, (state: MutationState) => void>();
|
|
46
|
+
|
|
47
|
+
/** Track a mutation with the given ID and initial status. */
|
|
48
|
+
export function trackMutation(id${T("string")}, status${T("MutationStatus")} = "idle")${R("MutationState")}{
|
|
49
|
+
let state = mutations.get(id);
|
|
50
|
+
if (!state) {
|
|
51
|
+
state = { id, status, error: null, data: null, timestamp: Date.now() };
|
|
52
|
+
mutations.set(id, state);
|
|
53
|
+
} else {
|
|
54
|
+
state.status = status;
|
|
55
|
+
state.timestamp = Date.now();
|
|
56
|
+
}
|
|
57
|
+
notifyListeners(state);
|
|
58
|
+
window.dispatchEvent(new CustomEvent("mutation-state-changed", { detail: state }));
|
|
59
|
+
return state;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Update an existing mutation's state. */
|
|
63
|
+
export function updateMutationState(id${T("string")}, partial${T("Partial<MutationState>")})${R("MutationState | null")}{
|
|
64
|
+
const state = mutations.get(id);
|
|
65
|
+
if (!state) return null;
|
|
66
|
+
Object.assign(state, partial);
|
|
67
|
+
state.timestamp = Date.now();
|
|
68
|
+
notifyListeners(state);
|
|
69
|
+
window.dispatchEvent(new CustomEvent("mutation-state-changed", { detail: state }));
|
|
70
|
+
return state;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Mark a mutation as successful with optional data. */
|
|
74
|
+
export function resolveMutation(id${T("string")}, data${T("unknown")} = null)${R("void")}{
|
|
75
|
+
updateMutationState(id, { status: "success", data, error: null });
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Mark a mutation as failed with an error. */
|
|
79
|
+
export function rejectMutation(id${T("string")}, error${T("Error")})${R("void")}{
|
|
80
|
+
updateMutationState(id, { status: "error", error });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Get the current state of a mutation by ID. */
|
|
84
|
+
export function getMutationState(id${T("string")})${R("MutationState | undefined")}{
|
|
85
|
+
return mutations.get(id);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Remove a mutation's state from the tracker. */
|
|
89
|
+
export function clearMutationState(id${T("string")})${R("void")}{
|
|
90
|
+
mutations.delete(id);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Get all tracked mutations. */
|
|
94
|
+
export function getAllMutationStates()${R("MutationState[]")}{
|
|
95
|
+
return Array.from(mutations.values());
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Get the count of mutations in a given status. */
|
|
99
|
+
export function getMutationCount(status${T("MutationStatus")})${R("number")}{
|
|
100
|
+
let count = 0;
|
|
101
|
+
for (const state of mutations.values()) {
|
|
102
|
+
if (state.status === status) count++;
|
|
103
|
+
}
|
|
104
|
+
return count;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Subscribe to mutation state changes. Returns an unsubscribe function. */
|
|
108
|
+
export function onMutationStateChange(callback${T("(state: MutationState) => void")})${R("() => void")}{
|
|
109
|
+
const id = ++listenerId;
|
|
110
|
+
listeners.set(id, callback);
|
|
111
|
+
return () => { listeners.delete(id); };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function notifyListeners(state${T("MutationState")})${R("void")}{
|
|
115
|
+
for (const cb of listeners.values()) {
|
|
116
|
+
try {
|
|
117
|
+
cb(state);
|
|
118
|
+
} catch {
|
|
119
|
+
// Handle listener errors silently
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
`;
|
|
124
|
+
writeFile(ctx, `mutation-state.${ext}`, code);
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=mutation-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutation-state.js","sourceRoot":"","sources":["../../../../src/lib/generators/file-generators/mutation-state.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAoB,SAAS,EAAE,MAAM,cAAc,CAAC;AAE3D,MAAM,UAAU,qBAAqB,CAAC,GAAqB;IACzD,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC;IACpB,MAAM,EAAE,GAAG,GAAG,KAAK,IAAI,CAAC;IACxB,MAAM,CAAC,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACpD,MAAM,CAAC,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAErD,MAAM,IAAI,GAAG;;;;;;mGAMoF,GAAG;;;;;;;;;;;;;;;;;MAiBhG,CAAC,CAAC,QAAQ,CAAC;UACP,CAAC,CAAC,gBAAgB,CAAC;SACpB,CAAC,CAAC,cAAc,CAAC;QAClB,CAAC,CAAC,SAAS,CAAC;aACP,CAAC,CAAC,QAAQ,CAAC;;;;;;;;;kCASU,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC,eAAe,CAAC;;;;;;;;;;;;;;;wCAelE,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC,sBAAsB,CAAC;;;;;;;;;;;oCAWnF,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC;;;;;mCAKrD,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;;;;;qCAK1C,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,2BAA2B,CAAC;;;;;uCAK3C,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;;;;;wCAKvB,CAAC,CAAC,iBAAiB,CAAC;;;;;yCAKnB,CAAC,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC;;;;;;;;;gDAS3B,CAAC,CAAC,gCAAgC,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC;;;;;;gCAMtE,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;;;;;;;;;CAS9D,CAAC;IAEA,SAAS,CAAC,GAAG,EAAE,kBAAkB,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC;AAChD,CAAC"}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generates push.{js|ts} - push notification subscription management.
|
|
3
|
-
*/
|
|
4
1
|
import { writeFile } from "./context.js";
|
|
5
2
|
export function generatePush(ctx) {
|
|
6
3
|
const ext = ctx.ext;
|
|
@@ -9,6 +6,7 @@ export function generatePush(ctx) {
|
|
|
9
6
|
const R = (type) => (ts ? `: ${type} ` : " ");
|
|
10
7
|
const PT = (type) => (ts ? `<${type}>` : "");
|
|
11
8
|
const AS = (type) => (ts ? ` as ${type}` : "");
|
|
9
|
+
const vapidKey = ctx.config.features.pushNotifications?.vapidPublicKey ?? "";
|
|
12
10
|
const code = `/**
|
|
13
11
|
* Swoff Push Notifications
|
|
14
12
|
* Push subscription management with IndexedDB persistence.
|
|
@@ -17,7 +15,7 @@ export function generatePush(ctx) {
|
|
|
17
15
|
* import { subscribeToPush, unsubscribeFromPush, isSubscribed } from './swoff/push.${ext}';
|
|
18
16
|
*
|
|
19
17
|
* // Enable (triggers permission prompt)
|
|
20
|
-
* const subscription = await subscribeToPush(
|
|
18
|
+
* const subscription = await subscribeToPush();
|
|
21
19
|
* await fetch("/api/push/subscribe", {
|
|
22
20
|
* method: "POST",
|
|
23
21
|
* body: JSON.stringify(subscription.toJSON()),
|
|
@@ -33,6 +31,7 @@ export function generatePush(ctx) {
|
|
|
33
31
|
|
|
34
32
|
const SUBSCRIPTION_DB = "swoff-push";
|
|
35
33
|
const SUBSCRIPTION_STORE = "subscription";
|
|
34
|
+
const VAPID_PUBLIC_KEY = ${JSON.stringify(vapidKey)};
|
|
36
35
|
|
|
37
36
|
let permissionState = Notification.permission;
|
|
38
37
|
|
|
@@ -73,15 +72,15 @@ export async function getPushSubscription()${R("Promise<PushSubscription | null>
|
|
|
73
72
|
}
|
|
74
73
|
}
|
|
75
74
|
|
|
76
|
-
/** Subscribe to push notifications. Returns the subscription or null if permission denied. */
|
|
77
|
-
export async function subscribeToPush(
|
|
75
|
+
/** Subscribe to push notifications. Returns the subscription or null if permission denied. Uses the VAPID public key from your swoff.config.json. */
|
|
76
|
+
export async function subscribeToPush()${R("Promise<PushSubscription | null>")}{
|
|
78
77
|
const granted = await requestNotificationPermission();
|
|
79
78
|
if (!granted) return null;
|
|
80
79
|
|
|
81
80
|
const registration = await navigator.serviceWorker.ready;
|
|
82
81
|
const subscription = await registration.pushManager.subscribe({
|
|
83
82
|
userVisibleOnly: true,
|
|
84
|
-
applicationServerKey: urlBase64ToUint8Array(
|
|
83
|
+
applicationServerKey: urlBase64ToUint8Array(VAPID_PUBLIC_KEY)${AS("BufferSource")},
|
|
85
84
|
});
|
|
86
85
|
|
|
87
86
|
const db = await openPushDB();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"push.js","sourceRoot":"","sources":["../../../../src/lib/generators/file-generators/push.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"push.js","sourceRoot":"","sources":["../../../../src/lib/generators/file-generators/push.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,SAAS,EAAE,MAAM,cAAc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X,EAAE,CAAC,cAAc,CAAC;;;;;;;;;;;;;;;;;;;;;;;;6CAwBxC,CAAC,CAAC,eAAe,CAAC;;;;;;;;;;;;;;;;;;;;sCAoBzB,CAAC,CAAC,kBAAkB,CAAC;;;;;;6CAMd,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC;;;;;;CAM1E,CAAC;IAEA,SAAS,CAAC,GAAG,EAAE,QAAQ,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -1,88 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Generates README.md — quick reference
|
|
2
|
+
* Generates README.md — quick reference that points to the static docs.
|
|
3
3
|
*/
|
|
4
4
|
import { writeFile } from "./context.js";
|
|
5
5
|
export function generateReadme(ctx) {
|
|
6
|
-
const { config } = ctx;
|
|
7
|
-
const ext = ctx.ext;
|
|
8
6
|
const lines = [];
|
|
9
7
|
const w = (s) => lines.push(s);
|
|
10
8
|
w("# Swoff — Quick Reference");
|
|
11
9
|
w("");
|
|
12
|
-
w("For the
|
|
10
|
+
w("For the complete API reference, see:");
|
|
13
11
|
w("");
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
w("initServiceWorker();");
|
|
20
|
-
w("```");
|
|
21
|
-
w("");
|
|
22
|
-
}
|
|
23
|
-
w("## API calls (use for all fetch requests)");
|
|
24
|
-
w("Use `fetchWithCache` instead of `fetch()` — it sets caching headers the SW needs.");
|
|
25
|
-
w("Plain `fetch()` skips SW caching when `cacheStrategy` is `\"explicit-only\"`.");
|
|
26
|
-
w("```ts");
|
|
27
|
-
w(`import { fetchWithCache } from "./swoff/fetch-wrapper.${ext}";`);
|
|
28
|
-
w('const data = await fetchWithCache("/api/data").then(r => r.json());');
|
|
29
|
-
w("```");
|
|
12
|
+
w("- `node_modules/@swoff/cli/docs/API.md` — every generated function");
|
|
13
|
+
w("- `node_modules/@swoff/cli/docs/ARCHITECTURE.md` — design & rationale");
|
|
14
|
+
w("- `node_modules/@swoff/cli/docs/CLI.md` — CLI commands");
|
|
15
|
+
w("- `node_modules/@swoff/cli/docs/CONFIG.md` — config schema");
|
|
16
|
+
w("- `node_modules/@swoff/cli/docs/COMPARISON.md` — library comparison");
|
|
30
17
|
w("");
|
|
31
|
-
|
|
32
|
-
w("## Authenticated API calls");
|
|
33
|
-
w("```ts");
|
|
34
|
-
w(`import { fetchWithCache } from "./swoff/fetch-wrapper.${ext}";`);
|
|
35
|
-
w('const data = await fetchWithCache("/api/me", { auth: true }).then(r => r.json());');
|
|
36
|
-
w("```");
|
|
37
|
-
w("");
|
|
38
|
-
}
|
|
39
|
-
if (config.features.mutationQueue) {
|
|
40
|
-
w("## Offline mutations (queue writes when offline)");
|
|
41
|
-
w("```ts");
|
|
42
|
-
w(`import { queueMutation, getPendingCount } from "./swoff/mutation-queue.${ext}";`);
|
|
43
|
-
w("await queueMutation({ method: \"POST\", url: \"/api/todos\", body: {...} });");
|
|
44
|
-
w("```");
|
|
45
|
-
w("");
|
|
46
|
-
if (config.features.auth.enabled) {
|
|
47
|
-
w("## After re-login (flush queued mutations)");
|
|
48
|
-
w("```ts");
|
|
49
|
-
w(`import { flushMutations } from "./swoff/mutation-queue.${ext}";`);
|
|
50
|
-
w("await flushMutations();");
|
|
51
|
-
w("```");
|
|
52
|
-
w("");
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
if (config.features.pushNotifications?.enabled) {
|
|
56
|
-
w("## Push notifications");
|
|
57
|
-
w("```ts");
|
|
58
|
-
w(`import { subscribeToPush, unsubscribeFromPush, isSubscribed } from "./swoff/push.${ext}";`);
|
|
59
|
-
w('const sub = await subscribeToPush("YOUR_VAPID_PUBLIC_KEY");');
|
|
60
|
-
w("```");
|
|
61
|
-
w("");
|
|
62
|
-
}
|
|
63
|
-
if (config.features.tagInvalidation) {
|
|
64
|
-
w("## Cache invalidation");
|
|
65
|
-
w("```ts");
|
|
66
|
-
w(`import { generateTags, invalidateUrl } from "./swoff/invalidation-tags.${ext}";`);
|
|
67
|
-
w('const data = await fetchWithCache("/api/todos", { tags: generateTags("/api/todos") });');
|
|
68
|
-
w('await invalidateUrl("/api/todos/42"); // after mutation');
|
|
69
|
-
w("```");
|
|
70
|
-
w("");
|
|
71
|
-
}
|
|
72
|
-
if (ctx.frameworkName === "react") {
|
|
73
|
-
w("## React hook — auto-refetch on cache invalidation");
|
|
74
|
-
w("```tsx");
|
|
75
|
-
w(`import { useCachedFetch } from "./swoff/hooks/useCachedFetch.${ext}x";`);
|
|
76
|
-
w('const { data, error, loading, refetch } = useCachedFetch("/api/todos");');
|
|
77
|
-
w("```");
|
|
78
|
-
w("");
|
|
79
|
-
}
|
|
80
|
-
w("## Build script");
|
|
81
|
-
w("The SW generator learns your build output to precache assets.");
|
|
82
|
-
w("Swoff has already added this to your `package.json`:");
|
|
83
|
-
w("```json");
|
|
84
|
-
w('"build": "<your-build> && node swoff/sw/generator.js"');
|
|
85
|
-
w("```");
|
|
18
|
+
w("Or run `swoff info <feature>` for targeted help.");
|
|
86
19
|
writeFile(ctx, "README.md", lines.join("\n"));
|
|
87
20
|
}
|
|
88
21
|
//# sourceMappingURL=quick-readme.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quick-readme.js","sourceRoot":"","sources":["../../../../src/lib/generators/file-generators/quick-readme.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAoB,SAAS,EAAE,MAAM,cAAc,CAAC;AAE3D,MAAM,UAAU,cAAc,CAAC,GAAqB;IAClD,MAAM,
|
|
1
|
+
{"version":3,"file":"quick-readme.js","sourceRoot":"","sources":["../../../../src/lib/generators/file-generators/quick-readme.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAoB,SAAS,EAAE,MAAM,cAAc,CAAC;AAE3D,MAAM,UAAU,cAAc,CAAC,GAAqB;IAClD,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,MAAM,CAAC,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAEvC,CAAC,CAAC,2BAA2B,CAAC,CAAC;IAC/B,CAAC,CAAC,EAAE,CAAC,CAAC;IACN,CAAC,CAAC,sCAAsC,CAAC,CAAC;IAC1C,CAAC,CAAC,EAAE,CAAC,CAAC;IACN,CAAC,CAAC,oEAAoE,CAAC,CAAC;IACxE,CAAC,CAAC,uEAAuE,CAAC,CAAC;IAC3E,CAAC,CAAC,wDAAwD,CAAC,CAAC;IAC5D,CAAC,CAAC,4DAA4D,CAAC,CAAC;IAChE,CAAC,CAAC,qEAAqE,CAAC,CAAC;IACzE,CAAC,CAAC,EAAE,CAAC,CAAC;IACN,CAAC,CAAC,kDAAkD,CAAC,CAAC;IAEtD,SAAS,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates server-push.ts/js — client-side connection manager for SSE/WebSocket.
|
|
3
|
+
* The SW connects to the push endpoint directly in modern browsers.
|
|
4
|
+
* This client-side helper provides a fallback and status events for the UI.
|
|
5
|
+
*/
|
|
6
|
+
import { writeFile } from "./context.js";
|
|
7
|
+
export function generateServerPush(ctx) {
|
|
8
|
+
const ext = ctx.ext;
|
|
9
|
+
const ts = ext === "ts";
|
|
10
|
+
const T = (type) => (ts ? `: ${type}` : "");
|
|
11
|
+
const R = (type) => (ts ? `: ${type}` : " ");
|
|
12
|
+
const sp = ctx.config.features.serverPush;
|
|
13
|
+
const endpoint = sp.endpoint;
|
|
14
|
+
const reconnectDelayMs = sp.reconnectDelayMs;
|
|
15
|
+
const invalidate = `
|
|
16
|
+
// Forward to SW for cache invalidation
|
|
17
|
+
if (navigator.serviceWorker.controller) {
|
|
18
|
+
for (const tag of tags) {
|
|
19
|
+
navigator.serviceWorker.controller.postMessage({ type: "INVALIDATE_TAG", tag });
|
|
20
|
+
}
|
|
21
|
+
}`;
|
|
22
|
+
const sseConnect = `
|
|
23
|
+
return new Promise((resolve) => {
|
|
24
|
+
fetch("${endpoint}", {
|
|
25
|
+
headers: { Accept: "text/event-stream" },
|
|
26
|
+
signal: options.signal,
|
|
27
|
+
}).then(async (response) => {
|
|
28
|
+
if (!response.ok || !response.body) { resolve(); return; }
|
|
29
|
+
notifyStatus(true);
|
|
30
|
+
const reader = response.body.getReader();
|
|
31
|
+
const decoder = new TextDecoder();
|
|
32
|
+
let buffer = "";
|
|
33
|
+
let eventType = "";
|
|
34
|
+
let dataStr = "";
|
|
35
|
+
|
|
36
|
+
while (true) {
|
|
37
|
+
const { done, value } = await reader.read();
|
|
38
|
+
if (done) break;
|
|
39
|
+
buffer += decoder.decode(value, { stream: true });
|
|
40
|
+
const lines = buffer.split("\\n");
|
|
41
|
+
buffer = lines.pop() || "";
|
|
42
|
+
for (const line of lines) {
|
|
43
|
+
if (line.startsWith("event: ")) eventType = line.slice(7).trim();
|
|
44
|
+
else if (line.startsWith("data: ")) dataStr = line.slice(6);
|
|
45
|
+
else if (line === "" && eventType === "invalidate" && dataStr) {
|
|
46
|
+
try {
|
|
47
|
+
const p = JSON.parse(dataStr); if (p.tags) handleInvalidation(p.tags);
|
|
48
|
+
} catch {
|
|
49
|
+
// Handle invalidation data
|
|
50
|
+
}
|
|
51
|
+
eventType = ""; dataStr = "";
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}).catch(() => {}).finally(() => {
|
|
56
|
+
notifyStatus(false);
|
|
57
|
+
resolve();
|
|
58
|
+
});
|
|
59
|
+
});`;
|
|
60
|
+
const wsConnect = `
|
|
61
|
+
return new Promise((resolve) => {
|
|
62
|
+
try {
|
|
63
|
+
const ws = new WebSocket("${endpoint}");
|
|
64
|
+
ws.onopen = () => notifyStatus(true);
|
|
65
|
+
ws.onmessage = (event) => {
|
|
66
|
+
try { const d = JSON.parse(event.data); if (d.type === "invalidate" && d.tags) handleInvalidation(d.tags); } catch {}
|
|
67
|
+
};
|
|
68
|
+
ws.onclose = () => { notifyStatus(false); resolve(); };
|
|
69
|
+
ws.onerror = () => { ws.close(); resolve(); };
|
|
70
|
+
if (options.signal) {
|
|
71
|
+
options.signal.addEventListener("abort", () => ws.close());
|
|
72
|
+
}
|
|
73
|
+
} catch { resolve(); }
|
|
74
|
+
});`;
|
|
75
|
+
const code = `/**
|
|
76
|
+
* Swoff Server Push Events
|
|
77
|
+
*
|
|
78
|
+
* The service worker connects to ${endpoint} and invalidates cache tags
|
|
79
|
+
* when the server sends "invalidate" events — no polling needed.
|
|
80
|
+
* This client-side helper provides status tracking and a manual start/stop API.
|
|
81
|
+
*
|
|
82
|
+
* Usage:
|
|
83
|
+
* import { startPushEvents, stopPushEvents, isPushConnected } from "./server-push.${ext}";
|
|
84
|
+
* startPushEvents();
|
|
85
|
+
*
|
|
86
|
+
* Server sends:
|
|
87
|
+
* event: invalidate
|
|
88
|
+
* data: {"tags": ["todos", "todo:42"]}
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
type PushEventOptions= {
|
|
92
|
+
signal${T("AbortSignal")};
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
let active${T("boolean")} = false;
|
|
96
|
+
let reconnectTimer${T("ReturnType<typeof setTimeout> | null")} = null;
|
|
97
|
+
|
|
98
|
+
function handleInvalidation(tags${T("string[]")})${R("void")}{${invalidate}
|
|
99
|
+
window.dispatchEvent(new CustomEvent("cache-invalidated", { detail: { tags } }));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function notifyStatus(connected${T("boolean")})${R("void")}{
|
|
103
|
+
window.dispatchEvent(new CustomEvent("push-events-status", { detail: { connected } }));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async function connect(options${T("PushEventOptions")} = {} as PushEventOptions)${R("Promise<void>")}{
|
|
107
|
+
${sp.type === "sse" ? sseConnect : wsConnect}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Start listening for server push events. Only connects when the SW is not active — the SW is the primary connection manager. Retries on connection loss with exponential backoff. */
|
|
111
|
+
export async function startPushEvents(){
|
|
112
|
+
if (active) return;
|
|
113
|
+
|
|
114
|
+
// If SW is already controlling the page, skip client-side connection — the SW handles push events.
|
|
115
|
+
if (navigator.serviceWorker.controller) return;
|
|
116
|
+
|
|
117
|
+
// Listen for SW activation — if SW takes over, disconnect the client fallback.
|
|
118
|
+
const onControllerChange = () => { stopPushEvents(); };
|
|
119
|
+
navigator.serviceWorker.addEventListener("controllerchange", onControllerChange);
|
|
120
|
+
|
|
121
|
+
active = true;
|
|
122
|
+
let delay = ${reconnectDelayMs};
|
|
123
|
+
while (active) {
|
|
124
|
+
await connect();
|
|
125
|
+
if (!active) break;
|
|
126
|
+
await new Promise((r) => { reconnectTimer = setTimeout(r, delay); });
|
|
127
|
+
delay = Math.min(delay * 1.5, 30000); // cap at 30s
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
navigator.serviceWorker.removeEventListener("controllerchange", onControllerChange);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Stop listening for push events. */
|
|
134
|
+
export function stopPushEvents(){
|
|
135
|
+
active = false;
|
|
136
|
+
if (reconnectTimer) { clearTimeout(reconnectTimer); reconnectTimer = null; }
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Check if the push connection is currently established. */
|
|
140
|
+
export function isPushConnected(){
|
|
141
|
+
return active;
|
|
142
|
+
}
|
|
143
|
+
`;
|
|
144
|
+
writeFile(ctx, `server-push.${ext}`, code);
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=server-push.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-push.js","sourceRoot":"","sources":["../../../../src/lib/generators/file-generators/server-push.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAoB,SAAS,EAAE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AAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS;;;;;;;;;;;;;;;gBAe9B,gBAAgB;;;;;;;;;;;;;;;;;;;;;CAqB/B,CAAC;IAEA,SAAS,CAAC,GAAG,EAAE,eAAe,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generates sw-generator.js - build script that processes sw-template.js.
|
|
3
|
-
*/
|
|
4
1
|
import { writeFile } from "./context.js";
|
|
5
2
|
export function generateSwGeneratorBuild(ctx) {
|
|
6
3
|
const code = `#!/usr/bin/env node
|
|
@@ -40,11 +37,13 @@ const config = JSON.parse(readFileSync(configPath, 'utf8'));
|
|
|
40
37
|
const template = readFileSync(templatePath, 'utf8');
|
|
41
38
|
|
|
42
39
|
const swConfig = config.features?.serviceWorker || {};
|
|
43
|
-
const
|
|
44
|
-
const versionEnabled =
|
|
45
|
-
const version =
|
|
46
|
-
?
|
|
47
|
-
:
|
|
40
|
+
const versionField = swConfig.version;
|
|
41
|
+
const versionEnabled = versionField !== false && versionField !== "hash";
|
|
42
|
+
const version = versionField === "package"
|
|
43
|
+
? (pkg.version || '1.0.0')
|
|
44
|
+
: versionField && versionField !== "hash"
|
|
45
|
+
? versionField
|
|
46
|
+
: (pkg.version || '1.0.0');
|
|
48
47
|
const outputDir = config.build?.outputDir || 'dist';
|
|
49
48
|
const swFilename = config.build?.swFilename || 'sw';
|
|
50
49
|
|
|
@@ -98,7 +97,7 @@ if (!versionEnabled) {
|
|
|
98
97
|
writeFileSync(join(outDir, swFile), sw);
|
|
99
98
|
writeFileSync(join(outDir, 'version.json'), JSON.stringify({
|
|
100
99
|
version,
|
|
101
|
-
minSupportedVersion:
|
|
100
|
+
minSupportedVersion: swConfig.minSupportedVersion || '0.0.0',
|
|
102
101
|
generatedAt: new Date().toISOString(),
|
|
103
102
|
}, null, 2));
|
|
104
103
|
console.log(\`Service worker built: \${outputDir}/\${swFile}\`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sw-generator-build.js","sourceRoot":"","sources":["../../../../src/lib/generators/file-generators/sw-generator-build.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"sw-generator-build.js","sourceRoot":"","sources":["../../../../src/lib/generators/file-generators/sw-generator-build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,SAAS,EAAE,MAAM,cAAc,CAAC;AAE3D,MAAM,UAAU,wBAAwB,CAAC,GAAqB;IAC5D,MAAM,IAAI,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsGd,CAAC;IAEA,SAAS,CAAC,GAAG,EAAE,iBAAiB,EAAE,IAAI,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -5,7 +5,8 @@ import { writeFile } from "./context.js";
|
|
|
5
5
|
export function generateSwInjector(ctx) {
|
|
6
6
|
const autoUpdate = ctx.config.features.serviceWorker.autoUpdate;
|
|
7
7
|
const autoActivate = ctx.config.features.serviceWorker.autoActivate;
|
|
8
|
-
const
|
|
8
|
+
const v = ctx.config.features.serviceWorker.version;
|
|
9
|
+
const versionEnabled = v !== false && v !== "hash";
|
|
9
10
|
const ext = ctx.ext;
|
|
10
11
|
const ts = ext === "ts";
|
|
11
12
|
const T = (type) => (ts ? `: ${type}` : "");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sw-injector.js","sourceRoot":"","sources":["../../../../src/lib/generators/file-generators/sw-injector.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAoB,SAAS,EAAE,MAAM,cAAc,CAAC;AAE3D,MAAM,UAAU,kBAAkB,CAAC,GAAqB;IACtD,MAAM,UAAU,GAAG,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC;IA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e,CAAC;;;;;;;;;;gDAUN,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,oCAAoC,CAAC;;;;;;;;;;;;;2CAa3D,CAAC,CAAC,eAAe,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uDAoFN,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,eAAe,CAAC;;;;;;;;;;;;;;;;qCAgBnD,CAAC,CAAC,eAAe,CAAC;;;;;;CAMtD,CAAC;IAEA,MAAM,UAAU,GAAG;;;;;8DAKyC,GAAG;;;;;;;;;;;;oCAY7B,CAAC,CAAC,eAAe,CAAC;;;;;;;;;;;2CAWX,CAAC,CAAC,eAAe,CAAC;;;;;;;;;;;;;;;;;CAiB5D,CAAC;IAEA,MAAM,IAAI,GAAG,cAAc,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,UAAU,CAAC;IAEzD,SAAS,CAAC,GAAG,EAAE,eAAe,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -38,6 +38,7 @@ declare global {
|
|
|
38
38
|
"mutation-sync-complete": CustomEvent<{ succeeded: number; failed: number }>;
|
|
39
39
|
"mutation-queue-changed": CustomEvent;
|
|
40
40
|
"cache-invalidated": CustomEvent<{ tags?: string[] }>;
|
|
41
|
+
"mutation-state-changed": CustomEvent<{ id: string; status: string; error?: Error; data?: unknown }>;
|
|
41
42
|
"background-sync-complete": CustomEvent<{ succeeded: number; failed: number }>;
|
|
42
43
|
"push-subscription-changed": CustomEvent<{ subscribed: boolean }>;
|
|
43
44
|
"push-permission-changed": CustomEvent<{ permission: NotificationPermission }>;
|
|
@@ -68,7 +69,29 @@ declare global {
|
|
|
68
69
|
export interface FetchWithCacheOptions extends RequestInit {
|
|
69
70
|
strategy?: "read" | "mutation";
|
|
70
71
|
tags?: string[];
|
|
71
|
-
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export type MutationStatus = "idle" | "pending" | "success" | "error";
|
|
75
|
+
|
|
76
|
+
export interface MutationState {
|
|
77
|
+
id: string;
|
|
78
|
+
status: MutationStatus;
|
|
79
|
+
error: Error | null;
|
|
80
|
+
data: unknown;
|
|
81
|
+
timestamp: number;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface GqlOptions {
|
|
85
|
+
variables?: Record<string, unknown>;
|
|
86
|
+
tags?: string[];
|
|
87
|
+
auth?: boolean;
|
|
88
|
+
queueOffline?: boolean;
|
|
89
|
+
invalidate?: 'auto' | string[] | false;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface GqlResult${"<T>"} {
|
|
93
|
+
data: T;
|
|
94
|
+
fromCache: boolean;
|
|
72
95
|
}
|
|
73
96
|
|
|
74
97
|
export interface MutationQueueItem {
|
|
@@ -80,12 +103,14 @@ export interface MutationQueueItem {
|
|
|
80
103
|
headers: Record<string, string>;
|
|
81
104
|
timestamp: number;
|
|
82
105
|
retryCount: number;
|
|
106
|
+
nextRetryAt?: number;
|
|
83
107
|
tags: string[];
|
|
84
108
|
}
|
|
85
109
|
|
|
86
110
|
export interface MutationQueueResult {
|
|
87
111
|
succeeded: number;
|
|
88
112
|
failed: number;
|
|
113
|
+
total?: number;
|
|
89
114
|
}
|
|
90
115
|
|
|
91
116
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-definitions.js","sourceRoot":"","sources":["../../../../src/lib/generators/file-generators/type-definitions.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAoB,SAAS,EAAE,MAAM,cAAc,CAAC;AAE3D,MAAM,UAAU,uBAAuB,CAAC,GAAqB;IAC3D,IAAI,GAAG,CAAC,GAAG,KAAK,IAAI;QAAE,OAAO;IAE7B,MAAM,IAAI,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"type-definitions.js","sourceRoot":"","sources":["../../../../src/lib/generators/file-generators/type-definitions.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAoB,SAAS,EAAE,MAAM,cAAc,CAAC;AAE3D,MAAM,UAAU,uBAAuB,CAAC,GAAqB;IAC3D,IAAI,GAAG,CAAC,GAAG,KAAK,IAAI;QAAE,OAAO;IAE7B,MAAM,IAAI,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BAoFa,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;CAyBhC,CAAC;IAEA,SAAS,CAAC,GAAG,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Swoff Service Worker Generator
|
|
3
|
-
*
|
|
4
|
-
* Generates a service worker based on swoff.config.json configuration.
|
|
5
|
-
* Thin orchestrator - delegates to sw-sections for code generation.
|
|
6
|
-
*
|
|
7
|
-
* CLI Usage:
|
|
8
|
-
* node sw-generator.js [--project-root <path>] [--package-dir <path>] [--config-path <path>]
|
|
9
|
-
*
|
|
10
|
-
* Module Usage:
|
|
11
|
-
* import { generateSW } from './sw-generator.js';
|
|
12
|
-
* await generateSW({ projectRoot: '/path/to/project', onStatus: (msg) => {...} });
|
|
13
|
-
*/
|
|
14
1
|
import { readFileSync, writeFileSync, existsSync, mkdirSync } from "fs";
|
|
15
2
|
import { join } from "path";
|
|
16
3
|
import { fileURLToPath } from "url";
|
|
@@ -18,9 +5,11 @@ import { loadConfig } from "../config/loader.js";
|
|
|
18
5
|
import { assembleSW } from "./sw-sections/assemble-sw.js";
|
|
19
6
|
function resolveVersion(config, pkgVersion) {
|
|
20
7
|
const v = config.features.serviceWorker.version;
|
|
21
|
-
if (v
|
|
22
|
-
return
|
|
23
|
-
|
|
8
|
+
if (v === false || v === "hash")
|
|
9
|
+
return pkgVersion || "1.0.0";
|
|
10
|
+
if (v === "package")
|
|
11
|
+
return pkgVersion || "1.0.0";
|
|
12
|
+
return v;
|
|
24
13
|
}
|
|
25
14
|
export async function generateSW(options = {}) {
|
|
26
15
|
const optProjectRoot = options.projectRoot || process.cwd();
|
|
@@ -41,7 +30,8 @@ export async function generateSW(options = {}) {
|
|
|
41
30
|
status("Swoff config generation disabled. Using custom code mode.");
|
|
42
31
|
return { version: "", outputFile: "" };
|
|
43
32
|
}
|
|
44
|
-
const
|
|
33
|
+
const v = config.features.serviceWorker.version;
|
|
34
|
+
const versionEnabled = v !== false && v !== "hash";
|
|
45
35
|
const version = resolveVersion(config, pkg.version || "1.0.0");
|
|
46
36
|
const sw = assembleSW(config, version, optProjectRoot);
|
|
47
37
|
const outputDir = join(optProjectRoot, config.build.outputDir);
|
|
@@ -55,7 +45,7 @@ export async function generateSW(options = {}) {
|
|
|
55
45
|
if (versionEnabled) {
|
|
56
46
|
writeFileSync(join(outputDir, "version.json"), JSON.stringify({
|
|
57
47
|
version,
|
|
58
|
-
minSupportedVersion: config.features.serviceWorker.
|
|
48
|
+
minSupportedVersion: config.features.serviceWorker.minSupportedVersion,
|
|
59
49
|
generatedAt: new Date().toISOString(),
|
|
60
50
|
configEnabled: config.enabled,
|
|
61
51
|
configSource,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sw-generator.js","sourceRoot":"","sources":["../../../src/lib/generators/sw-generator.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"sw-generator.js","sourceRoot":"","sources":["../../../src/lib/generators/sw-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACxE,OAAO,EAAE,IAAI,EAAW,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,aA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