Skip to content

Commit 6b53aaf

Browse files
authored
Add 'xb-dev-extras' command. (#26)
1 parent 8c4035d commit 6b53aaf

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

commands/web/xb-dev-extras

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
3+
## #ddev-generated
4+
## Description: Add some convenience extras for development.
5+
## Usage: xb-dev-extras
6+
## Example: ddev xb-dev-extras\nddev xb-dev-extras --dry-run
7+
## Aliases: extras
8+
## Flags: [{"Name":"dry-run","Usage":"Show what the command will do if run"}]
9+
10+
# If the '--dry-run' flag is passed, show what the command would do and then exit.
11+
if [[ "$1" == "--dry-run" ]]; then
12+
echo "This command will...
13+
1. Install the following modules:
14+
- Admin Toolbar (admin_toolbar)
15+
- Admin Toolbar (admin_toolbar_tools)
16+
- Coffee (coffee)
17+
- \"All-Props\" Test SDC (sdc_test_all_props)
18+
2. Create a test page at '/test'."
19+
exit 0
20+
fi
21+
22+
# Add the modules to the codebase.
23+
composer require \
24+
--no-interaction \
25+
drupal/admin_toolbar \
26+
drupal/admin_toolbar_tools \
27+
drupal/coffee
28+
29+
# Install the modules in Drupal.
30+
drush en -y \
31+
admin_toolbar \
32+
admin_toolbar_tools \
33+
coffee \
34+
sdc_test_all_props
35+
36+
# Create a test page. Note: If any more PHP code is added here, it should be
37+
# extracted to its own file. Writing it this way is clumsy, to say the least.
38+
drush php:eval "
39+
\$alias = '/test';
40+
\$path_alias_repository = \Drupal::service('path_alias.repository');
41+
42+
// See if the test page already exists and exit if so. (Just checking for
43+
// the path alias is naive, but it will suffice for our purposes.
44+
if (\$path_alias_repository->lookupByAlias(\$alias, 'en')) {
45+
echo 'The test page already exists.' . PHP_EOL;
46+
return;
47+
}
48+
49+
// Create the xb_page entity.
50+
\Drupal::service('entity_type.manager')
51+
->getStorage('xb_page')
52+
->create([
53+
'title' => 'XB 💫',
54+
'description' => 'This is an XB page.',
55+
'path' => ['alias' => \$alias],
56+
])->save();
57+
58+
echo 'The test page has been created.' . PHP_EOL;
59+
"

install.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ project_files:
1111
- commands/host/xb-static
1212
- commands/web/xb-autosave
1313
- commands/web/xb-core-set-version
14+
- commands/web/xb-dev-extras
1415
- commands/web/xb-eslint
1516
- commands/web/xb-phpcs
1617
- commands/web/xb-phpstan
@@ -47,4 +48,6 @@ post_install_actions:
4748
rm -f "$FILE"
4849
done
4950
50-
- echo "‼️ If you're setting up this add-on for the first time on this project, finish installation by running 'ddev xb-setup'"
51+
- |
52+
echo "‼️ If you're setting up this add-on for the first time on this project, finish installation by running 'ddev xb-setup'."
53+
echo "💡 To set up optional extras for development, run 'ddev xb-dev-extras'. Run 'ddev xb-dev-extras --help' to see what it will do first."

0 commit comments

Comments
 (0)