Upgrading
An existing Emulsify starter theme (storybook) can be updated to a subtheme utilizing Emulsify Core by performing the following:
Scenario: Existing Drupal Project/Theme
- Install the base theme:
composer require drupal/emulsify
- Enable the base theme and it's helper module:
drush pm:enable emulsify_tools && drush theme:enable emulsify
- Uninstall the existing theme:
drush theme:uninstall [theme_name]
- [OPTIONAL] If you wish to keep the existing theme's name, then rename the old theme directory to something else (e.g.,
THEMENAME_old
) and rename the old theme's info.yml file as well (e.g.,THEMENAME_old.info.yml
)
- [OPTIONAL] If you wish to keep the existing theme's name, then rename the old theme directory to something else (e.g.,
- Generate an Emulsify subtheme:
drush emulsify [theme_name]
- Copy your
components/
directory from the old theme into the new theme directory. - Review the old theme's
package.json
for any customizations or additional packages/libraries. Compare this to Emulsify Core'spackage.json
file to help determine packages/libraries not part of the base installation. - Review the following files within your old theme and compare them to Emulsify Core's shipped configuration. If there are any customizations that need to carry forward you can extend/overwrite Emulsify Core's configuration by modifying your new theme's configuration within
[new theme]/config/emulsify-core
. - Verify the component structure defined in
project.emulsify.json
matches yourcomponents/
directory. - Delete the
node_modules/
directory if it exists. - Run
npm install
and verify all the scripts still run without errors.
Scenario: Standalone Project
If your instance of Emulsify lives outside of Drupal, you can do an in-place upgrade.
Tooling and custom configuration
All tooling and configuration has been moved to Emulsify Core in an effort to simplify your component library and provide an easier update workflow. This means there is a lot of additional files that are no longer needed post-update. Perform the following steps to remove files/configuration that are no longer needed and refactor any configuration customizations.
- Edit
.nvmrc
and change the version to20
- From the root of your project create a
config/
directory that can extend/overwrite Emulsify Core configurationgit clone -b main https://github.com/emulsify-ds/emulsify-drupal.git && cd emulsify-drupal && git sparse-checkout set --no-cone whisk && mv whisk/config .. && cd .. && rm -rf emulsify-drupal
- Review the existing files and compare them to their corresponding Emulsify Core implementation. Make note of any customization that need to carry forward:
.eslintrc.yml
compared to https://github.com/emulsify-ds/emulsify-core/blob/main/config/eslintrc.config.json.prettierignore
compared to https://github.com/emulsify-ds/emulsify-drupal/blob/main/whisk/config/emulsify-core/.prettierignore.prettierrc.json
compared to https://github.com/emulsify-ds/emulsify-core/blob/main/config/.prettierrc.json.storybook/emulsifyTheme.js
compared to https://github.com/emulsify-ds/emulsify-core/blob/main/.storybook/emulsifyTheme.js.stylelintrc.json
compared to https://github.com/emulsify-ds/emulsify-core/blob/main/config/.stylelintrc.jsona11y.config.js
compared to https://github.com/emulsify-ds/emulsify-core/blob/main/config/a11y.config.jsbabel.config.js
compared to https://github.com/emulsify-ds/emulsify-core/blob/main/config/babel.config.jsjest.config.js
compared to https://github.com/emulsify-ds/emulsify-core/blob/main/config/jest.config.jspostcss.config.js
compared to https://github.com/emulsify-ds/emulsify-core/blob/main/config/postcss.config.js
- If there are any customizations from step #2 that you want to carry forward you can now modify the corresponding files within
config/emulsify-core/
- Remove the following files from your project
.eslintignore
.eslintrc.yml
.prettierignore
.storybook/
.stylelintignore
.stylelintrc
a11y.config.js
babel.config.js
emulsify.php
jest.config.js
postcss.config.js
util/
Moving assets
As of version 4.7.0
all theme icons, images, fonts, ...etc have been moved to the assets/
directory. Verify this directory exists and houses the previously mentioned folders.
assets/icons
assets/images
assets/fonts
Update scripts and packages
The package.json
will likely see the most changes to your project due to all project dependencies and their versions now being added via Emulsify Core.
- Review the
package.json
file and make note of any custom"scripts": {
added to your project. Compare this to https://github.com/emulsify-ds/emulsify-drupal/blob/main/whisk/package.json#L15 to reference. - Copy all scripts from https://github.com/emulsify-ds/emulsify-drupal/blob/main/whisk/package.json#L15 into your own
package.json
and add any customizations previously identified. - Review the
"dependencies": {
in yourpackage.json
and compare them to https://github.com/emulsify-ds/emulsify-core/blob/main/package.json#L38. Make note of any additional packages your project may have. The version numbers for matching packages can be ignored as Emulsify Core will install the ideal version. - Remove all dependencies (except addition packages identified in step 3) and replace with
"emulsify-core": "github:emulsify-ds/emulsify-core"
. For most projectsgithub:emulsify-ds/emulsify-core
will be the only listed dependency. - Review and verify all your
devDependencies
are still relevant and in use. Update them to a version that is compatible with Node 20. This may result in additional configuration changes required for your specific project. - Delete the
node_modules/
directory if it exists. - Run
npm install
and verify all the scripts still run without errors.
Scenario: Upgrading from Pattern Lab
Early versions of Emulsify used Pattern Lab to organize and build components. Since September of 2020 Emulsify has moved to Storybook. Follow the steps below to refactor your old project and upgrade to the latest version of Emulsify.
Required Steps
- Disable old theme
- Rename old theme directory to something else (e.g.,
THEMENAME_old
) and rename the old theme's info.yml file as well (e.g.,THEMENAME_old.info.yml
) - Follow Drupal installation instructions (be sure and use your old name and machine name in the php script, e.g.,
php emulsify.php "THEME NAME" --machine-name THEME_NAME
- Replace contents of the new theme's
components
directory with your old theme'scomponents/_patterns
contents (if you don't want to have a lot of path changes you can keep them in the_patterns
subdirectory). Be sure and change any library paths in style.scss, like so:
// Old @import "normalize"; @import "breakpoint-sass/stylesheets/breakpoint" // New @import "~normalize.css/normalize"; @import "~breakpoint-sass/stylesheets/breakpoint";
- Move any static contents (e.g.,
images
directory) into the new theme.\ - Copy over Drupal files (you may need to fix paths later):
*.theme *.breakpoints.yml *.info.yml *.libraries.yml
- Disable/uninstall/remove the unified_twig_extensions module, and enable the new emulsify_twig module.\
- Enable new theme in Drupal\
- Run
composer remove fourkitchens/emulsify
\ - Run
npm run develop
.
Optional Steps (depending on your installation)
- Move any custom references inside
custom/old_theme/components/_meta/_00-head|_01-foot.twig
into.storybook/preview-head.html
(see Storybook docs for details) and fix any reference paths. An example of this might be as follows:
<!-- Old _00-head.twig --> <link rel="stylesheet" href="../../js/slick/slick.css?{{ cacheBuster }}" media="all" /> <script src="../../js/slick/slick.min.js"></script> <!-- New preview-head.html --> <link rel="stylesheet" href="../js/slick/slick.css?{{ cacheBuster }}" media="all" /> <script src="../js/slick/slick.min.js"></script>
To complete the step above, you would add this js
directory to the Storybook command in package.json like:
"storybook": "start-storybook -s ./dist, ./images, ./js -p 6006", "build-storybook": "build-storybook -s ./dist, ./images, ./js -o .out",
- You may need to copy over new Emulsify styles, e.g. for the colors.
Writing Stories
Storybook only loads the stories you tell it to, so you will need to create *.stories.js files. We have multiple examples in the new starter including ones using complex Twig includes, sharing data across components and using JavaScript (see usage details).
Data
Data can still be handled via YML (preferred) or JSON files. However, you will need to handle any global data files differently (see usage instructions) as the new setup pays no attention automatically to the old /components/_data
directory.