Skip to content

Instantly share code, notes, and snippets.

@miloskroulik
Last active February 15, 2024 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miloskroulik/1e354f298f08c04cb98a78b60c33724c to your computer and use it in GitHub Desktop.
Save miloskroulik/1e354f298f08c04cb98a78b60c33724c to your computer and use it in GitHub Desktop.
Subtheme of Radix subtheme post-processing
<?php
namespace Drupal\hd_radix;
use Drupal\Core\Theme\StarterKitInterface;
use Symfony\Component\Filesystem\Filesystem;
final class StarterKit implements StarterKitInterface {
const HD_RADIX_RELATIVE_PATH = '../hd_radix';
/**
* {@inheritdoc}
*/
public static function postProcess(string $working_dir, string $machine_name, string $theme_name): void {
self::removeBuiltAssets($working_dir,$machine_name);
self::symlinkNodeModules($working_dir, $machine_name);
self::importSCSSAssets($working_dir, $machine_name);
}
/**
* Delete copied node_modules directory and replace it with symlinkfrom hd_radix
*
* @param string $working_dir
* @param string $machine_name
*
* @return void
*/
private static function symlinkNodeModules(string $working_dir, string $machine_name) {
$fs = new Filesystem();
$fs->remove("{$working_dir}/node_modules");
$fs->symlink( self::HD_RADIX_RELATIVE_PATH ."/node_modules", "{$working_dir}/node_modules");
}
/**
* Delete built assets copied from hd_radix
*
* @param string $working_dir
* @param string $machine_name
*
* @return void
*/
private static function removeBuiltAssets(string $working_dir, string $machine_name) {
$fs = new Filesystem();
$fs->remove("{$working_dir}/build");
}
/**
* Add import statement to the top of base SCSS files
*
* @param string $working_dir
* @param string $machine_name
*
* @return void
*/
private static function importSCSSAssets(string $working_dir, string $machine_name) {
$fs = new Filesystem();
$base_scss_path = "src/scss/base";
$base_files = [
'elements',
'functions',
'helpers',
'mixins',
'typography',
'utilities'
];
foreach ($base_files as $base_file) {
$content = "\n@import \"../../../" . self::HD_RADIX_RELATIVE_PATH . "/{$base_scss_path}/{$base_file}\";";
$fs->appendToFile("{$working_dir}/{$base_scss_path}/_{$base_file}.scss",$content);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment