@emulsify/core 3.5.0 → 4.0.0

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.
Files changed (110) hide show
  1. package/.cli/init.js +40 -31
  2. package/.storybook/_drupal.js +129 -8
  3. package/.storybook/css-components.js +13 -0
  4. package/.storybook/css-dist.js +5 -0
  5. package/.storybook/emulsifyTheme.js +9 -6
  6. package/.storybook/main.js +397 -106
  7. package/.storybook/manager.js +9 -16
  8. package/.storybook/preview.js +88 -110
  9. package/.storybook/utils.js +69 -74
  10. package/README.md +110 -59
  11. package/config/.stylelintrc.json +2 -6
  12. package/config/a11y.config.js +9 -5
  13. package/config/babel.config.js +6 -11
  14. package/config/eslint.config.js +31 -3
  15. package/config/postcss.config.js +5 -0
  16. package/config/vite/entries.js +227 -0
  17. package/config/vite/environment.js +39 -0
  18. package/config/vite/platforms.js +70 -0
  19. package/config/vite/plugins/copy-src-assets.js +76 -0
  20. package/config/vite/plugins/copy-twig-files.js +84 -0
  21. package/config/vite/plugins/css-asset-relativizer.js +40 -0
  22. package/config/vite/plugins/index.js +105 -0
  23. package/config/vite/plugins/mirror-components.js +358 -0
  24. package/config/vite/plugins/require-context.js +311 -0
  25. package/config/vite/plugins/source-file-index.js +184 -0
  26. package/config/vite/plugins/svg-sprite.js +117 -0
  27. package/config/vite/plugins/twig-extension-installers.js +36 -0
  28. package/config/vite/plugins/twig-module.js +1251 -0
  29. package/config/vite/plugins/virtual-twig-asset-sources.js +404 -0
  30. package/config/vite/plugins/virtual-twig-globs.js +136 -0
  31. package/config/vite/plugins/vituum-patch.js +167 -0
  32. package/config/vite/plugins/yaml-module.js +133 -0
  33. package/config/vite/plugins.js +12 -0
  34. package/config/vite/project-config.js +192 -0
  35. package/config/vite/project-extensions.js +177 -0
  36. package/config/vite/project-structure.js +447 -0
  37. package/config/vite/twig-extensions.js +109 -0
  38. package/config/vite/utils/fs-safe.js +66 -0
  39. package/config/vite/utils/paths.js +40 -0
  40. package/config/vite/utils/react-singleton.js +85 -0
  41. package/config/vite/utils/unique.js +36 -0
  42. package/config/vite/vite.config.js +161 -0
  43. package/package.json +164 -75
  44. package/scripts/a11y.js +70 -16
  45. package/scripts/audit-twig-stories.js +378 -0
  46. package/scripts/audit.js +1602 -0
  47. package/scripts/check-node-version.js +18 -0
  48. package/scripts/loadYaml.js +5 -1
  49. package/src/extensions/index.js +8 -0
  50. package/src/extensions/react/index.js +12 -0
  51. package/src/extensions/react/register.js +45 -0
  52. package/src/extensions/shared/attributes.js +308 -0
  53. package/src/extensions/shared/html.js +41 -0
  54. package/src/extensions/shared/lists.js +38 -0
  55. package/src/extensions/shared/object.js +22 -0
  56. package/src/extensions/twig/function-map.js +20 -0
  57. package/src/extensions/twig/functions/add-attributes.js +39 -0
  58. package/src/extensions/twig/functions/bem.js +166 -0
  59. package/src/extensions/twig/index.js +13 -0
  60. package/src/extensions/twig/register.js +52 -0
  61. package/src/extensions/twig/tag-map.js +16 -0
  62. package/src/extensions/twig/tags/switch.js +266 -0
  63. package/src/storybook/index.js +14 -0
  64. package/src/storybook/main-config.js +132 -0
  65. package/src/storybook/platform-behaviors.js +60 -0
  66. package/src/storybook/preview-parameters.js +81 -0
  67. package/src/storybook/render-twig.js +295 -0
  68. package/src/storybook/twig/drupal-filters.js +7 -0
  69. package/src/storybook/twig/include-function.js +109 -0
  70. package/src/storybook/twig/include.js +28 -0
  71. package/src/storybook/twig/reference-paths.js +294 -0
  72. package/src/storybook/twig/resolver.js +318 -0
  73. package/src/storybook/twig/setup.js +39 -0
  74. package/src/storybook/twig/source-events.js +5 -0
  75. package/src/storybook/twig/source-extensions.js +24 -0
  76. package/src/storybook/twig/source-function.js +239 -0
  77. package/src/storybook/twig/source.js +39 -0
  78. package/.all-contributorsrc +0 -45
  79. package/.editorconfig +0 -5
  80. package/.github/ISSUE_TEMPLATE/BUG_REPORT_TEMPLATE.md +0 -18
  81. package/.github/ISSUE_TEMPLATE/FEATURE_REQUEST_TEMPLATE.md +0 -11
  82. package/.github/PULL_REQUEST_TEMPLATE.md +0 -19
  83. package/.github/dependabot.yml +0 -6
  84. package/.github/workflows/addtoprojects.yml +0 -21
  85. package/.github/workflows/contributors.yml +0 -37
  86. package/.github/workflows/lint.yml +0 -22
  87. package/.github/workflows/semantic-release.yml +0 -24
  88. package/.husky/commit-msg +0 -2
  89. package/.husky/pre-commit +0 -2
  90. package/.nvmrc +0 -1
  91. package/.prettierignore +0 -4
  92. package/.storybook/polyfills/twig-include.js +0 -40
  93. package/.storybook/polyfills/twig-resolver.js +0 -70
  94. package/.storybook/polyfills/twig-source.js +0 -65
  95. package/.storybook/webpack.config.js +0 -269
  96. package/CODE_OF_CONDUCT.md +0 -56
  97. package/commitlint.config.js +0 -5
  98. package/config/jest.config.js +0 -19
  99. package/config/webpack/app.js +0 -1
  100. package/config/webpack/loaders.js +0 -167
  101. package/config/webpack/optimizers.js +0 -26
  102. package/config/webpack/plugins.js +0 -283
  103. package/config/webpack/resolves.js +0 -157
  104. package/config/webpack/sdc-loader.js +0 -16
  105. package/config/webpack/webpack.common.js +0 -272
  106. package/config/webpack/webpack.dev.js +0 -41
  107. package/config/webpack/webpack.prod.js +0 -6
  108. package/release.config.cjs +0 -30
  109. package/scripts/a11y.test.js +0 -172
  110. package/scripts/loadYaml.test.js +0 -30
