Skip to content

Commit

Permalink
feat: improve turborepo setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Leksat committed Nov 20, 2023
1 parent 97df5de commit 4badb6c
Show file tree
Hide file tree
Showing 19 changed files with 59 additions and 145 deletions.
12 changes: 0 additions & 12 deletions .idea/runConfigurations/CMS_Turbo_Dev.xml

This file was deleted.

12 changes: 0 additions & 12 deletions .idea/runConfigurations/CMS_Turbo_Dev_Light.xml

This file was deleted.

12 changes: 0 additions & 12 deletions .idea/runConfigurations/Website_Turbo_Dev.xml

This file was deleted.

12 changes: 0 additions & 12 deletions .idea/runConfigurations/Website_Turbo_Dev_Light.xml

This file was deleted.

46 changes: 12 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,48 +87,26 @@ Other steps

```
pnpm i
pnpm turbo:prep
```

Additionally, you can run `pnpm turbo:test`. This will serve two purposes:

- It will make sure that your system is fully compatible with the project
- It will generate code that is required for IDE autocompletion
Additionally, you can run `pnpm turbo:test` to make sure that your system is
fully compatible with the project.

## Working with apps and packages

Navigate to an app or package folder and run `pnpm turbo:dev`. Turborepo will
make sure to run all required tasks and cache as much as it can.

### Turborepo setup

We try to follow common rules in all apps and packages.

Usually, the following scripts can be found in `package.json`:
Navigate to an app/package folder and run `pnpm dev`.

- `prep`: Prepare everything related to code. For example, compile code,
generate types, download additional dependencies, etc.
- `build`: Build the app or package. For example, setup Drupal, build Gatsby,
build Storybook, etc.

If there is a `turbo:` prefixed script, it will run the non prefixed script and
additionally

- Run all required scripts in this or other packages
- Cache the results if possible

For example, running `pnpm turbo:dev` in `apps/website` will prepare all
dependencies, setup and start Drupal, start Publisher and open the Publisher's
status URL in the browser.
When working on integration tasks, it may be required to re-run
`pnpm turbo:prep` from the repo root.

### Drupal

Considering the above, please note that the Drupal database can be reset on

- re-running `pnpm turbo:dev` in `apps/cms`
- running some `turbo:` prefixed scripts in `apps/website`
Running `pnpm turbo:prep` works conditionally for Drupal. If database exists, it
clears Drupal cache. Otherwise, it re-installs Drupal completely.

If you have some unsaved work in the Drupal database, don't start Drupal with
`pnpm turbo:dev` but use `pnpm dev` instead.
If you wish `pnpm turbo:prep` to re-install Drupal, delete
`apps/cms/web/sites/default/files/.sqlite` first.

## Environment overrides

