-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegration_test__tests__basic-usages.snap
More file actions
264 lines (219 loc) · 8.98 KB
/
integration_test__tests__basic-usages.snap
File metadata and controls
264 lines (219 loc) · 8.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
---
source: tests/integration_test.rs
expression: idempt_output
---
--- app/home/_components/heading.tsx ---
import { FC } from "react";
// whitelabel *
export const Heading: FC = () => <h1>Heading</h1>;
--- app/home/page.tsx ---
import whitelabel from "../whitelabel";
import { Heading } from "./_components/heading";
/**
* The most formal `whitelabel` marker
*/ // whitelabel: for=variant1, key=BG_COLOR
export const variant1_bgClassname: string = "bg-red-100";
/**
* If `for` is omitted, it will default to your `default_target` config
*/ // whitelabel
export const BG_COLOR: string = "bg-red-200";
/**
* The most natural `whitelabel` marker
* `as` works the same way as `key`, excepts you can omits `=`.
*/ // whitelabel for 'variant2' as 'BG_COLOR'
export const variant2_bgClassname: string = "bg-red-300";
/**
* Or
* (Not recommended, hard to read)
*/ // whitelabel for variant3 as BG_COLOR
export const variant3_bgClassname: string = "bg-red-400";
/**
* Or
*/ // whitelabel for 'variant4' as='BG_COLOR'
export const variant4_bgClassname: string = "bg-red-400";
const Homepage = () => (
<div className={`h-full w-full ${whitelabel.BG_COLOR}`}>
<whitelabel.Heading />
</div>
);
export default Homepage;
--- app/variant1.const.tsx ---
import { FC } from "react";
// whitelabel for=variant1
export const Heading: FC = () => <h1>Variant1 Heading</h1>;
--- app/whitelabel/def.generated.tsx ---
/* eslint-disable @typescript-eslint/no-require-imports */
// AUTO-GENERATED: DO NOT EDIT
import type { WhitelabelConfig } from "./whitelabel";
export class whitelabel implements WhitelabelConfig {
public get BG_COLOR(): WhitelabelConfig["BG_COLOR"] {
return require("../home/page").BG_COLOR;
}
public get Heading(): WhitelabelConfig["Heading"] {
return require("../home/_components/heading").Heading;
}
}
export default whitelabel;
--- app/whitelabel/index.ts ---
/**
* 🎨 WHITELABEL RESOLUTION ENTRY POINT
* * Unlike the `*.generated.tsx` files in this directory, this file is YOURS to edit!
* `wl-extractor` generated this as a starter template. You should customize the
* logic here to match how your application determines the current tenant/brand.
* * By default, this uses a static, build-time environment variable.
*/
import { type Variants, Whitelabel, type WhitelabelConfig } from "./whitelabel";
// --- Default Strategy: Build-time Environment Variable ---
const currentWhitelabel = (() => {
// Fallback to 'def' (or your project's default) if the env var is missing
const variant = (process.env.NEXT_PUBLIC_WHITELABEL as Variants) || "def";
return new Whitelabel()[variant];
})();
// ! The default export MUST satisfy the `WhitelabelConfig` interface.
// This ensures that wherever you `import whitelabel from '...'`, it is strictly typed.
export default currentWhitelabel satisfies WhitelabelConfig;
export { type Variants, type WhitelabelConfig };
/* * ============================================================================
* 💡 IDEAS FOR ADVANCED CUSTOM LOGIC
* ============================================================================
* * 1. React Context & Hooks (Client-Side Dynamic)
* ----------------------------------------------------------------------------
* If your app switches brands dynamically in the browser (e.g., a dropdown),
* export a hook to access the current config:
* * export const useWhitelabel = (): WhitelabelConfig => {
* // e.g., Read from Redux, Zustand, or React Context
* const currentTenant = useTenantStore((state) => state.tenant);
* return new Whitelabel()[currentTenant as Variants];
* };
* * * 2. Next.js App Router / SSR (Per-Request Whitelabeling)
* ----------------------------------------------------------------------------
* If you are hosting multiple tenants on a single Node server, `process.env`
* won't work. Instead, resolve the brand based on the request headers or URL:
* * import { headers } from 'next/headers';
* * export const getServerWhitelabel = (): WhitelabelConfig => {
* const host = headers().get('host');
* const variant = host?.includes('brand-a') ? 'brandA' : 'def';
* return new Whitelabel()[variant as Variants];
* };
* ============================================================================
*/
--- app/whitelabel/variant1.generated.tsx ---
/* eslint-disable @typescript-eslint/no-require-imports */
// AUTO-GENERATED: DO NOT EDIT
import type { WhitelabelConfig } from "./whitelabel";
export class whitelabel implements WhitelabelConfig {
public get BG_COLOR(): WhitelabelConfig["BG_COLOR"] {
return require("../home/page").variant1_bgClassname;
}
public get Heading(): WhitelabelConfig["Heading"] {
return require("../variant1.const").Heading;
}
}
export default whitelabel;
--- app/whitelabel/variant2.generated.tsx ---
/* eslint-disable @typescript-eslint/no-require-imports */
// AUTO-GENERATED: DO NOT EDIT
import type { WhitelabelConfig } from "./whitelabel";
export class whitelabel implements WhitelabelConfig {
public get BG_COLOR(): WhitelabelConfig["BG_COLOR"] {
return require("../home/page").variant2_bgClassname;
}
public get Heading(): WhitelabelConfig["Heading"] {
return require("../home/_components/heading").Heading;
}
}
export default whitelabel;
--- app/whitelabel/variant3.generated.tsx ---
/* eslint-disable @typescript-eslint/no-require-imports */
// AUTO-GENERATED: DO NOT EDIT
import type { WhitelabelConfig } from "./whitelabel";
export class whitelabel implements WhitelabelConfig {
public get BG_COLOR(): WhitelabelConfig["BG_COLOR"] {
return require("../home/page").variant3_bgClassname;
}
public get Heading(): WhitelabelConfig["Heading"] {
return require("../home/_components/heading").Heading;
}
}
export default whitelabel;
--- app/whitelabel/variant4.generated.tsx ---
/* eslint-disable @typescript-eslint/no-require-imports */
// AUTO-GENERATED: DO NOT EDIT
import type { WhitelabelConfig } from "./whitelabel";
export class whitelabel implements WhitelabelConfig {
public get BG_COLOR(): WhitelabelConfig["BG_COLOR"] {
return require("../home/page").variant4_bgClassname;
}
public get Heading(): WhitelabelConfig["Heading"] {
return require("../home/_components/heading").Heading;
}
}
export default whitelabel;
--- app/whitelabel/whitelabel.ts ---
/* eslint-disable @typescript-eslint/no-require-imports */
// AUTO-GENERATED: DO NOT EDIT
import type { BG_COLOR as def_f5ddee806ca95ade } from "../home/page";
import type { variant1_bgClassname as variant1_93de170be0ce975c } from "../home/page";
import type { variant2_bgClassname as variant2_d84b71ffdf9f5fcd } from "../home/page";
import type { variant3_bgClassname as variant3_fa79c0168dc71b7 } from "../home/page";
import type { variant4_bgClassname as variant4_ff373c3ac713a727 } from "../home/page";
import type { Heading as def_cce35f3890d1b666 } from "../home/_components/heading";
import type { Heading as variant1_35f9b289efdadf9f } from "../variant1.const";
export interface WhitelabelConfig {
/**
* ### 🏷️ Available for: {@link def_f5ddee806ca95ade | `def`} | {@link variant1_93de170be0ce975c | `variant1`} | {@link variant2_d84b71ffdf9f5fcd | `variant2`} | {@link variant3_fa79c0168dc71b7 | `variant3`} | {@link variant4_ff373c3ac713a727 | `variant4`}
* @copyright **def**
* @default
* ```tsx
* "bg-red-200"
* ```
*/
BG_COLOR: typeof def_f5ddee806ca95ade | typeof variant1_93de170be0ce975c | typeof variant2_d84b71ffdf9f5fcd | typeof variant3_fa79c0168dc71b7 | typeof variant4_ff373c3ac713a727;
/**
* ### 🏷️ Available for: {@link def_cce35f3890d1b666 | `def`} | {@link variant1_35f9b289efdadf9f | `variant1`} | `variant2` = {@link def_cce35f3890d1b666 | def} | `variant3` = {@link def_cce35f3890d1b666 | def} | `variant4` = {@link def_cce35f3890d1b666 | def}
* @copyright **def**
* @default
* ```tsx
* () => <h1>Heading</h1>
* ```
*/
Heading: typeof def_cce35f3890d1b666 | typeof variant1_35f9b289efdadf9f;
}
export type Variants = "def" | "variant1" | "variant2" | "variant3" | "variant4";
export class Whitelabel implements Record<Variants, WhitelabelConfig> {
public get def(): WhitelabelConfig {
const VariantConfig = require("./def.generated").default;
return new VariantConfig();
}
public get variant1(): WhitelabelConfig {
const VariantConfig = require("./variant1.generated").default;
return new VariantConfig();
}
public get variant2(): WhitelabelConfig {
const VariantConfig = require("./variant2.generated").default;
return new VariantConfig();
}
public get variant3(): WhitelabelConfig {
const VariantConfig = require("./variant3.generated").default;
return new VariantConfig();
}
public get variant4(): WhitelabelConfig {
const VariantConfig = require("./variant4.generated").default;
return new VariantConfig();
}
}
--- tsconfig.json ---
{
"compilerOptions": {
"jsx": "react-jsx",
"paths": {}
}
}
--- whitelabel.config.json ---
{
"src": "app/",
"patterns": ["**/*.tsx", "**/*.ts"],
"output_dir": "whitelabel",
"default_target": "def",
"tsconfig": "tsconfig.json"
}