create-lupine 1.0.27 → 1.0.29
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/index.js +6 -7
- package/package.json +2 -2
- package/templates/common/AI_CONTEXT.md +142 -60
- package/templates/lupine-template-cv-starter/lupine.json +10 -8
- package/templates/lupine-template-doc-starter/lupine.json +10 -8
- package/templates/lupine-template-hello-world/lupine.json +5 -5
- package/templates/lupine-template-hello-world/web/src/styles/global.css +57 -70
- package/templates/lupine-template-responsive-starter/lupine.json +7 -7
- package/templates/lupine-template-responsive-starter/web/src/components/side-menu-content.tsx +7 -3
- package/templates/lupine-template-responsive-starter/web/src/styles/global.css +57 -70
- package/templates/common/dev/dev-watch.js +0 -371
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import path from 'node:path';
|
|
@@ -280,7 +280,9 @@ async function init() {
|
|
|
280
280
|
version: '0.0.0',
|
|
281
281
|
private: true,
|
|
282
282
|
workspaces: ['apps/*', 'apps/*/*', 'packages/*'],
|
|
283
|
+
'//desktop': 'If you want to build desktop applications, please run `npm run add-electron` first.',
|
|
283
284
|
scripts: {
|
|
285
|
+
'add-electron': 'npm install -D electron@^35.2.0 electron-builder@^26.0.12',
|
|
284
286
|
'app1:build-win': `electron-builder --win --config apps/${appName}/electron/builder.json`,
|
|
285
287
|
'app1:build-linux': `electron-builder --linux --config apps/${appName}/electron/builder.json`,
|
|
286
288
|
'app1:build-mac': `export CSC_IDENTITY_AUTO_DISCOVERY=true && electron-builder --mac --x64 --config apps/${appName}/electron/builder.json`,
|
|
@@ -291,9 +293,9 @@ async function init() {
|
|
|
291
293
|
'app1:sync': `npm run sync --workspace=${appName}-web`,
|
|
292
294
|
'app1:open-ios': `npm run open-ios --workspace=${appName}-web`,
|
|
293
295
|
'app1:open-android': `npm run open-android --workspace=${appName}-web`,
|
|
294
|
-
dev: '
|
|
295
|
-
build: '
|
|
296
|
-
'build-mobile': '
|
|
296
|
+
dev: 'lupine-build --env=.env.development --dev=1 --cmd=start-dev',
|
|
297
|
+
build: 'lupine-build --env=.env.production --dev=0 --obfuscate=0',
|
|
298
|
+
'build-mobile': 'lupine-build --env=.env.mobile --dev=0 --mobile=1',
|
|
297
299
|
'start-dev': 'node dist/server_root/server/server-loader.js --env=.env.development',
|
|
298
300
|
'start-production': 'node dist/server_root/server/server-loader.js --env=.env.production',
|
|
299
301
|
format: 'prettier --write "**/*.{js,json,css,scss,md,html,yaml,ts,jsx,tsx}"',
|
|
@@ -302,9 +304,6 @@ async function init() {
|
|
|
302
304
|
'lupine.api': 'file:packages/lupine.api',
|
|
303
305
|
},
|
|
304
306
|
devDependencies: {
|
|
305
|
-
esbuild: '^0.24.2',
|
|
306
|
-
electron: '^35.2.0',
|
|
307
|
-
'electron-builder': '^26.0.12',
|
|
308
307
|
typescript: '^5.7.2',
|
|
309
308
|
'@types/node': '^22.10.5',
|
|
310
309
|
prettier: '^2.7.1',
|
package/package.json
CHANGED
|
@@ -191,91 +191,174 @@ export const MyComponent = () => {
|
|
|
191
191
|
|
|
192
192
|
## 4. CSS Placement Strategies & Sharing Scopes
|
|
193
193
|
|
|
194
|
-
Lupine.js
|
|
194
|
+
Lupine.js handles CSS scoping by generating unique IDs and replacing the `&` symbol in class names. Depending on where your components live, you have three strategies for sharing this CSS scope.
|
|
195
195
|
|
|
196
|
-
###
|
|
196
|
+
### 4.1 Sharing CSS inside a method (Component Level)
|
|
197
197
|
|
|
198
|
-
**Best for**:
|
|
198
|
+
**Best for**: Complex components or pages where you define a single `const css: CssProps` and share it across sub-components rendered in the same function.
|
|
199
199
|
|
|
200
|
-
When you
|
|
200
|
+
When you assign `css={css}` to the root element, a unique ID is generated (e.g., `l01`).
|
|
201
201
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
### Strategy B: `bindGlobalStyle` (Reusable Components)
|
|
206
|
-
|
|
207
|
-
**Best for**: Reusable UI components (Buttons, Toggles, List Items, Modals) that will be rendered multiple times.
|
|
208
|
-
|
|
209
|
-
`bindGlobalStyle`, combined with `getGlobalStylesId`, places the `<style>` block in the `<head>` of the document **exactly once**. All instances of the component share the same CSS class names, but those names are still guaranteed to be collision-free!
|
|
210
|
-
|
|
211
|
-
**How it works seamlessly with `&`**:
|
|
212
|
-
|
|
213
|
-
1. Generate an ID based on the `CssProps` content: `const globalCssId = getGlobalStylesId(css);`. (Call this _inside_ the component!)
|
|
214
|
-
2. Bind the style block globally once: `bindGlobalStyle(globalCssId, css);`
|
|
215
|
-
3. Assign this ID to the component's `ref` to link the scope: `const ref: RefProps = { globalCssId };` / `<div ref={ref}>`
|
|
216
|
-
4. Use `class="&-item"` normally. Lupine replaces `&` with the identical `globalCssId` across all instances.
|
|
217
|
-
|
|
218
|
-
> [!WARNING]
|
|
219
|
-
> Because `getGlobalStylesId` relies on `getRequestContext()` data to correctly attach and track styles (especially across SSR and interactive client renders), `getGlobalStylesId` and `bindGlobalStyle` **MUST** be called inside the component function scope. Calling them at the file/module level will result in runtime errors like: `Uncaught Error: Request context is not initialized`.
|
|
220
|
-
|
|
221
|
-
### ⚠️ IMPORTANT: The "Static `CssProps`" Rule
|
|
222
|
-
|
|
223
|
-
Because `bindGlobalStyle` injects your `<style>` tags into the `<head>` globally, your `CssProps` definition **MUST** be entirely static.
|
|
224
|
-
|
|
225
|
-
**ANTI-PATTERN:** Putting variables (like `isVertical`, `size`, `color`) directly inside the `CssProps` object structure. Every time the component re-renders with a different prop, it will generate conflicting CSS IDs and the latter will overwrite the former's styles, corrupting the layout. Define one immutable `const css: CssProps = {...}` and handle visual variations by appending standard class names to your root element (`class={isVertical ? '&-vertical' : '&-horizontal'}`) and map those variations inside your static `CssProps`.
|
|
226
|
-
|
|
227
|
-
### 🔗 Sharing the same CSS scope (`globalCssId`) among Separated DOMs
|
|
228
|
-
|
|
229
|
-
If your component divides its logic so that some internal floating DOM elements are rendered dynamically later (e.g. through a function passed to `HtmlVar`) _separated_ from the root return statement, the inner DOM will automatically generate a **new, mismatched** CSS ID if not linked. Its internal `class="&-item"` references will break and styles will fail to apply.
|
|
230
|
-
|
|
231
|
-
To force separated local DOM partitions to share the exact same `&` CSS Scope as their parent page, explicitly share a globally unique CSS ID using `globalStyleUniqueId()`:
|
|
202
|
+
1. **Automatic Inheritance**: The top node's CSS ID will be automatically inherited by all descendant nodes in most cases. You **do not** need to pass it manually.
|
|
203
|
+
2. **HtmlVar Support**: Detached DOMs rendered via `HtmlVar` now automatically inherit the CSS ID of the element they are mounted into!
|
|
204
|
+
3. **Explicit Linking (`referToCssId`)**: The **ONLY** time the inheritance chain is broken is when a sub-component defines its OWN `css` property (which creates a new CSS scope). If you want descendants of that sub-component to still use the top parent's CSS ID instead of the new one, you must explicitly pass `referToCssId`.
|
|
232
205
|
|
|
233
206
|
```tsx
|
|
234
|
-
import {
|
|
207
|
+
import { domUniqueId, HtmlVar, RefProps, CssProps } from 'lupine.components';
|
|
208
|
+
|
|
209
|
+
export const TestCssShareInside = () => {
|
|
210
|
+
const cssInner: CssProps = {
|
|
211
|
+
// Top-level rules apply to the root component
|
|
212
|
+
display: 'flex',
|
|
213
|
+
'.&-content': { color: 'red' },
|
|
214
|
+
'.&-sub-title': { fontWeight: 'bold' },
|
|
215
|
+
'.&-list-item': { color: 'blue' }
|
|
216
|
+
};
|
|
235
217
|
|
|
236
|
-
|
|
237
|
-
// 1. Generate a manual ID for the container scope beforehand
|
|
238
|
-
const cssId = globalStyleUniqueId();
|
|
218
|
+
const ref: RefProps = { id: domUniqueId() };
|
|
239
219
|
|
|
220
|
+
// Example of a detached DOM using HtmlVar.
|
|
221
|
+
// It automatically inherits the CSS ID when mounted inside the component!
|
|
240
222
|
const listDom = new HtmlVar('');
|
|
241
|
-
|
|
242
223
|
const renderList = () => {
|
|
243
|
-
// 2. Explicitly bind the inner detached DOM to the parent's globalCssId
|
|
244
224
|
listDom.value = (
|
|
245
|
-
<div
|
|
246
|
-
<div class='&-
|
|
225
|
+
<div class='&-list'>
|
|
226
|
+
<div class='&-list-item'>HtmlVar List Item</div>
|
|
247
227
|
</div>
|
|
248
228
|
);
|
|
249
229
|
};
|
|
250
230
|
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
|
|
231
|
+
const SubContent1 = () => {
|
|
232
|
+
const ref2: RefProps = { onLoad: async () => {} };
|
|
233
|
+
// This sub-component only has a ref, so it naturally inherits the parent's css ID!
|
|
234
|
+
return <div ref={ref2} class='&-sub-top'>Sub component without css.</div>;
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
const SubContent2 = (props: { children: VNode<any> }) => {
|
|
238
|
+
// ⚠️ This sub-component has its own `css`, which would break inheritance!
|
|
239
|
+
const css2: CssProps = { color: 'blue' };
|
|
240
|
+
const ref2: RefProps = {
|
|
241
|
+
// So we MUST explicitly link it using referToCssId if we still want parent's css id.
|
|
242
|
+
referToCssId: ref.id,
|
|
243
|
+
onLoad: async () => renderList()
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
return (
|
|
247
|
+
<div ref={ref2} css={css2} class='&-sub-top'>
|
|
248
|
+
<div class='&-sub-title'>Sub component with its own css.</div>
|
|
249
|
+
{listDom.node}
|
|
250
|
+
{props.children}
|
|
251
|
+
</div>
|
|
252
|
+
);
|
|
254
253
|
};
|
|
255
|
-
const css: CssProps = { '.&-bundle-name': { color: 'red' } };
|
|
256
254
|
|
|
257
255
|
return (
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
{
|
|
256
|
+
// 1. Assign css to the top node.
|
|
257
|
+
<div ref={ref} css={cssInner}>
|
|
258
|
+
{/* 2. Normal elements automatically inherit the CSS ID */}
|
|
259
|
+
<div class='&-content'>Content</div>
|
|
260
|
+
|
|
261
|
+
{/* 3. SubContent1 automatically inherits */}
|
|
262
|
+
<SubContent1 />
|
|
263
|
+
|
|
264
|
+
{/* 4. SubContent2 explicitly overrides inheritance internally */}
|
|
265
|
+
<SubContent2>
|
|
266
|
+
<div class='&-sub'>Passed as parameter</div>
|
|
267
|
+
</SubContent2>
|
|
268
|
+
</div>
|
|
269
|
+
);
|
|
270
|
+
};
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### 4.2 Sharing CSS between components (Module Level)
|
|
274
|
+
|
|
275
|
+
**Best for**: Reusable UI components (Buttons, Modals, List Items) that are rendered multiple times across the application, or when sharing a common style block between a few specific components.
|
|
276
|
+
|
|
277
|
+
If you render 100 items using `css={}`, it injects 100 identical `<style>` blocks. To avoid this bloat, use `bindGlobalStyle` to inject the `<style>` block exactly once into the `<head>`, and share its ID using `referToCssId`.
|
|
278
|
+
|
|
279
|
+
**How to share:**
|
|
280
|
+
1. Define the CSS outside or inside of the component method.
|
|
281
|
+
2. Inside the component, get the ID and bind it globally using `bindGlobalStyle()`.
|
|
282
|
+
3. Assign `referToCssId` to the root element's `ref`, **and** add the `globalCssId` to the tag's `class` attribute.
|
|
283
|
+
```tsx
|
|
284
|
+
// 1. Define shared CSS
|
|
285
|
+
const cssShared: CssProps = {
|
|
286
|
+
display: 'flex',
|
|
287
|
+
'.&-content': { color: 'red' },
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
export const TestGlobalCss = () => {
|
|
291
|
+
// 2. Get the unique ID and bind it globally (only happens once)
|
|
292
|
+
// By default, noTopClassName is false, meaning the globalCssId will be prefixed to top level selectors (e.g., '.g00 .g00-content').
|
|
293
|
+
const globalCssId = getGlobalStylesId(cssShared);
|
|
294
|
+
bindGlobalStyle(globalCssId, cssShared);
|
|
295
|
+
|
|
296
|
+
return (
|
|
297
|
+
// 3. Assign referToCssId AND manually add the globalCssId as a class name!
|
|
298
|
+
// Since bindGlobalStyle added `.g00` to the selectors, we MUST add `g00` to the top tag.
|
|
299
|
+
<div ref={{ referToCssId: globalCssId }} class={globalCssId}>
|
|
300
|
+
{/* & is automatically replaced by globalCssId */}
|
|
301
|
+
<div class='&-content'>Share CSS cross components</div>
|
|
261
302
|
</div>
|
|
262
303
|
);
|
|
263
304
|
};
|
|
264
305
|
```
|
|
265
306
|
|
|
266
|
-
###
|
|
307
|
+
### 4.3 The `noTopClassName` Parameter
|
|
308
|
+
|
|
309
|
+
When using `bindGlobalStyle` or `bindAppGlobalStyle`, the `noTopClassName` parameter (4th argument) dictates how top-level CSS selectors are compiled.
|
|
267
310
|
|
|
268
|
-
|
|
311
|
+
- **`noTopClassName = false` (Default)**:
|
|
312
|
+
`bindGlobalStyle(globalCssId, cssShared)` will prepend the ID to all top-level selectors.
|
|
313
|
+
If `cssShared` is `{ '.selector-1': {} }` and `globalCssId` is `g00`, it compiles to:
|
|
314
|
+
`'.g00 .selector-1' { ... }`
|
|
315
|
+
This is why you **must** add `class={globalCssId}` to the top tag. In this mode, `cssShared` can also contain styles applied directly to the top tag (e.g., `display: 'flex'`).
|
|
269
316
|
|
|
270
|
-
|
|
317
|
+
- **`noTopClassName = true`**:
|
|
318
|
+
`bindGlobalStyle(globalCssId, cssShared, false, true)` will NOT prepend the ID.
|
|
319
|
+
It compiles to:
|
|
320
|
+
`'.selector-1' { ... }`
|
|
321
|
+
In this mode, you **cannot** define top-level styles directly on the root component without a selector, and you **do not** need to add `globalCssId` to the top tag's class name.
|
|
271
322
|
|
|
272
|
-
|
|
323
|
+
> [!WARNING]
|
|
324
|
+
> Because `bindGlobalStyle` injects your `<style>` tags into the `<head>` globally, your `CssProps` definition **MUST** be entirely static. Do not put variables (like `size` or `color`) directly inside the `CssProps` object structure.
|
|
273
325
|
|
|
274
|
-
|
|
326
|
+
### 4.4 Sharing CSS at application level (Global Scope)
|
|
275
327
|
|
|
276
|
-
|
|
328
|
+
**Best for**: True global styles like general utility classes, typography, or theme-wide resets.
|
|
277
329
|
|
|
278
|
-
|
|
330
|
+
In this case, you define an application-level CSS block and add it to the header when the app initializes.
|
|
331
|
+
|
|
332
|
+
- You **cannot** use the `&` ampersand to represent a dynamic unique ID prefix (like `&-content`). However, you **can** still use `&` in nested structures to refer to the parent selector (e.g., `&.title` compiles to `.app-header.title`), though explicitly using absolute selectors is generally recommended for clarity.
|
|
333
|
+
- You do not need to pass `referToCssId`. You just use the standard global class names in your JSX.
|
|
334
|
+
|
|
335
|
+
```tsx
|
|
336
|
+
// 1. Define the shared CSS with absolute selectors
|
|
337
|
+
export const appSharedCss = {
|
|
338
|
+
'.app-header': {
|
|
339
|
+
fontSize: '14px',
|
|
340
|
+
// Using & here refers to the parent selector (.app-header),
|
|
341
|
+
// resulting in .app-header.title
|
|
342
|
+
'&.title': { fontSize: '24px' },
|
|
343
|
+
},
|
|
344
|
+
'.app-warning-color': { color: 'red' },
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
// 2. Add this in your app's initialization (e.g., index.tsx)
|
|
348
|
+
// The 4th parameter (noTopClassName = true) is critical here!
|
|
349
|
+
bindAppGlobalStyle('app-shared-css', appSharedCss, false, true);
|
|
350
|
+
|
|
351
|
+
// 3. Use it anywhere
|
|
352
|
+
export const AnyComponent = () => (
|
|
353
|
+
// Use the absolute class names directly
|
|
354
|
+
<div class="app-header title">Hello</div>
|
|
355
|
+
);
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
### 4.5 Using `&` on Top-Level Tags
|
|
359
|
+
|
|
360
|
+
When there is a special need to use an `&-` class prefix on a top-level tag, use the `&.&-box` syntax. The standalone `&` selector is replaced by the CSS ID automatically generated for this top-level tag.
|
|
361
|
+
For instance, `"&.&-box"` compiles to `"l01.l01-box"`.
|
|
279
362
|
|
|
280
363
|
```typescript
|
|
281
364
|
export const Component1 = () => {
|
|
@@ -288,18 +371,17 @@ export const Component1 = () => {
|
|
|
288
371
|
bindGlobalStyle(gCssId, css);
|
|
289
372
|
|
|
290
373
|
const ref: RefProps = {
|
|
291
|
-
|
|
374
|
+
referToCssId: gCssId,
|
|
292
375
|
};
|
|
376
|
+
|
|
293
377
|
return (
|
|
294
|
-
<div ref={ref} class='&-box'>
|
|
378
|
+
<div ref={ref} class={[gCssId, '&-box'].join(' ')}>
|
|
295
379
|
<div class='&-item'>item</div>
|
|
296
380
|
</div>
|
|
297
381
|
);
|
|
298
382
|
};
|
|
299
383
|
```
|
|
300
384
|
|
|
301
|
-
---
|
|
302
|
-
|
|
303
385
|
## 5. Common Patterns ("The Lupine Way")
|
|
304
386
|
|
|
305
387
|
### List / Search (No Re-render)
|
|
@@ -17,22 +17,24 @@
|
|
|
17
17
|
}
|
|
18
18
|
],
|
|
19
19
|
"apiEntryPoint": "api/src/index.ts",
|
|
20
|
-
"watchFiles": [
|
|
20
|
+
"watchFiles": [
|
|
21
|
+
"web/markdown/**/*.md"
|
|
22
|
+
],
|
|
21
23
|
"copyFiles": [
|
|
22
24
|
{
|
|
23
|
-
"
|
|
25
|
+
"env": "all",
|
|
24
26
|
"from": "web/assets",
|
|
25
|
-
"to": "assets"
|
|
27
|
+
"to": "web/assets"
|
|
26
28
|
},
|
|
27
29
|
{
|
|
28
|
-
"
|
|
30
|
+
"env": "all",
|
|
29
31
|
"from": "web/src/lupine-template-cv-starter/404.html",
|
|
30
|
-
"to": "lupine-template-cv-starter/404.html"
|
|
32
|
+
"to": "web/lupine-template-cv-starter/404.html"
|
|
31
33
|
},
|
|
32
34
|
{
|
|
33
|
-
"
|
|
35
|
+
"env": "all",
|
|
34
36
|
"from": "api/resources",
|
|
35
|
-
"to": "resources"
|
|
37
|
+
"to": "data/resources"
|
|
36
38
|
}
|
|
37
39
|
]
|
|
38
|
-
}
|
|
40
|
+
}
|
|
@@ -17,22 +17,24 @@
|
|
|
17
17
|
}
|
|
18
18
|
],
|
|
19
19
|
"apiEntryPoint": "api/src/index.ts",
|
|
20
|
-
"watchFiles": [
|
|
20
|
+
"watchFiles": [
|
|
21
|
+
"web/markdown/**/*.md"
|
|
22
|
+
],
|
|
21
23
|
"copyFiles": [
|
|
22
24
|
{
|
|
23
|
-
"
|
|
25
|
+
"env": "all",
|
|
24
26
|
"from": "web/assets",
|
|
25
|
-
"to": "assets"
|
|
27
|
+
"to": "web/assets"
|
|
26
28
|
},
|
|
27
29
|
{
|
|
28
|
-
"
|
|
30
|
+
"env": "all",
|
|
29
31
|
"from": "web/src/lupine-template-doc-starter/404.html",
|
|
30
|
-
"to": "lupine-template-doc-starter/404.html"
|
|
32
|
+
"to": "web/lupine-template-doc-starter/404.html"
|
|
31
33
|
},
|
|
32
34
|
{
|
|
33
|
-
"
|
|
35
|
+
"env": "all",
|
|
34
36
|
"from": "api/resources",
|
|
35
|
-
"to": "resources"
|
|
37
|
+
"to": "data/resources"
|
|
36
38
|
}
|
|
37
39
|
]
|
|
38
|
-
}
|
|
40
|
+
}
|
|
@@ -10,14 +10,14 @@
|
|
|
10
10
|
"apiEntryPoint": "api/src/index.ts",
|
|
11
11
|
"copyFiles": [
|
|
12
12
|
{
|
|
13
|
-
"
|
|
13
|
+
"env": "all",
|
|
14
14
|
"from": "web/assets",
|
|
15
|
-
"to": "assets"
|
|
15
|
+
"to": "web/assets"
|
|
16
16
|
},
|
|
17
17
|
{
|
|
18
|
-
"
|
|
18
|
+
"env": "all",
|
|
19
19
|
"from": "api/resources",
|
|
20
|
-
"to": "resources"
|
|
20
|
+
"to": "data/resources"
|
|
21
21
|
}
|
|
22
22
|
]
|
|
23
|
-
}
|
|
23
|
+
}
|