Skip to content

Commit

Permalink
feat: rename kit to recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
callinmullaney committed Aug 31, 2023
1 parent 1b1ff61 commit afcd432
Show file tree
Hide file tree
Showing 34 changed files with 120 additions and 454 deletions.
78 changes: 40 additions & 38 deletions emulsify.drush.inc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function emulsify_drush_command() {
'machine_name' => 'The machine-readable name of your subtheme. This will be auto-generated from the human-readable name if ommited.',
'description' => 'The description of your subtheme',
'path' => 'The destination of your subtheme. Defaults to "all" (themes).',
'kit' => 'The name or url of the starter kit to use. Defaults to "whisk".',
'recipe' => 'The name or url of the starter recipe to use. Defaults to "whisk".',
],
'examples' => [
'drush emulsify "Whisk"' => 'Creates a Emulsify subtheme called "Whisk", using the default options.',
Expand Down Expand Up @@ -82,73 +82,73 @@ function drush_emulsify($name = NULL, $machine_name = NULL) {
$subtheme_path = drush_trim_path($path);
}

// Determine the kit to use.
$kit = (drush_get_option('kit')) ? drush_trim_path(drush_get_option('kit')) : 'whisk';
// Determine the recipe to use.
$recipe = (drush_get_option('recipe')) ? drush_trim_path(drush_get_option('recipe')) : 'whisk';

drush_emulsify_create($name, $machine_name, $description, $subtheme_path, $kit);
drush_emulsify_create($name, $machine_name, $description, $subtheme_path, $recipe);
}

/**
* Create frontend theme.
*/
function drush_emulsify_create($name, $machine_name, $description, $subtheme_path, $kit) {
function drush_emulsify_create($name, $machine_name, $description, $subtheme_path, $recipe) {
$subtheme_path = drush_normalize_path(drush_get_context('DRUSH_DRUPAL_ROOT') . '/' . $subtheme_path . '/' . $machine_name);

// Make a fresh copy of the kit.
$kit_path = drush_normalize_path(drush_get_context('DRUSH_DRUPAL_ROOT') . '/' . drupal_get_path('theme', 'emulsify') . '/kits/' . $kit);
// Make a fresh copy of the recipe.
$recipe_path = drush_normalize_path(drush_get_context('DRUSH_DRUPAL_ROOT') . '/' . drupal_get_path('theme', 'emulsify') . '/recipes/' . $recipe);

if (!is_dir(dirname($subtheme_path))) {
drush_die(dt('The directory "!directory" was not found.', ['!directory' => dirname($subtheme_path)]));
}
drush_op('drush_copy_dir', $kit_path, $subtheme_path);
drush_op('drush_copy_dir', $recipe_path, $subtheme_path);

// Alter the contents of the .info file based on the command options.
$alterations = [
'EMULSIFY_KIT_NAME' => $name,
'EMULSIFY_KIT_DESCRIPTION' => $description,
'emulsify_kit' => $machine_name,
'EMULSIFY_RECIPE_NAME' => $name,
'EMULSIFY_RECIPE_DESCRIPTION' => $description,
'emulsify_recipe' => $machine_name,
'hidden: true' => '',
];

// Replace all occurrences of '{{machine_name}}' with the machine name of our
// sub theme.
$files_to_replace = emulsify_get_files_to_make_replacements($kit);
$files_to_replace = emulsify_get_files_to_make_replacements($recipe);
foreach ($files_to_replace as $file_to_replace) {
drush_op('emulsify_file_str_replace', $subtheme_path . '/' . $file_to_replace, array_keys($alterations), $alterations);
}

// Rename files.
$files_to_rename = [
'{{kit}}.info.yml',
'{{kit}}.libraries.yml',
'{{kit}}.breakpoints.yml',
'{{kit}}.theme',
'dev/scss/{{kit}}.scss',
'dev/js/{{kit}}.js',
'config/schema/{{kit}}.schema.yml',
'{{recipe}}.info.yml',
'{{recipe}}.libraries.yml',
'{{recipe}}.breakpoints.yml',
'{{recipe}}.theme',
'dev/scss/{{recipe}}.scss',
'dev/js/{{recipe}}.js',
'config/schema/{{recipe}}.schema.yml',
];

foreach ($files_to_rename as $file_to_rename_path) {
$file_original_path = $subtheme_path . '/' . str_replace('{{kit}}', $kit, $file_to_rename_path);
$file_new_path = $subtheme_path . '/' . str_replace('{{kit}}', $machine_name, $file_to_rename_path);
$file_original_path = $subtheme_path . '/' . str_replace('{{recipe}}', $recipe, $file_to_rename_path);
$file_new_path = $subtheme_path . '/' . str_replace('{{recipe}}', $machine_name, $file_to_rename_path);
drush_op('rename', drush_normalize_path($file_original_path), drush_normalize_path($file_new_path));
}

// Batch rename all config files.
$includes_path = $subtheme_path . '/config/optional/*.yml';
foreach (glob($includes_path) as $file_to_rename_path) {
$file_new_path = str_replace($kit, $machine_name, $file_to_rename_path);
$file_new_path = str_replace($recipe, $machine_name, $file_to_rename_path);
drush_op('rename', drush_normalize_path($file_to_rename_path), drush_normalize_path($file_new_path));
drush_op('emulsify_file_str_replace', $file_new_path, array_keys($alterations), $alterations);
}

// Notify user of the newly created theme.
$message = 'Successfully created the Emulsify subtheme "!name" created in: !path using the "!kit" kit';
$message = 'Successfully created the Emulsify subtheme "!name" created in: !path using the "!recipe" recipe';

$message = dt($message . '.', [
'!name' => $name,
'!path' => $subtheme_path,
'!kit' => $kit,
'!recipe' => $recipe,
]);
drush_print($message);
}
Expand All @@ -164,22 +164,24 @@ function emulsify_file_str_replace($file_path, $find, $replace) {
}

/**
* Returns an array of files to make string replacements. Based on kit chosen.
* Returns an array of files to make string replacements. Based on recipe chosen.
*/
function emulsify_get_files_to_make_replacements($kit) {
function emulsify_get_files_to_make_replacements($recipe) {
return [
'config/install/' . $kit . '.settings.yml',
'config/schema/' . $kit . '.schema.yml',
'dev/scss/' . $kit . '.scss',
'dev/js/' . $kit . '.js',
'dev/bower.json',
'dev/gulpfile.js',
'dev/package.json',
'dev/config/config.json',
$kit . '.info.yml',
$kit . '.libraries.yml',
$kit . '.breakpoints.yml',
$kit . '.theme',
'.cli/init.js',
'assets/fonts/.gitkeep',
'assets/icons/.gitkeep',
'assets/images/.gitkeep',
'components/.gitkeep',
'config/install/' . $recipe . '.settings.yml',
'config/schema/' . $recipe . '.schema.yml',
'dist/css/.gitkeep',
'dist/js/.gitkeep',
'templates/layout/page.html.twig',
$recipe . '.info.yml',
$recipe . '.libraries.yml',
$recipe . '.breakpoints.yml',
$recipe . '.theme',
'README.md',
];
}
7 changes: 0 additions & 7 deletions kits/whisk/.gitignore

This file was deleted.

95 changes: 0 additions & 95 deletions kits/whisk/config/dev/.eslintrc

This file was deleted.

Loading

0 comments on commit afcd432

Please sign in to comment.