]> BookStack Code Mirror - bookstack/blob - dev/docs/development.md
Merge pull request #5627 from BookStackApp/lexical_20250525
[bookstack] / dev / docs / development.md
1 # Development & Testing
2
3 All development on BookStack is currently done on the `development` branch. 
4 When it's time for a release the `development` branch is merged into release with built & minified CSS & JS then tagged at its version. Here are the current development requirements:
5
6 * [Node.js](https://nodejs.org/en/) v20.0+
7
8 ## Building CSS & JavaScript Assets
9
10 This project uses SASS for CSS development and this is built, along with the JavaScript, using a range of npm scripts. The below npm commands can be used to install the dependencies & run the build tasks:
11
12 ``` bash
13 # Install NPM Dependencies
14 npm install
15
16 # Build assets for development
17 npm run build
18
19 # Build and minify assets for production
20 npm run production
21
22 # Build for dev (With sourcemaps) and watch for changes
23 npm run dev
24 ```
25
26 Further details about the BookStack JavaScript codebase can be found in the [javascript-code.md document](javascript-code.md).
27
28 ## Automated App Testing 
29
30 BookStack has a large suite of PHP tests to cover application functionality. We try to ensure that all additions and changes to the platform are covered with testing.
31
32 For details about setting-up, running and writing tests please see the [php-testing.md document](php-testing.md).
33
34 ## Code Standards
35
36 We use tools to manage code standards and formatting within the project. If submitting a PR, formatting as per our project standards would help for clarity but don't worry too much about using/understanding these tools as we can always address issues at a later stage when they're picked up by our automated tools.
37
38 ### PHP
39
40 PHP code standards are managed by [using PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer).
41 Static analysis is in place using [PHPStan](https://phpstan.org/) & [Larastan](https://github.com/nunomaduro/larastan).
42 The below commands can be used to utilise these tools:
43
44 ```bash
45 # Run code linting using PHP_CodeSniffer
46 composer lint
47
48 # As above, but show rule names in output
49 composer lint -- -s
50
51 # Auto-fix formatting & lint issues via PHP_CodeSniffer phpcbf
52 composer format
53
54 # Run static analysis via larastan/phpstan
55 composer check-static
56 ```
57
58 ### JavaScript
59
60 JavaScript code standards use managed using [ESLint](https://eslint.org/).
61 The ESLint rule configuration is managed within the `package.json` file.
62 The below commands can be used to lint and format:
63
64 ```bash
65 # Run code linting using ESLint
66 npm run lint
67
68 # Fix code where possible using ESLint
69 npm run fix
70 ```
71
72 ## Development using Docker
73
74 This repository ships with a Docker Compose configuration intended for development purposes. It'll build a PHP image with all needed extensions installed and start up a MySQL server and a Node image watching the UI assets.
75
76 To get started, make sure you meet the following requirements:
77
78 - Docker and Docker Compose are installed
79 - Your user is part of the `docker` group
80
81 If all the conditions are met, you can proceed with the following steps:
82
83 1. **Copy `.env.example` to `.env`**, change `APP_KEY` to a random 32 char string and set `APP_ENV` to `local`.
84 2. Make sure **port 8080 is unused** *or else* change `DEV_PORT` to a free port on your host.
85 3. **Run `chgrp -R docker storage`**. The development container will chown the `storage`, `public/uploads` and `bootstrap/cache` directories to the `www-data` user inside the container so BookStack can write to it. You need to change the group to your host's `docker` group here to not lose access to the `storage` directory.
86 4. **Run `docker-compose up`** and wait until the image is built and all database migrations have been done.
87 5. You can now login with `admin@admin.com` and `password` as password on `localhost:8080` (or another port if specified).
88
89 If needed, You'll be able to run any artisan commands via docker-compose like so:
90
91 ```bash
92 docker-compose run app php artisan list
93 ```
94
95 The docker-compose setup runs an instance of [MailHog](https://github.com/mailhog/MailHog) and sets environment variables to redirect any BookStack-sent emails to MailHog. You can view this mail via the MailHog web interface on `localhost:8025`. You can change the port MailHog is accessible on by setting a `DEV_MAIL_PORT` environment variable.
96
97 ### Running tests
98
99 After starting the general development Docker, migrate & seed the testing database:
100
101  ```bash
102 # This only needs to be done once
103 docker-compose run app php artisan migrate --database=mysql_testing
104 docker-compose run app php artisan db:seed --class=DummyContentSeeder --database=mysql_testing
105 ```
106
107 Once the database has been migrated & seeded, you can run the tests like so:
108
109  ```bash
110 docker-compose run app php vendor/bin/phpunit
111 ```
112
113 ### Debugging
114
115 The docker-compose setup ships with Xdebug, which you can listen to on port 9090.
116 NB : For some editors like Visual Studio Code, you might need to map your workspace folder to the /app folder within the docker container for this to work.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.