Update update script to automatically find CivicTheme directory

Created on 31 March 2025, 26 days ago

Problem/Motivation

1. We hardcode the relative link from sub-theme to civictheme based on civictheme directory structure: `https://github.com/civictheme/monorepo-drupal/blob/080b05c537678d7a50580...
2. It would be great if we could update this as part of two things:
a. storybook update script (and future update scripts
b. civictheme starter script - we need to update this when we create the sub-theme

Steps to reproduce

Proposed resolution

1. Create a dynamic lookup or configuration step to get the civictheme directory
2. Update civictheme starter script to update the link in the JS to be updated when sub-theme is built

🐛 Bug report
Status

Active

Version

1.10

Component

Code

Created by

🇦🇺Australia RichardGaunt Melbourne

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @RichardGaunt
  • 🇦🇺Australia RichardGaunt Melbourne
  • 🇦🇺Australia alan.cole

    As this is to resolve an issue with the build script where it's unable to find the civictheme path, rather than hard-code a path in as part of the update script, we could resolve the path at runtime within the build script.

    Example:

    const DIR_CIVICTHEME            = getCivicthemeDir(PATH)
    
    // ...
    
    function getCivicthemeDir(subthemeDir) {
      let currentDir = subthemeDir
      while (currentDir !== path.parse(currentDir).root) {
        if (path.parse(currentDir).name === 'themes') {
          const civicthemePath = globSync(currentDir + '/**/civictheme').pop()
          if (fs.existsSync(civicthemePath) && fs.lstatSync(civicthemePath).isDirectory()) {
            return path.relative(civicthemePath, subthemeDir)
          }
        }
        currentDir = path.dirname(currentDir)
      }
      errorReporter('Could not find civictheme directory.')
    }
    
  • 🇦🇺Australia alan.cole

    2 PRs have been raised to update the drupal and UI Kit:

    1. This script update provides a way for subthemes to automatically find the civictheme base class, assuming that the subtheme and base theme both live in the themes folder in Drupal.
    2. This change was needed because the location of the civictheme base class can be different per implementation. Some projects use /contrib/ and /custom/, some put all themes in the same parent directory.
    3. If the parent theme is expected to live in a vastly different directory, the base theme class can still be set manually, e.g.

    const DIR_CIVICTHEME = config.base ? null : `/any/directory/path/civictheme`

    1. This change also implements a few more checks for config.base ? null : ... for other variables. This is because some variables are only required if building for subtheme. This change, as well as avoiding setting variables that aren't required, also makes it clearer which variables are not used with the base theme.
Production build 0.71.5 2024