@emulsify/core 4.0.2 → 4.0.3
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/.storybook/utils.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import {
|
|
6
6
|
attachStorybookBehaviors,
|
|
7
7
|
genericStorybookAdapter,
|
|
8
|
+
noneStorybookAdapter,
|
|
8
9
|
normalizeStorybookPlatformAdapter,
|
|
9
10
|
} from '../src/storybook/platform-behaviors.js';
|
|
10
11
|
import { setupTwig } from '../src/storybook/twig/setup.js';
|
|
@@ -93,6 +94,7 @@ export {
|
|
|
93
94
|
attachStorybookBehaviors,
|
|
94
95
|
fetchCSSFiles,
|
|
95
96
|
genericStorybookAdapter,
|
|
97
|
+
noneStorybookAdapter,
|
|
96
98
|
normalizeStorybookPlatformAdapter,
|
|
97
99
|
setupTwig,
|
|
98
100
|
};
|
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ See [Version Evolution](docs/version-evolution.md) for more release history.
|
|
|
34
34
|
|
|
35
35
|
Twig and React are equally valid ways to build component libraries with Emulsify Core. The right authoring model depends on the consuming project:
|
|
36
36
|
|
|
37
|
-
- Use Twig for CMS themes and server-rendered template systems. Drupal has a dedicated adapter today; Craft CMS and WordPress + Timber can use the
|
|
37
|
+
- Use Twig for CMS themes and server-rendered template systems. Drupal has a dedicated adapter today; Craft CMS and WordPress + Timber can use the `none` adapter unless a project adds platform-specific behavior.
|
|
38
38
|
- Use React for standalone UI libraries, application components, or projects that already use React.
|
|
39
39
|
- Use mixed Twig and React when a design system needs to document both CMS-rendered and JavaScript-rendered components in the same Storybook instance.
|
|
40
40
|
|
|
@@ -53,7 +53,7 @@ Every project should provide a `project.emulsify.json` file at the project root:
|
|
|
53
53
|
```json
|
|
54
54
|
{
|
|
55
55
|
"project": {
|
|
56
|
-
"platform": "
|
|
56
|
+
"platform": "none",
|
|
57
57
|
"name": "example",
|
|
58
58
|
"machineName": "example"
|
|
59
59
|
}
|
|
@@ -77,7 +77,7 @@ The documentation is split by task:
|
|
|
77
77
|
| [Component Authoring](docs/component-authoring.md) | Choosing Twig, React, or mixed Storybook authoring and comparing component examples. |
|
|
78
78
|
| [Storybook](docs/storybook.md) | Rendering Twig stories, using `renderTwig()`, understanding Twig runtime helpers, and mixing Twig with React stories. |
|
|
79
79
|
| [Project Structure And Output](docs/project-structure.md) | Configuring `src/components`, root `./components`, `variant.structureImplementations`, and expected output paths. |
|
|
80
|
-
| [Platform Adapters](docs/platform-adapters.md) | Understanding `
|
|
80
|
+
| [Platform Adapters](docs/platform-adapters.md) | Understanding `none`, `drupal`, platform resolution order, and Drupal SDC behavior. |
|
|
81
81
|
| [Extension Points](docs/extension-points.md) | Adding Vite plugins, Tailwind CSS, Storybook preview overrides, and other framework tooling. |
|
|
82
82
|
| [Performance](docs/performance.md) | Understanding sourcemaps, eager Twig imports, Tailwind scanning, copied files, and fixture validation. |
|
|
83
83
|
| [Native Twig Extensions](docs/native-twig-extensions.md) | Using `bem()`, `add_attributes()`, and `switch/case/default/endswitch` in Twig.js. |
|
|
@@ -86,24 +86,24 @@ The documentation is split by task:
|
|
|
86
86
|
|
|
87
87
|
## Known Limitations
|
|
88
88
|
|
|
89
|
-
- Implemented platform adapters are currently `
|
|
89
|
+
- Implemented platform adapters are currently `none` and `drupal`. WordPress + Timber and Craft CMS are supported as Twig-oriented use cases through the `none` adapter today. Dedicated adapters are future opportunities. See [Platform Adapters](docs/platform-adapters.md).
|
|
90
90
|
- Storybook's Twig resolver eagerly imports Twig modules and raw Twig source. This is reliable for `include()` and `source()`, but large Twig libraries should keep Storybook source roots intentional. See [Performance](docs/performance.md).
|
|
91
91
|
- Production sourcemaps are enabled by default unless a project overrides Vite config through `config/emulsify-core/vite/plugins.*`. See [Performance](docs/performance.md).
|
|
92
92
|
- Project extensions use the public `config/emulsify-core` directory: `config/emulsify-core/vite/plugins.*` for Vite, `config/emulsify-core/storybook/...` for Storybook, and `config/emulsify-core/a11y.config.js` for a11y. See [Extension Points](docs/extension-points.md).
|
|
93
93
|
- Webpack-specific customizations must be migrated manually to Vite plugins or `extendConfig()`. See [Migration](docs/migration-4x.md).
|
|
94
|
-
- Drupal SDC mirroring only applies when the Drupal adapter and SDC settings are enabled.
|
|
94
|
+
- Drupal SDC mirroring only applies when the Drupal adapter and SDC settings are enabled. `none` projects should expect output to remain in `dist/`. See [Platform Adapters](docs/platform-adapters.md).
|
|
95
95
|
|
|
96
96
|
## Supported Project Shapes
|
|
97
97
|
|
|
98
98
|
Release-readiness coverage validates:
|
|
99
99
|
|
|
100
100
|
- Drupal SDC projects using `src/components`.
|
|
101
|
-
-
|
|
101
|
+
- `none` platform Twig projects using `src/components`.
|
|
102
102
|
- Root `./components` projects.
|
|
103
103
|
- Projects using multiple `variant.structureImplementations`.
|
|
104
104
|
- Mixed Twig + React Storybook projects.
|
|
105
105
|
|
|
106
|
-
WordPress + Timber and Craft CMS are Twig-based project use cases that can use the `
|
|
106
|
+
WordPress + Timber and Craft CMS are Twig-based project use cases that can use the `none` adapter today. Dedicated adapters for those platforms are future opportunities. The implemented adapters in this package are currently `none` and `drupal`.
|
|
107
107
|
|
|
108
108
|
## Public Imports
|
|
109
109
|
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* entries, plugins, and the Vite config.
|
|
6
6
|
*
|
|
7
7
|
* Highlights:
|
|
8
|
-
* - `platform`: from env var or project.emulsify.json (default "
|
|
8
|
+
* - `platform`: from env var or project.emulsify.json (default "none").
|
|
9
9
|
* - `SDC`: boolean from project.emulsify.json `project.singleDirectoryComponents`.
|
|
10
10
|
* - `structureOverrides`: true when safe `variant.structureImplementations` exist.
|
|
11
11
|
* - `structureRoots`: array of directories from `variant.structureImplementations`.
|
|
@@ -21,7 +21,7 @@ import { resolveProjectConfig } from './project-config.js';
|
|
|
21
21
|
* projectDir: string,
|
|
22
22
|
* srcDir: string,
|
|
23
23
|
* srcExists: boolean,
|
|
24
|
-
* platform: 'drupal' | '
|
|
24
|
+
* platform: 'drupal' | 'none' | string,
|
|
25
25
|
* SDC: boolean,
|
|
26
26
|
* structureOverrides: boolean,
|
|
27
27
|
* structureRoots: string[],
|
package/config/vite/platforms.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* decisions can be used by Node-side Vite config and Storybook browser code.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
const
|
|
9
|
-
name: '
|
|
8
|
+
const noneAdapter = {
|
|
9
|
+
name: 'none',
|
|
10
10
|
outputStrategy: 'dist',
|
|
11
11
|
storybook: {
|
|
12
12
|
loadDrupalBehaviorShim: false,
|
|
@@ -36,7 +36,8 @@ const drupalAdapter = {
|
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
const adapters = {
|
|
39
|
-
|
|
39
|
+
none: noneAdapter,
|
|
40
|
+
generic: noneAdapter,
|
|
40
41
|
drupal: drupalAdapter,
|
|
41
42
|
};
|
|
42
43
|
|
|
@@ -50,21 +51,39 @@ function cloneAdapter(adapter) {
|
|
|
50
51
|
return JSON.parse(JSON.stringify(adapter));
|
|
51
52
|
}
|
|
52
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Normalize configured platform names to canonical identifiers.
|
|
56
|
+
*
|
|
57
|
+
* `generic` is retained as a legacy alias for existing projects, but new
|
|
58
|
+
* configuration should use `none` for projects without platform-specific
|
|
59
|
+
* behavior.
|
|
60
|
+
*
|
|
61
|
+
* @param {*} platform - Candidate platform name.
|
|
62
|
+
* @returns {string} Canonical platform name.
|
|
63
|
+
*/
|
|
64
|
+
export function normalizePlatformName(platform = 'none') {
|
|
65
|
+
const key = (platform || '').toString().toLowerCase().trim();
|
|
66
|
+
if (!key || key === 'generic') {
|
|
67
|
+
return 'none';
|
|
68
|
+
}
|
|
69
|
+
return key;
|
|
70
|
+
}
|
|
71
|
+
|
|
53
72
|
/**
|
|
54
73
|
* Resolve the platform adapter for a normalized platform name.
|
|
55
74
|
*
|
|
56
|
-
* Unknown platforms intentionally use
|
|
75
|
+
* Unknown platforms intentionally use `none` behavior while preserving the
|
|
57
76
|
* resolved `platform` string separately on the environment object.
|
|
58
77
|
*
|
|
59
|
-
* @param {string} [platform='
|
|
78
|
+
* @param {string} [platform='none'] - Normalized platform name.
|
|
60
79
|
* @returns {object} Serializable platform adapter.
|
|
61
80
|
*/
|
|
62
|
-
export function getPlatformAdapter(platform = '
|
|
63
|
-
const key = (platform
|
|
81
|
+
export function getPlatformAdapter(platform = 'none') {
|
|
82
|
+
const key = normalizePlatformName(platform);
|
|
64
83
|
if (key === 'drupal') {
|
|
65
84
|
return cloneAdapter(drupalAdapter);
|
|
66
85
|
}
|
|
67
|
-
return cloneAdapter(
|
|
86
|
+
return cloneAdapter(noneAdapter);
|
|
68
87
|
}
|
|
69
88
|
|
|
70
89
|
export { adapters };
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { normalize, resolve, sep } from 'path';
|
|
11
|
-
import { getPlatformAdapter } from './platforms.js';
|
|
11
|
+
import { getPlatformAdapter, normalizePlatformName } from './platforms.js';
|
|
12
12
|
import { resolveProjectStructure } from './project-structure.js';
|
|
13
13
|
import { safeExists, safeReadJson } from './utils/fs-safe.js';
|
|
14
14
|
|
|
@@ -53,8 +53,12 @@ function normalizeIdentifier(value) {
|
|
|
53
53
|
* @returns {string} Stable cache-key segment.
|
|
54
54
|
*/
|
|
55
55
|
function projectConfigEnvSignature(env = {}) {
|
|
56
|
+
const platformOverride = normalizeIdentifier(env.EMULSIFY_PLATFORM);
|
|
57
|
+
|
|
56
58
|
return JSON.stringify({
|
|
57
|
-
EMULSIFY_PLATFORM:
|
|
59
|
+
EMULSIFY_PLATFORM: platformOverride
|
|
60
|
+
? normalizePlatformName(platformOverride)
|
|
61
|
+
: '',
|
|
58
62
|
});
|
|
59
63
|
}
|
|
60
64
|
|
|
@@ -119,11 +123,12 @@ export function resolveProjectConfig(
|
|
|
119
123
|
const srcExists = safeExists(srcCandidate);
|
|
120
124
|
const srcDir = srcExists ? srcCandidate : resolve(root, 'components');
|
|
121
125
|
|
|
122
|
-
const
|
|
126
|
+
const resolvedPlatform =
|
|
123
127
|
normalizeIdentifier(env.EMULSIFY_PLATFORM) ||
|
|
124
128
|
normalizeIdentifier(rawConfig?.project?.platform) ||
|
|
125
129
|
normalizeIdentifier(rawConfig?.variant?.platform) ||
|
|
126
|
-
'
|
|
130
|
+
'none';
|
|
131
|
+
const platform = normalizePlatformName(resolvedPlatform);
|
|
127
132
|
const platformAdapter = getPlatformAdapter(platform);
|
|
128
133
|
|
|
129
134
|
const singleDirectoryComponents = Boolean(
|
package/package.json
CHANGED
package/scripts/audit.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @file Platform-specific Storybook behavior helpers.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
export const
|
|
5
|
+
export const noneStorybookAdapter = {
|
|
6
6
|
loadDrupalBehaviorShim: false,
|
|
7
7
|
attachDrupalBehaviors: false,
|
|
8
8
|
registerDrupalTwigFilters: false,
|
|
@@ -10,15 +10,17 @@ export const genericStorybookAdapter = {
|
|
|
10
10
|
allowSyncXhrSource: false,
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
+
export const genericStorybookAdapter = noneStorybookAdapter;
|
|
14
|
+
|
|
13
15
|
/**
|
|
14
16
|
* Normalize optional platform adapter flags into the full Storybook shape.
|
|
15
17
|
*
|
|
16
18
|
* @param {object} [adapter] - Candidate Storybook adapter flags.
|
|
17
|
-
* @returns {object} Storybook adapter flags with
|
|
19
|
+
* @returns {object} Storybook adapter flags with non-platform defaults.
|
|
18
20
|
*/
|
|
19
21
|
export function normalizeStorybookPlatformAdapter(adapter = {}) {
|
|
20
22
|
return {
|
|
21
|
-
...
|
|
23
|
+
...noneStorybookAdapter,
|
|
22
24
|
...(adapter || {}),
|
|
23
25
|
};
|
|
24
26
|
}
|
|
@@ -27,7 +29,7 @@ export function normalizeStorybookPlatformAdapter(adapter = {}) {
|
|
|
27
29
|
* Attach platform-specific behaviors after a Storybook render.
|
|
28
30
|
*
|
|
29
31
|
* Drupal behavior attachment is opt-in through the active platform adapter.
|
|
30
|
-
*
|
|
32
|
+
* `none` and unknown platforms return without creating Drupal globals.
|
|
31
33
|
*
|
|
32
34
|
* @param {object} [options={}] - Attachment options.
|
|
33
35
|
* @param {object} [options.adapter] - Active Storybook platform adapter.
|