@@ -1,30 +1,60 @@
1
- // .storybook/preview.js
2
- import { useEffect } from 'storybook/preview-api';
3
- import Twig from 'twig';
4
- import { setupTwig, fetchCSSFiles } from './utils.js';
1
+ /**
2
+ * @file Storybook preview configuration shared by Emulsify projects.
3
+ */
4
+
5
5
  import { getRules } from 'axe-core';
6
+ import React from 'react';
7
+ import { defaultDecorateStory, useEffect } from 'storybook/preview-api';
8
+ import Twig from 'twig';
9
+ import { twigExtensionInstallers } from 'virtual:emulsify-twig-extension-installers';
10
+ import {
11
+ mergePreviewParameters,
12
+ normalizePreviewOverrideModule,
13
+ } from '../src/storybook/preview-parameters.js';
14
+ import {
15
+ renderHtmlStoryResult,
16
+ withLegacyStoryToString,
17
+ } from '../src/storybook/render-twig.js';
18
+ import {
19
+ attachStorybookBehaviors,
20
+ fetchCSSFiles,
21
+ getStorybookPlatformAdapter,
22
+ setupTwig,
23
+ } from './utils.js';
24
+
25
+ const previewOverrideModules = import.meta.glob(
26
+ [
27
+ // Installed package path: node_modules/@emulsify/core/.storybook -> project root.
28
+ '../../../../config/emulsify-core/storybook/preview.js',
29
+ // Local development path: repo .storybook -> repo root.
30
+ '../config/emulsify-core/storybook/preview.js',
31
+ ],
32
+ { eager: true },
33
+ );
34
+ const [previewOverrideModule] = Object.values(previewOverrideModules);
35
+ const externalOverrides = normalizePreviewOverrideModule(previewOverrideModule);
6
36
 
7
37
  /**
8
- * External override parameters loaded from project config file, if present.
9
- * @type {object}
38
+ * Active platform behavior used by the shared preview decorators.
39
+ *
40
+ * @type {ReturnType<typeof getStorybookPlatformAdapter>}
10
41
  */
11
- let externalOverrides;
42
+ const platformAdapter = getStorybookPlatformAdapter();
12
43
 
13
- // Load the preview.js from the project config overrides.
14
- try {
15
- /**
16
- * Dynamically require external preview overrides.
17
- * @module '../../../../config/emulsify-core/storybook/preview.js'
18
- */
19
- externalOverrides =
20
- require('../../../../config/emulsify-core/storybook/preview.js').default;
21
- } catch {
22
- // no override file? swallow the error and use {}
23
- externalOverrides = {};
24
- }
44
+ /**
45
+ * Deferred Drupal behavior shim import.
46
+ *
47
+ * The decorator awaits this promise when Drupal behaviors are enabled so that
48
+ * `attachBehaviors()` is available before a story asks for it.
49
+ *
50
+ * @type {Promise<*>}
51
+ */
52
+ const platformBehaviorShimReady = platformAdapter.loadDrupalBehaviorShim
53
+ ? import('./_drupal.js')
54
+ : Promise.resolve();
25
55
 
