Files
pear-docs/guide/starting-a-pear-desktop-project.md
Sean Zellmer 577c4c1bec Updating guides (1.5.0) (#154)
* Remove `--` for app option passthrough

Changed since `paparam` was used for parsing command line options:
85892a6a32a84ae42a548f8e3ac0b5dbedd70c80
Now uses `cmd.rest` for app args.

* Use `Pear.config.args` for howto scripts

* Update "starting a pear desktop project" guide to match template

* Remove `--no-ask-trust` flag from `pear run` cli doc

This command was replaced by `--no-ask` which was already in the
documentation. Updated a reference to `--no-ask-trust` in the 'Sharing a
Pear Application' guide.

* Fix typos in "Releasing a Pear Application" guide

* Correct application storage folder name in hyperbee howto

* Add missing `test/index.test.js` in project structure for terminal guide

* Remove language about app continuing to run

This is no longer true at least as of pear:
v0.5114.pqbzjhqyonxprx8hghxexnmctw75mr91ewqw5dxe1zmntfyaddqy / v1.5.0

* Fix extra indention in example code for hypercore howto

* Format json in `_template.json` example

* Add instructions to set up a minimal `package.json` for testing template

Without this, the next step of `pear run --dev .` does not work since
`pear` expects a `package.json` file.

* Rename hyperbee reader app in hyperdrive howto to avoid name conflict

Naming only matters if someone is following the guides and starts each
guide from the same root directory. If they do, then `bee-reader-app`
from the hyperdrive conflicts with the `bee-reader-app` from the
hyperbee howto.

* Remove unrelated youtube tutorial from hyperswarm howto

* Update guide/creating-a-pear-init-template.md

Co-authored-by: David Mark Clements <huperekchunow@googlemail.com>

* Fix spelling mistake

Co-authored-by: David Mark Clements <huperekchunow@googlemail.com>

---------

Co-authored-by: David Mark Clements <huperekchunow@googlemail.com>
2024-11-01 19:32:58 +01:00

91 lines
2.3 KiB
Markdown

# Starting a Pear Desktop Project
This section shows how to generate, configure, and develop a Pear desktop project, in preparation for [Making a Pear Desktop Application](./making-a-pear-desktop-app.md).
{% embed url="https://www.youtube.com/watch?v=y2G97xz78gU" %} Build with Pear - Episode 01: Developing with Pear {% embeded %}
## Step 1. Initialization
Use `pear init` to create a new Pear project.
```
mkdir chat
cd chat
pear init --yes
```
This creates the base project structure.
- `package.json`. App configuration. Notice the `pear` property.
- `index.html`. App entrypoint.
- `app.js`. Main code.
- `test/index.test.js`. Test skeleton.
## Step 2. Verify Everything Works
Use `pear run` to verify everything works as expected.
```
pear run --dev .
```
> A directory or link needs to be specified with `pear run`, here `.` denotes the current Project directory.
The app should open in development mode. In this mode developer tools are also opened.
![Running pear run --dev .](../assets/chat-app-1.png)
## Step 3. Automatic Reload
To enable automatic reloading, add the following lines to `app.js` :
```js
Pear.updates(() => Pear.reload())
```
Run the app again using:
```js
pear run --dev .
```
Now Pear watches project files. When they change, the app is automatically reloaded.
While keeping the `pear run --dev .` command running, open `index.html` in an editor.
Change `<h1>desktop</h1>` to `<h1>Hello world</h1>`.
The app should now show:
![Automatic reload](../assets/chat-app-2.png)
> Live reload with hot-module reloading is possible by using the `pear.watch` configuration and the [`pear.updates`](../reference/pear/api.md#pearupdateslistener-async-functionfunction) API. The [pear-hotmods](https://github.com/holepunchto/pear-hotmods) convenience module can also be used.
## Step 4. Configuration
Application configuration is under the `pear` property in `package.json`
Open `package.json` and update it to:
```
{
...
"pear": {
"gui": {
"height": 400,
"width": 700
}
}
...
}
```
Close the app and re-run `pear run --dev .` to see the changes, the initial window size is different now.
See the [Configuration Documentation](../reference/pear/configuration.md) for all options.
## Next
* [Making a Pear Desktop Application](./making-a-pear-desktop-app.md)