Expand Down Expand Up @@ -167,8 +145,8 @@ lagoon add variable -p [project name] -e dev -N NETLIFY_SITE_ID -V [netlify site

### Publisher authentication with Drupal

Publisher can require to authenticate with Drupal based on OAuth2.
It is only used on Lagoon environments.
Publisher can require to authenticate with Drupal based on OAuth2. It is only
used on Lagoon environments.

<details>
<summary>How it works</summary>
Expand Down
3 changes: 3 additions & 0 deletions apps/cms/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ generated/translations.json

# GraphQL autoload registry
autoload.json

# A workaround to avoid turbo caching locally.
turbo-seed.txt
12 changes: 4 additions & 8 deletions apps/cms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,16 @@
"description": "Drupal based content management system.",
"sideEffects": false,
"scripts": {
"prep": "if command -v composer; then composer install; else echo 'Skipping composer install.'; fi",
"build": "pnpm drupal-install && rm -rf install-cache.zip && pnpm content:import && pnpm fix-premissions && pnpm ensure-working-db",
"turbo:build": "pnpm turbo build --output-logs=new-only",
"export:schema": "pnpm drush silverback-gatsby:schema-export ../../../tests/schema",
"prep:composer": "if command -v composer; then composer install; else echo 'Skipping composer install.'; fi",
"prep:database": "./prep-database.sh",
"prep:schema": "pnpm drush silverback-gatsby:schema-export ../../../tests/schema",
"fix-premissions": "chmod +w web/sites/default/files/.htaccess && chmod +w web/sites/default/files/private/.htaccess",
"ensure-working-db": "pnpm drush sqlq 'select * from node'",
"drush": "SB_ENVIRONMENT=1 SIMPLETEST_DB=sqlite://localhost/sites/default/files/.sqlite DRUSH_OPTIONS_URI=http://127.0.0.1:8888 vendor/bin/drush",
"silverback": "SB_ENVIRONMENT=1 SIMPLETEST_DB=sqlite://localhost/sites/default/files/.sqlite SB_ADMIN_USER=admin SB_ADMIN_PASS=admin vendor/bin/silverback",
"drupal-install": "SB_SETUP=1 pnpm silverback setup --profile minimal && pnpm drush php-eval 'node_access_rebuild();'",
"drupal-install": "SB_SETUP=1 pnpm silverback setup --profile minimal && pnpm content:import && pnpm drush php-eval 'node_access_rebuild();' && rm -rf install-cache.zip && pnpm fix-premissions && pnpm ensure-working-db",
"start": "cd web; SB_ENVIRONMENT=1 SIMPLETEST_DB=sqlite://localhost/sites/default/files/.sqlite DRUSH_OPTIONS_URI=http://127.0.0.1:8888 php -S 0.0.0.0:8888 .ht.router.php # no drush to avoid the drush server timeout",
"dev": "pnpm start",
"dev:light": "pnpm clear && pnpm dev",
"turbo:dev": "pnpm turbo dev --output-logs=new-only",
"turbo:dev:light": "pnpm turbo dev:light --output-logs=new-only",
"clear": "pnpm drush cr",
"login": "pnpm drush uli",
"content:export": "pnpm drush php-script web/modules/custom/test_content/export.php",
Expand Down
12 changes: 12 additions & 0 deletions apps/cms/prep-database.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
if [ ! -z $LAGOON ]
then
# Do not touch database on Lagoon
exit 0
fi

if ! test -f web/sites/default/files/.sqlite
then
pnpm drupal-install
else
pnpm drush cr
fi
32 changes: 18 additions & 14 deletions apps/cms/turbo.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
{
"extends": ["//"],
"pipeline": {
"dev": {
"persistent": true,
"dependsOn": ["build", "^build"]
"prep": {
"dependsOn": ["prep:schema"]
},
"dev:light": {
"notes": "Same as dev, but does not build the CMS, just clears caches",
"persistent": true,
"dependsOn": ["^build"]
"prep:schema": {
"dependsOn": ["prep:database"]
},
"build": {
"dependsOn": ["prep"],
"inputs": ["config/**", "web/modules/custom/**", "web/themes/custom/**"],
"outputs": ["web/sites/default/files/**"]
"prep:database": {
"dependsOn": ["prep:composer"],
"inputs": [
"turbo-seed.txt",
"prep-database.sh",
"config/**",
"web/modules/custom/**",
"web/themes/custom/**"
],
"outputs": ["web/sites/default/files/**"],
"env": ["CI", "LAGOON"]
},
"prep": {
"dependsOn": [],
"inputs": ["composer.json", "composer.lock", "scaffold/**"],
"prep:composer": {
"inputs": ["composer.json", "composer.lock", "scaffold/**", "patches/**"],
"outputs": [
"drush/**",
"vendor/**",
"!**/.git/**",
"web/**",
Expand Down
3 changes: 0 additions & 3 deletions apps/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@
"start": "publisher",
"serve": "netlify dev --dir=public --port=8000",
"dev": "pnpm clean && publisher",
"dev:light": "pnpm dev",
"open": "open http://127.0.0.1:8000/___status/",
"turbo:dev": "start-test start:cms 8888 'pnpm turbo dev --output-logs=new-only'",
"turbo:dev:light": "start-test start:cms 8888 'pnpm turbo dev:light --output-logs=new-only'",
"gatsby:develop": "ENABLE_GATSBY_REFRESH_ENDPOINT=true pnpm gatsby develop",
"gatsby:refresh": "curl -X POST http://localhost:8000/__refresh",
"clean": "gatsby clean"
Expand Down
18 changes: 1 addition & 17 deletions apps/website/turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
"extends": ["//"],
"pipeline": {
"dev": {
"persistent": true,
"dependsOn": ["@custom/cms#build", "prep", "^prep"]
},
"dev:light": {
"notes": "Same as dev, but does not build the CMS",
"persistent": true,
"dependsOn": ["prep", "^prep"]
},
Expand All @@ -16,20 +11,9 @@
"test:static": {
"inputs": ["src/**", "!src/gatsby-fragments.js"]
},
"rebuild": {
"cache": false,
"dependsOn": ["prep", "^prep"],
"inputs": [
"gatsby-browser.js",
"gatsby-config.js",
"gatsby-node.ts",
"netlify/**",
"netlify.toml"
]
},
"build": {
"env": ["DRUPAL_INTERNAL_URL", "DRUPAL_EXTERNAL_URL"],
"dependsOn": ["@custom/cms#build", "prep", "^build"],
"dependsOn": ["@custom/cms#prep", "prep", "^prep"],
"inputs": [
"gatsby-browser.js",
"gatsby-config.js",
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"scripts": {
"postinstall": "husky install || true",
"commit": "git-cz",
"turbo:test": "pnpm turbo:test:quick && CI=true turbo test:integration --output-logs=new-only --concurrency=1",
"turbo:test:quick": "turbo test:static --output-logs=errors-only && turbo test:unit --output-logs=errors-only",
"turbo:prep": "turbo prep --output-logs=new-only",
"turbo:build:website": "turbo rebuild --filter=\"@custom/website\" --output-logs=new-only"
"turbo:local": "if [ -z $CI ]; then echo $(date)$RANDOM > apps/cms/turbo-seed.txt; fi",
"turbo:test": "pnpm turbo:local && turbo test:unit --output-logs=new-only && turbo test:integration --output-logs=new-only --concurrency=1",
"turbo:test:quick": "pnpm turbo:local && turbo test:unit --output-logs=new-only",
"turbo:prep": "pnpm turbo:local && turbo prep --output-logs=new-only"
},
"private": true,
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/schema/turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"extends": ["//"],
"pipeline": {
"prep": {
"dependsOn": ["@custom/cms#prep"],
"dependsOn": ["@custom/cms#prep:composer"],
"inputs": [
"../../apps/website/node_modules/@amazeelabs/*/directives.graphql",
"../../apps/cms/web/modules/contrib/*/directives.graphql",
Expand Down
1 change: 0 additions & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
}
},
"scripts": {
"turbo:prep": "pnpm turbo prep",
"prep:types": "tsc --emitDeclarationOnly",
"prep:scripts": "swc ./src -d ./build",
"prep:styles": "NODE_ENV=production pnpm postcss tailwind.css -o build/styles.css",
Expand Down
1 change: 0 additions & 1 deletion tests/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"scripts": {
"test:static": "tsc --noEmit && eslint '**/*.{ts,tsx,js,jsx}' --ignore-path='./.gitignore'",
"test:integration": "playwright test",
"turbo:test:integration": "CI=true turbo test:integration --output-logs=new-only",
"test:headed": "playwright test --headed",
"dev": "playwright test --ui",
"download-browsers": "playwright install chromium"
Expand Down
3 changes: 1 addition & 2 deletions tests/schema/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Before running tests, start Drupal from `apps/cms` with either `pnpm turbo:dev`
or `pnpm dev`
Before running tests, start Drupal from `apps/cms` with `pnpm dev`
2 changes: 1 addition & 1 deletion tests/schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"start": "pnpm run --filter @custom/cms start",
"test:static": "tsc --noEmit && eslint '**/*.{ts,tsx,js,jsx}' --ignore-path='./.gitignore'",
"test:integration": "start-server-and-test 8888 vitest",
"test:integration": "CI=true start-server-and-test 8888 vitest",
"dev": "vitest --ui # for non phpstorm users"
},
"optionalDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion tests/schema/turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"extends": ["//"],
"pipeline": {
"test:integration": {
"dependsOn": ["@custom/cms#build"]
"dependsOn": ["@custom/cms#prep"]
},
"dev": {
"persistent": true
Expand Down
11 changes: 1 addition & 10 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,12 @@
"dependsOn": ["test:static"]
},
"test:static": {
// Static tests don't require a build of the package, but they
// require dependencies to be built, since these might contain
// type definitions.
"dependsOn": ["^prep"]
},
"test:unit": {
// Unit tests also don't require the package to be built since test
// tools build packages on the fly. Dependencies need to be built though.
// Also unit tests should not even run without static tests passing or
// dependencies unit tests failing.
"dependsOn": ["^prep", "test:static", "^test:unit"]
"dependsOn": ["test:static"]
},
"test:integration": {
// Integration tests run the full system and require the package to be
// built and unit tested.
"dependsOn": ["build", "test:unit"]
}
}
Expand Down

0 comments on commit 4badb6c

Please sign in to comment.