26
- // Import Drupal behaviors for rich JavaScript integration.
27
- import './_drupal.js';
56
+ /** @type {Array<Function>} Configured Twig.js extension installers. */
57
+ const configuredTwigExtensions = twigExtensionInstallers;
28
58
 
29
59
  /**
30
60
  * Filters accessibility rules by matching tags.
@@ -54,99 +84,48 @@ const AxeRules = enableRulesByTag([
54
84
  ]);
55
85
 
56
86
  /**
57
- * Cache of rendered story output keyed by story id.
58
- * Storybook server renderer calls `storyFn()` before `fetchStoryHtml`, so
59
- * decorators can stash markup here and fetch can read it without re-rendering.
87
+ * Storybook React wraps story functions in React elements before decorators run.
88
+ * Preserve that React-safe behavior while giving old stringifying decorators a
89
+ * useful string result for legacy Twig stories.
60
90
  *
61
- * @type {Map<string, unknown>}
91
+ * @param {Function} storyFn Storybook story function.
92
+ * @param {Function[]} decorators Storybook decorators.
93
+ * @returns {Function} Decorated story function.
62
94
  */
63
- const renderedStoryCache = new Map();
64
-
65
- /**
66
- * Converts a rendered story return value into an HTML string.
67
- *
68
- * @param {unknown} rendered
69
- * The rendered story result.
70
- *
71
- * @returns {string}
72
- * Normalized HTML string.
73
- */
74
- function toHtmlString(rendered) {
75
- if (typeof rendered === 'string') {
76
- return rendered;
77
- }
78
-
79
- if (rendered && typeof rendered === 'object') {
80
- if (typeof rendered.outerHTML === 'string') {
81
- return rendered.outerHTML;
82
- }
83
- if (typeof rendered.html === 'string') {
84
- return rendered.html;
85
- }
86
- }
87
-
88
- return '';
89
- }
90
-
91
- /**
92
- * Default server renderer adapter for Storybook 9 server-webpack5.
93
- * Falls back to local story functions so projects do not need a remote
94
- * `parameters.server.url` endpoint for basic HTML/Twig stories.
95
- *
96
- * @param {string} _url
97
- * Unused URL from server parameters.
98
- * @param {string} _path
99
- * Unused story path/id from server parameters.
100
- * @param {object} _params
101
- * Unused merged server params.
102
- * @param {object} storyContext
103
- * Story context from Storybook.
104
- *
105
- * @returns {Promise<string>}
106
- * Story markup as an HTML string.
107
- */
108
- async function fetchStoryHtmlFromStoryContext(
109
- _url,
110
- _path,
111
- _params,
112
- storyContext,
113
- ) {
114
- const storyId = storyContext?.id || _path;
115
- if (!storyId || !renderedStoryCache.has(storyId)) {
116
- return '';
117
- }
118
-
119
- const rendered = await Promise.resolve(renderedStoryCache.get(storyId));
120
- return toHtmlString(rendered);
121
- }
122
-
123
- // Initialize Twig and load any CSS that your stories need.
124
- setupTwig(Twig);
125
- fetchCSSFiles();
95
+ export const applyDecorators = (storyFn, decorators) =>
96
+ defaultDecorateStory(
97
+ (context) =>
98
+ withLegacyStoryToString(React.createElement(storyFn, context), () =>
99
+ storyFn(context),
100
+ ),
101
+ decorators,
102
+ );
126
103
 
127
104
  /**
128
- * Storybook decorators to apply Drupal behaviors before rendering each story.
129
- * The HTML renderer still uses the generic Storybook decorator signature.
130
- * @type {Function[]}
105
+ * Storybook decorators to apply platform-specific behavior after each story render.
106
+ * @type {Array<import('@storybook/react').Decorator>}
131
107
  */
132
108
  export const decorators = [
133
109
  /**
134
- * Decorator that attaches Drupal behaviors on story mount.
110
+ * Decorator that attaches platform behavior on story mount and args updates.
111
+ * Legacy Twig stories that return HTML strings are wrapped so React
112
+ * Storybook renders them as markup while projects migrate to renderTwig().
113
+ *
135
114
  * @param {Function} Story The story component to render.
136
115
  * @param {object} context Story context including args.
137
- * @returns {Function} Rendered story.
116
+ * @returns {*} Rendered story.
138
117
  */
139
- (Story, context) => {
140
- const { args, id } = context;
118
+ (Story, { args }) => {
141
119
  useEffect(() => {
142
- Drupal.attachBehaviors();
120
+ void attachStorybookBehaviors({
121
+ adapter: platformAdapter,
122
+ behaviorShimReady: platformBehaviorShimReady,
123
+ });
143
124
  }, [args]);
144
125
 
145
- const rendered = Story();
146
- if (id) {
147
- renderedStoryCache.set(id, rendered);
148
- }
149
- return rendered;
126
+ return renderHtmlStoryResult(Story({ args }), {
127
+ platformAdapter,
128
+ });
150
129
  },
151
130
  ];
152
131
 
@@ -164,18 +143,17 @@ const defaultParams = {
164
143
  },
165
144
  },
166
145
  layout: 'fullscreen',
167
- server: {
168
- url: '',
169
- fetchStoryHtml: fetchStoryHtmlFromStoryContext,
170
- params: {},
171
- },
172
146
  };
173
147
 
174
148
  /**
175
149
  * Merged Storybook parameters including external overrides.
176
150
  * @type {object}
177
151
  */
178
- export const parameters = {
179
- ...defaultParams,
180
- ...externalOverrides,
181
- };
152
+ export const parameters = mergePreviewParameters(
153
+ defaultParams,
154
+ externalOverrides,
155
+ );
156
+
157
+ // Initialize platform-agnostic Twig helpers and eager-load story CSS.
158
+ setupTwig(Twig, { extensions: configuredTwigExtensions });
159
+ await fetchCSSFiles(parameters);
@@ -1,61 +1,76 @@
1
- import { resolve, dirname } from 'path';
2
- import twigDrupal from 'twig-drupal-filters';
3
- import twigBEM from 'bem-twig-extension';
4
- import twigAddAttributes from 'add-attributes-twig-extension';
5
- import emulsifyConfig from '../../../../project.emulsify.json' with { type: 'json' };
6
- import twigInclude from './polyfills/twig-include.js';
7
- import twigSource from './polyfills/twig-source.js';
1
+ /**
2
+ * @file Shared Storybook runtime helpers.
3
+ */
8
4
 
9
- // Create __filename from import.meta.url without fileURLToPath
10
- let _filename = decodeURIComponent(new URL(import.meta.url).pathname);
5
+ import {
6
+ attachStorybookBehaviors,
7
+ genericStorybookAdapter,
8
+ normalizeStorybookPlatformAdapter,
9
+ } from '../src/storybook/platform-behaviors.js';
10
+ import { setupTwig } from '../src/storybook/twig/setup.js';
11
11
 
12
- // On Windows, remove the leading slash (e.g. "/C:/path" -> "C:/path")
13
- if (process.platform === 'win32' && _filename.startsWith('/')) {
14
- _filename = _filename.slice(1);
12
+ const emulsifyEnv =
13
+ (typeof __EMULSIFY_ENV__ !== 'undefined' && __EMULSIFY_ENV__) || {};
14
+
15
+ /**
16
+ * Get the normalized Emulsify environment injected by Storybook's Vite config.
17
+ *
18
+ * @returns {object} Normalized Emulsify environment.
19
+ */
20
+ export function getEmulsifyEnvironment() {
21
+ return emulsifyEnv;
15
22
  }
16
23
 
17
- const _dirname = dirname(_filename);
24
+ /**
25
+ * Get Storybook platform behavior flags from the active adapter.
26
+ *
27
+ * @returns {object} Storybook adapter flags.
28
+ */
29
+ export function getStorybookPlatformAdapter() {
30
+ return normalizeStorybookPlatformAdapter(
31
+ emulsifyEnv.platformAdapter?.storybook,
32
+ );
33
+ }
18
34
 
19
35
  /**
20
- * Fetches project-based variant configuration. If no such configuration
21
- * exists, returns default values as a flat component structure.
36
+ * Determine whether Storybook should eagerly load all compiled CSS.
22
37
  *
23
- * @returns {Array} project-based variant configuration, or default config.
38
+ * @param {object} [parameters={}] - Storybook parameters.
39
+ * @returns {boolean} TRUE unless `parameters.emulsify.loadAllCSS` is false.
24
40
  */
25
- const fetchVariantConfig = () => {
26
- try {
27
- return emulsifyConfig.variant.structureImplementations;
28
- } catch {
29
- return [
30
- {
31
- name: 'components',
32
- directory: '../../../../components',
33
- },
34
- ];
35
- }
36
- };
41
+ export function getLoadAllCSS(parameters = {}) {
42
+ return parameters?.emulsify?.loadAllCSS !== false;
43
+ }
37
44
 
38
45
  /**
39
- * Fetches and loads all CSS files from the specified directories based on the project's configuration.
40
- * If the platform is 'drupal', it also includes CSS files from additional component directories.
46
+ * Eagerly load CSS from the active Storybook render path.
47
+ *
48
+ * Drupal-style mirrored component CSS uses the root `components` CSS tree for
49
+ * component styles and keeps shared compiled CSS from `dist` excluding
50
+ * `dist/components`; all other projects use the compiled `dist` CSS tree. The
51
+ * eager globs live in separate dynamically imported modules so Vite cannot
52
+ * hoist both render paths into the same preview bundle. Projects with very
53
+ * large CSS libraries can set `parameters.emulsify.loadAllCSS = false` and
54
+ * import their own CSS from a preview override.
41
55
  *
42
- * @returns {undefined} If an error occurs, the function will return undefined.
56
+ * @param {object} [parameters={}] - Storybook parameters.
57
+ * @returns {Promise<undefined>} Resolves when the selected CSS path is loaded.
43
58
  */
44
- const fetchCSSFiles = () => {
59
+ const fetchCSSFiles = async (parameters = {}) => {
45
60
  try {
46
- // Load all CSS files from 'dist'.
47
- const cssFiles = require.context('../../../../dist', true, /\.css$/);
48
- cssFiles.keys().forEach((file) => cssFiles(file));
61
+ if (!getLoadAllCSS(parameters)) {
62
+ return undefined;
63
+ }
64
+
65
+ const adapter = getStorybookPlatformAdapter();
49
66
 
50
- // Load all CSS files from 'components' for 'drupal' platform.
51
- if (emulsifyConfig.project.platform === 'drupal') {
52
- const drupalCSSFiles = require.context(
53
- '../../../../components',
54
- true,
55
- /\.css$/,
56
- );
57
- drupalCSSFiles.keys().forEach((file) => drupalCSSFiles(file));
67
+ if (adapter.loadMirroredComponentCss) {
68
+ await import('./css-components.js');
69
+ return undefined;
58
70
  }
71
+
72
+ await import('./css-dist.js');
73
+ return undefined;
59
74
  } catch {
60
75
  return undefined;
61
76
  }
@@ -68,36 +83,16 @@ const fetchCSSFiles = () => {
68
83
  * @returns {string|undefined} Project machine name string, or undefined if not available
69
84
  */
70
85
  export function getProjectMachineName() {
71
- try {
72
- return emulsifyConfig.project.machineName;
73
- } catch {
74
- return undefined;
75
- }
86
+ return typeof emulsifyEnv.machineName === 'string'
87
+ ? emulsifyEnv.machineName
88
+ : undefined;
76
89
  }
77
90
 
78
- // Build namespaces mapping.
79
- export const namespaces = Object.fromEntries(
80
- fetchVariantConfig().map(({ name, directory }) => [
81
- name,
82
- resolve(_dirname, '../../../../', directory),
83
- ]),
84
- );
85
-
86
- /**
87
- * Configures and extends a standard Twig object.
88
- *
89
- * @param {Object} twig - Twig object that should be configured and extended.
90
- * @returns {Object} Configured Twig object.
91
- */
92
- export function setupTwig(twig) {
93
- twig.cache();
94
- twigDrupal(twig);
95
- twigBEM(twig);
96
- twigAddAttributes(twig);
97
- twigInclude(twig);
98
- twigSource(twig);
99
- return twig;
100
- }
101
-
102
- // Export the fetchCSSFiles function.
103
- export { fetchCSSFiles };
91
+ // Keep these named exports stable for preview.js and downstream overrides.
92
+ export {
93
+ attachStorybookBehaviors,
94
+ fetchCSSFiles,
95
+ genericStorybookAdapter,
96
+ normalizeStorybookPlatformAdapter,
97
+ setupTwig,
98
+ };
package/README.md CHANGED
@@ -4,93 +4,144 @@
4
4
 
5
5
  An open-source toolset for creating and implementing design systems.
6
6
 
7
- **Emulsify Core** provides a [Storybook](https://storybook.js.org/) component library and a [Webpack](https://webpack.js.org/) development environment. It is meant to make project setup and ongoing development easier by bundling all necessary configuration and providing it as an extendable package for your theme or standalone project.
7
+ **Emulsify Core** provides shared [Vite](https://vite.dev/) build configuration and a [Storybook](https://storybook.js.org/) component library setup for component-driven development. Twig-based components and React components are both supported authoring models. A project can be Twig-first, React-first, or intentionally mixed.
8
8
 
9
- ## Installation and usage
10
- Installation and configuration is setup by the provided base theme project(s). As of this writing, Emulsify Drupal is the only base theme project [with this integration](https://github.com/emulsify-ds/emulsify-drupal/blob/main/whisk/package.json#L36).
9
+ ## How Emulsify Core Works
11
10
 
12
- ### Manual installation
13
- - `npm install @emulsify/core` within your repository or project theme.
14
- - Copy the provided `npm run` scripts from [Emulsify Drupal's package.json](https://github.com/emulsify-ds/emulsify-drupal/blob/main/whisk/package.json#L15)
15
- - Copy the contents of `whisk/config/emulsify-core/` from [Emulsify Drupal](https://github.com/emulsify-ds/emulsify-drupal/tree/main/whisk/config/emulsify-core) into your project so `config/` exists at the root of your repository or project theme. The files within `config/` allow you to extend or overwrite configuration provided by Emulsify Core.
11
+ - Vite builds project JavaScript, Sass/CSS, Twig templates, component metadata, and static component assets.
12
+ - Storybook uses the React/Vite framework.
13
+ - Twig files can render in React-based Storybook through `renderTwig()`.
14
+ - React components render through Storybook's React/Vite support.
15
+ - Twig and React stories can coexist in the same Storybook instance.
16
+ - `project.emulsify.json` is the source of truth for platform and structure configuration.
17
+ - Platform-specific behavior is controlled by adapters instead of being assumed globally.
18
+ - Node.js 24 or later is required.
16
19
 
17
- ### Common Scripts
20
+ ## Project Evolution
18
21
 
19
- Run `nvm use` prior to running any of the following commands to verify you are using Node 20.
20
- (Each is prefixed with `npm run `)
22
+ Emulsify Core has grown through each major release while keeping the same practical goal: make component-library tooling easier to share across real projects.
21
23
 
22
- **develop**
23
- Starts and instance of storybook, watches for any files changes, recompiles CSS/JS, and live reloads storybook assets.
24
+ - `1.x` established Emulsify Core as a reusable package for Storybook, Webpack, linting, a11y checks, project overrides, and asset handling.
25
+ - `2.x` expanded component structure support, improved Drupal SDC compatibility, upgraded Storybook, and made more project files configurable from consuming projects.
26
+ - `3.x` modernized the runtime around ESM and Node 24, continued Storybook and dependency upgrades, improved component asset copying, and strengthened compatibility for existing Drupal-oriented builds.
27
+ - The current release moves the build system to Vite, runs Storybook on React/Vite, supports Twig and React stories side by side, and normalizes platform and project-structure behavior through `project.emulsify.json`.
24
28
 
25
- **lint**
26
- Lints all JS/SCSS within your components and reports any violations.
29
+ The latest version is the next evolution of that work: faster builds, clearer public APIs, less global Drupal assumption, and a broader foundation for CMS themes, standalone UI libraries, and mixed component systems.
27
30
 
28
- **lint-fix**
29
- Automatically fixes any simple violations.
31
+ See [Version Evolution](docs/version-evolution.md) for more release history.
30
32
 
31
- **prettier**
32
- Outputs any code formatting violations.
33
+ ## Authoring Models
33
34
 
34
- **prettier-fix**
35
- Automatically fixes any simple code formatting violations.
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
- **storybook-build**
38
- Builds a static output of the storybook instance.
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 generic adapter unless a project adds platform-specific behavior.
38
+ - Use React for standalone UI libraries, application components, or projects that already use React.
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.
39
40
 
41
+ See [Component Authoring](docs/component-authoring.md) for Twig, React, mixed Storybook, and shared Sass examples.
40
42
 
41
- ### Quick Links
43
+ ## Basic Usage
42
44
 
43
- - [Emulsify Homepage](https://www.emulsify.info/)
45
+ Installation and project scripts are usually provided by a starter or platform integration. Manual setup starts with:
44
46
 
45
- ## Demo
47
+ ```sh
48
+ npm install @emulsify/core
49
+ ```
46
50
 
47
- 1. [Storybook](http://storybook.emulsify.info/)
51
+ Every project should provide a `project.emulsify.json` file at the project root:
48
52
 
49
- ## Contributing
53
+ ```json
54
+ {
55
+ "project": {
56
+ "platform": "generic",
57
+ "name": "example",
58
+ "machineName": "example"
59
+ }
60
+ }
61
+ ```
50
62
 
51
- ### [Code of Conduct](https://github.com/emulsify-ds/emulsify-drupal/blob/master/CODE_OF_CONDUCT.md)
63
+ Common project scripts call the shared Emulsify Core Vite and Storybook config:
52
64
 
53
- The project maintainers have adopted a Code of Conduct that we expect project participants to adhere to. Please read the full text so that you can understand what actions will and will not be tolerated.
65
+ - `storybook`: starts Storybook development.
66
+ - `storybook-build`: builds static Storybook output.
67
+ - `build`: runs the Vite build for JS, CSS, copied Twig templates, component metadata, and static component assets.
68
+ - `lint`: lints maintained project source.
54
69
 
55
- ### Contribution Guide
70
+ ## Documentation
56
71
 
57
- Please also follow the issue template and pull request templates provided. See below for the correct places to post issues:
72
+ The documentation is split by task:
58
73
 
59
- 1. [Emulsify Drupal](https://github.com/emulsify-ds/emulsify-drupal/issues)
60
- 2. [Emulsify Twig Extensions](https://github.com/emulsify-ds/emulsify-twig-extensions/issues)
61
- 3. [Emulsify Tools (Drupal module)](https://www.drupal.org/project/issues/emulsify_tools)
74
+ | Topic | Use This When |
75
+ | --------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
76
+ | [Version Evolution](docs/version-evolution.md) | Understanding how Emulsify Core has evolved across major releases. |
77
+ | [Component Authoring](docs/component-authoring.md) | Choosing Twig, React, or mixed Storybook authoring and comparing component examples. |
78
+ | [Storybook](docs/storybook.md) | Rendering Twig stories, using `renderTwig()`, understanding Twig runtime helpers, and mixing Twig with React stories. |
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 `generic`, `drupal`, platform resolution order, and Drupal SDC behavior. |
81
+ | [Extension Points](docs/extension-points.md) | Adding Vite plugins, Tailwind CSS, Storybook preview overrides, and other framework tooling. |
82
+ | [Performance](docs/performance.md) | Understanding sourcemaps, eager Twig imports, Tailwind scanning, copied files, and fixture validation. |
83
+ | [Native Twig Extensions](docs/native-twig-extensions.md) | Using `bem()`, `add_attributes()`, and `switch/case/default/endswitch` in Twig.js. |
84
+ | [Release Verification](docs/release.md) | Running 4.x release checks, tarball smoke tests, and semantic-release dry runs before publishing. |
85
+ | [Migration](docs/migration-4x.md) | Upgrading from earlier versions while preserving existing structures. |
62
86
 
63
- ### Committing Changes
87
+ ## Known Limitations
64
88
 
65
- To facilitate automatic semantic release versioning, we utilize the [Conventional Changelog](https://github.com/conventional-changelog/conventional-changelog) standard through Commitizen. Follow these steps when commiting your work to ensure semantic release can version correctly.
89
+ - Implemented platform adapters are currently `generic` and `drupal`. WordPress + Timber and Craft CMS are supported as Twig-oriented use cases through the generic adapter today; dedicated adapters are future opportunities. See [Platform Adapters](docs/platform-adapters.md).
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
+ - Production sourcemaps are enabled by default unless a project overrides Vite config through `config/emulsify-core/vite/plugins.*`. See [Performance](docs/performance.md).
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
+ - 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. Generic projects should expect output to remain in `dist/`. See [Platform Adapters](docs/platform-adapters.md).
66
95
 
67
- 1. Stage your changes, ensuring they encompass exactly what you wish to change, no more.
68
- 2. Run the `commit` script via `yarn commit` or `npm run commit` and follow the prompts to craft the perfect commit message.
69
- 3. Your commit message will be used to create the changelog for the next version that includes that commit.
96
+ ## Supported Project Shapes
70
97
 
71
- ## Author
98
+ Release-readiness coverage validates:
72
99
 
73
- Emulsify&reg; is a product of [Four Kitchens](https://fourkitchens.com).
100
+ - Drupal SDC projects using `src/components`.
101
+ - Generic Twig projects using `src/components`.
102
+ - Root `./components` projects.
103
+ - Projects using multiple `variant.structureImplementations`.
104
+ - Mixed Twig + React Storybook projects.
74
105
 
75
- ## Contributors
106
+ WordPress + Timber and Craft CMS are Twig-based project use cases that can use the `generic` adapter today. Dedicated adapters for those platforms are future opportunities. The implemented adapters in this package are currently `generic` and `drupal`.
76
107
 
77
- <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
78
- <!-- prettier-ignore-start -->
79
- <!-- markdownlint-disable -->
80
- <table>
81
- <tbody>
82
- <tr>
83
- <td align="center" valign="top" width="16.66%"><a href="https://github.com/callinmullaney"><img src="https://avatars.githubusercontent.com/u/369018?v=4?s=100" width="100px;" alt="Callin Mullaney"/><br /><sub><b>Callin Mullaney</b></sub></a><br /><a href="https://github.com/fourkitchens/emulsify-core/commits?author=callinmullaney" title="Code">💻</a> <a href="https://github.com/fourkitchens/emulsify-core/commits?author=callinmullaney" title="Documentation">📖</a></td>
84
- <td align="center" valign="top" width="16.66%"><a href="https://github.com/amazingrando"><img src="https://avatars.githubusercontent.com/u/409903?v=4?s=100" width="100px;" alt="Randy Oest"/><br /><sub><b>Randy Oest</b></sub></a><br /><a href="https://github.com/fourkitchens/emulsify-core/commits?author=amazingrando" title="Code">💻</a> <a href="https://github.com/fourkitchens/emulsify-core/commits?author=amazingrando" title="Documentation">📖</a></td>
85
- <td align="center" valign="top" width="16.66%"><a href="https://github.com/robherba"><img src="https://avatars.githubusercontent.com/u/9342274?v=4?s=100" width="100px;" alt="Roberto Hernandez"/><br /><sub><b>Roberto Hernandez</b></sub></a><br /><a href="https://github.com/fourkitchens/emulsify-core/commits?author=robherba" title="Code">💻</a></td>
86
- <td align="center" valign="top" width="16.66%"><a href="https://github.com/dependabot"><img src="https://avatars.githubusercontent.com/u/49699333?v=4?s=100" width="100px;" alt="Dependabot"/><br /><sub><b>Dependabot</b></sub></a><br /><a href="#maintenance-dependabot" title="Maintenance">🚧</a></td>
87
- </tr>
88
- </tbody>
89
- </table>
108
+ ## Public Imports
109
+
110
+ Emulsify Core exposes stable public package paths:
111
+
112
+ ```js
113
+ import { renderTwig } from '@emulsify/core/storybook';
114
+ import { registerTwigExtensions } from '@emulsify/core/extensions/twig';
115
+ import { defineReactExtension } from '@emulsify/core/extensions/react';
116
+ ```
117
+
118
+ `defineReactExtension` is reserved for future React extension support. It currently returns the input unchanged. Adopting the import path is safe; the runtime is intentionally a no-op until the registry lands. See [Extension Points](docs/extension-points.md#public-imports).
119
+
120
+ Vite consumers can import the shared config from `@emulsify/core/vite` and public Vite plugin helpers from `@emulsify/core/vite/plugins`.
121
+
122
+ ## Contributing
90
123
 
91
- <!-- markdownlint-restore -->
92
- <!-- prettier-ignore-end -->
124
+ Maintained JavaScript source, config, scripts, and tests should use consistent comments:
93
125
 
94
- <!-- ALL-CONTRIBUTORS-LIST:END -->
126
+ - Start each maintained JS file with a short JSDoc file block that explains the file's responsibility.
127
+ - Use JSDoc blocks for exported functions, complex helpers, and public contracts.
128
+ - Use `//` comments for local intent, compatibility behavior, and non-obvious edge cases.
129
+ - Keep comments concise and factual. Prefer explaining why behavior exists instead of restating the code.
130
+ - Use YAML or shell comments in workflow, hook, and fixture files where the format supports comments.
95
131
 
96
- This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
132
+ Do not add comments to JSON files, lockfiles, binary assets, generated output, legal documents, or dependency files. Those formats either do not support comments or should remain exact artifacts.
133
+
134
+ Please also follow the issue template and pull request templates provided. See below for the correct places to post issues:
135
+
136
+ 1. [Emulsify Drupal](https://github.com/emulsify-ds/emulsify-drupal/issues)
137
+ 2. [Emulsify Tools (Drupal module)](https://www.drupal.org/project/issues/emulsify_tools)
138
+
139
+ ## Links
140
+
141
+ - [Emulsify Homepage](https://www.emulsify.info/)
142
+ - [Storybook Demo](http://storybook.emulsify.info/)
143
+ - [Code of Conduct](https://github.com/emulsify-ds/emulsify-drupal/blob/master/CODE_OF_CONDUCT.md)
144
+
145
+ ## Author
146
+
147
+ Emulsify&reg; is a product of [Four Kitchens](https://fourkitchens.com).
@@ -1,10 +1,6 @@
1
1
  {
2
- "extends": [
3
- "stylelint-config-standard-scss"
4
- ],
5
- "plugins": [
6
- "stylelint-prettier"
7
- ],
2
+ "extends": ["stylelint-config-standard-scss"],
3
+ "plugins": ["stylelint-prettier"],
8
4
  "customSyntax": "postcss-scss",
9
5
  "rules": {
10
6
  "at-rule-empty-line-before": [