### Run Pear command for setup
Source: https://github.com/holepunchto/pear-docs/blob/main/guide/getting-started.md
Execute the 'pear' command after installation to complete the setup. This command fetches the platform from peers if it's not already available.
```sh
pear
```
--------------------------------
### Example: Run Application from Pear Link
Source: https://github.com/holepunchto/pear-docs/blob/main/reference/cli.md
Example of how to run an application using its Pear link.
```bash
pear run pear://u6c6it1hhb5serppr3tghdm96j1gprtesygejzhmhnk5xsse8kmy
```
--------------------------------
### Initialize Project and Install Dependencies
Source: https://github.com/holepunchto/pear-docs/blob/main/howto/connect-to-many-peers-by-topic-with-hyperswarm.md
Sets up a new project using 'pear init' and installs necessary npm packages including hyperswarm, hypercore-crypto, and b4a.
```bash
mkdir peer-app
cd peer-app
pear init -y -t terminal
npm install hyperswarm hypercore-crypto b4a bare-process
```
--------------------------------
### Install Client Dependencies
Source: https://github.com/holepunchto/pear-docs/blob/main/howto/connect-two-peers-by-key-with-hyperdht.md
Installs necessary packages for the client application, including hyperdht, b4a, and bare-process.
```bash
mkdir client-app
cd client-app
pear init -y -t terminal
npm install hyperdht b4a bare-process
```
--------------------------------
### Install Pear CLI globally
Source: https://github.com/holepunchto/pear-docs/blob/main/guide/getting-started.md
Install the Pear CLI globally using npm. This command is required for initial setup.
```sh
npm i -g pear
```
--------------------------------
### Example: Run Application from Local Directory with Custom Storage
Source: https://github.com/holepunchto/pear-docs/blob/main/reference/cli.md
Example of running an application from a local directory, specifying a temporary storage path and passing application arguments.
```bash
pear run -s /tmp/app-storage path/to/an-app-folder some --app args
```
--------------------------------
### Install Bare CLI
Source: https://github.com/holepunchto/pear-docs/blob/main/reference/bare-overview.md
Install the Bare command-line interface globally using npm.
```sh
npm i -g bare
```
--------------------------------
### Example Output: Peer Connection Established
Source: https://github.com/holepunchto/pear-docs/blob/main/guide/making-a-pear-terminal-app.md
Example output indicating a new peer has joined and the connection status within the chat room.
```log
[info] Number of connections is now 0
[info] New peer joined, 6193ec
[info] Number of connections is now 1
[info] Joined chat room
```
--------------------------------
### Example: Run Application from Local Directory with Temporary Storage and Deep Link Simulation
Source: https://github.com/holepunchto/pear-docs/blob/main/reference/cli.md
Example of running an application from a local directory using temporary storage and simulating a deep link click.
```bash
pear run -t file://path/to/an-app-folder --some app --args
```
--------------------------------
### Install Bare Make Tool
Source: https://github.com/holepunchto/pear-docs/blob/main/reference/bare-overview.md
Install the bare-make build tool globally using npm.
```console
npm i -g bare-make
```
--------------------------------
### Navigate to Project Directory
Source: https://github.com/holepunchto/pear-docs/blob/main/guide/making-a-bare-mobile-app.md
Change into the cloned project directory to begin installing dependencies and configuring the application.
```bash
cd autopass-mobile-example
```
--------------------------------
### Install pear-inspect
Source: https://github.com/holepunchto/pear-docs/blob/main/guide/debugging-a-pear-terminal-app.md
Install the pear-inspect package using npm. This is the first step to enable debugging capabilities.
```bash
npm install pear-inspect
```
--------------------------------
### Initialize and Install Dependencies for Bee Writer App
Source: https://github.com/holepunchto/pear-docs/blob/main/howto/share-append-only-databases-with-hyperbee.md
Initializes a new Pear project and installs necessary npm packages for the bee-writer-app. Ensure you have the 'dict.json' file in the same directory.
```bash
mkdir bee-writer-app
cd bee-writer-app
pear init -y -t terminal
npm install corestore hyperswarm hyperbee b4a bare-fs
```
--------------------------------
### Install Server Dependencies
Source: https://github.com/holepunchto/pear-docs/blob/main/howto/connect-two-peers-by-key-with-hyperdht.md
Installs necessary packages for the server application, including hyperdht, b4a, and bare-process.
```bash
mkdir server-app
cd server-app
pear init -y -t terminal
npm install hyperdht b4a bare-process
```
--------------------------------
### Create and Start Worklet
Source: https://github.com/holepunchto/pear-docs/blob/main/guide/making-a-bare-mobile-app.md
Instantiate a new Worklet and start it with the bundled code and necessary arguments. Arguments are accessible via Bare.argv.
```typescript
const worklet = new Worklet()
```
```typescript
worklet.start('/app.bundle', bundle, [String(documentDirectory), pairingInvite])
```
--------------------------------
### List Installed Pear Applications
Source: https://github.com/holepunchto/pear-docs/blob/main/reference/faq.md
Run this command in the terminal to get a list of all Pear applications installed on your system. For more details, refer to the CLI documentation.
```console
pear data apps
```
--------------------------------
### Initialize and Install Dependencies for Bee Reader App
Source: https://github.com/holepunchto/pear-docs/blob/main/howto/share-append-only-databases-with-hyperbee.md
Sets up the bee-reader-app project by creating a directory, initializing it with Pear, and installing required npm packages. This app is used to query data from a shared Hyperbee database.
```bash
mkdir bee-reader-app
cd bee-reader-app
pear init -y -t terminal
npm install corestore hyperswarm hyperbee b4a bare-pipe
```
--------------------------------
### Initialize Core Reader App
Source: https://github.com/holepunchto/pear-docs/blob/main/howto/share-append-only-databases-with-hyperbee.md
Sets up the necessary project structure and installs dependencies for a core reader application.
```bash
mkdir core-reader-app
cd core-reader-app
pear init -y -t terminal
npm install corestore hyperswarm hyperbee b4a
```
--------------------------------
### Install libatomic on Fedora
Source: https://github.com/holepunchto/pear-docs/blob/main/guide/getting-started.md
Use this command to install the libatomic library on Fedora systems.
```bash
sudo dnf install libatomic
```
--------------------------------
### Run iOS Application
Source: https://github.com/holepunchto/pear-docs/blob/main/guide/making-a-bare-mobile-app.md
Command to start the iOS application. Assumes necessary build configurations are in place.
```bash
npm run ios
```
--------------------------------
### Example Output: Created New Chat Room
Source: https://github.com/holepunchto/pear-docs/blob/main/guide/making-a-pear-terminal-app.md
This is an example of the output when a new chat room is created by the Pear application in development mode.
```log
[info] Created new chat room: a1b2c35fbeb452bc900c5a1c00306e52319a3159317312f54fe5a246d634f51a
```
--------------------------------
### Install Application Dependencies
Source: https://github.com/holepunchto/pear-docs/blob/main/guide/making-a-pear-terminal-app.md
Installs the necessary modules for the chat functionality, including networking, buffer conversions, cryptography, and terminal input/output.
```bash
npm i bare-readline bare-tty bare-process hyperswarm b4a hypercore-crypto
```
--------------------------------
### Run Android Application
Source: https://github.com/holepunchto/pear-docs/blob/main/guide/making-a-bare-mobile-app.md
Command to start the Android application. Assumes necessary build configurations are in place.
```bash
npm run android
```
--------------------------------
### Sidecar Output Example
Source: https://github.com/holepunchto/pear-docs/blob/main/reference/migration.md
This is an example of the output you might see when running the Pear sidecar command. It indicates the status of the sidecar and runtime information.
```sh
- Closing any current Sidecar clients...
- Shutting down current Sidecar...
✔ Sidecar has shutdown
- Rebooting current process as Sidecar
- [ pqbzjhqyonxprx8hghxexnmctw75mr91ewqw5dxe1zmntfyaddqy ]
- Runtime: pear-runtime
========================= INIT ===================================
- Sidecar Booting [+0ms]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
✔ Current process is now Sidecar
- Version: {
"key": "pqbzjhqyonxprx8hghxexnmctw75mr91ewqw5dxe1zmntfyaddqy",
"length": 9195,
"fork": 0
}
========================= RUN ====================================
- Switching to key pzcjqmpoo6szkoc4bpkw65ib9ctnrq7b6mneeinbhbheihaq6p6o with length 2371... [+261.4711ms]
Platform update Available. Restart to update to: [+367.2348ms]
v0.2371.pzcjqmpoo6szkoc4bpkw65ib9ctnrq7b6mneeinbhbheihaq6p6o [+0.0349ms]
- DHT known-nodes read from database 100 nodes [+4631.6207ms]
- Drive bundle pzcjqmpoo6szkoc4bpkw65ib9ctnrq7b6mneeinbhbheihaq6p6o core length: 2371 [+5.1877ms]
- Sidecar swarm joining discovery key of pzcjqmpoo6szkoc4bpkw65ib9ctnrq7b6mneeinbhbheihaq6p6o [+0.0797ms]
- Sidecar Booted [+1.1023ms]
```
--------------------------------
### Install Development Dependencies
Source: https://github.com/holepunchto/pear-docs/blob/main/guide/making-a-pear-terminal-app.md
Installs the core development dependencies for a Pear Terminal project, including pear-interface and brittle.
```bash
npm install
```
--------------------------------
### Initialize Drive Bee Reader App Project
Source: https://github.com/holepunchto/pear-docs/blob/main/howto/create-a-full-peer-to-peer-filesystem-with-hyperdrive.md
Commands to create a new directory, navigate into it, initialize a Pear project, and install necessary npm packages for the drive-bee-reader-app.
```bash
mkdir drive-bee-reader-app
cd drive-bee-reader-app
pear init -y -t terminal
npm install corestore hyperswarm hyperdrive hyperbee b4a
```
--------------------------------
### Initialize and Configure Multicore Writer App
Source: https://github.com/holepunchto/pear-docs/blob/main/howto/work-with-many-hypercores-using-corestore.md
Sets up a new Pear terminal project, installs necessary packages, and configures the Corestore and Hyperswarm instances for managing multiple Hypercores.
```bash
mkdir multicore-writer-app
cd multicore-writer-app
pear init -y -t terminal
npm install bare-process corestore hyperswarm b4a
```
--------------------------------
### Example Debug URL Output
Source: https://github.com/holepunchto/pear-docs/blob/main/guide/debugging-a-pear-terminal-app.md
This is an example of the debug URL that will be outputted when the application is run in development mode with pear-inspect enabled.
```text
Debug with pear://runtime/devtools/a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2
```
--------------------------------
### Install Pear v2 Dependencies
Source: https://github.com/holepunchto/pear-docs/blob/main/reference/migration.md
Install the necessary Pear v2 dependencies, `pear-electron` for the UI and `pear-bridge` for P2P communication, to prepare your application for migration.
```sh
npm install pear-electron pear-bridge
```
--------------------------------
### Install Application Dependencies
Source: https://github.com/holepunchto/pear-docs/blob/main/guide/making-a-pear-desktop-app.md
Installs the core runtime dependencies for the Pear chat application, including hyperswarm, hypercore-crypto, and b4a, using npm.
```bash
npm install hyperswarm hypercore-crypto b4a
```
--------------------------------
### Initialize Multicore Reader App Project
Source: https://github.com/holepunchto/pear-docs/blob/main/howto/work-with-many-hypercores-using-corestore.md
Creates a new Pear terminal project for the reader application and installs the necessary npm packages.
```bash
mkdir multicore-reader-app
cd multicore-reader-app
pear init -y -t terminal
npm install corestore hyperswarm b4a
```
--------------------------------
### Example index.html for Pear App
Source: https://github.com/holepunchto/pear-docs/blob/main/guide/creating-a-pear-init-template.md
The HTML content for the `index.html` file, including basic structure, styling, and a Pear control element.
```html
Initialized from a Pear Template
```
--------------------------------
### Install Core Dependencies
Source: https://github.com/holepunchto/pear-docs/blob/main/guide/making-a-bare-mobile-app.md
Install essential npm packages for P2P communication, file system operations, RPC, and data storage. These are required for the application's backend functionality.
```bash
npm i b4a bare-fs bare-rpc corestore autopass @react-native-clipboard/clipboard graceful-goodbye
```
--------------------------------
### Initialize Writer App with Hypercore and Hyperswarm
Source: https://github.com/holepunchto/pear-docs/blob/main/howto/replicate-and-persist-with-hypercore.md
Sets up a new Pear terminal application, installs necessary dependencies including Hypercore and Hyperswarm, and configures the project to store data persistently.
```bash
mkdir writer-app
cd writer-app
pear init -y -t terminal
npm install bare-path bare-process hypercore hyperswarm b4a
```
--------------------------------
### Complete _template.json Configuration
Source: https://github.com/holepunchto/pear-docs/blob/main/guide/creating-a-pear-init-template.md
The full `_template.json` file content for the example template, defining multiple parameters with various configurations.
```json
{
"params": [
{
"name": "name",
"prompt": "name"
},
{
"name": "main",
"default": "index.html",
"prompt": "main",
"validation": "(value) => value.endsWith('.html')",
"msg": "must have an .html file extension"
},
{
"name": "height",
"validation": "(value) => Number.isInteger(+value)",
"prompt": "height",
"msg": "must be an integer"
},
{
"name": "width",
"validation": "(value) => Number.isInteger(+value)",
"prompt": "width",
"msg": "must be an integer"
},
{
"name": "license",
"default": "Apache-2.0",
"prompt": "license"
}
]
}
```
--------------------------------
### Get Runtime Binary with Pear.constructor.RUNTIME
Source: https://github.com/holepunchto/pear-docs/blob/main/reference/api.md
Pear.constructor.RUNTIME specifies the runtime binary to spawn when running, useful for testing scenarios.
```javascript
const runtimeBinary = Pear.constructor.RUNTIME
```
--------------------------------
### Start Mirroring Process
Source: https://github.com/holepunchto/pear-docs/blob/main/howto/create-a-full-peer-to-peer-filesystem-with-hyperdrive.md
Initiates the process of copying contents from a remote drive to a local directory. Ensure the drive instance and local directory are properly configured before calling.
```javascript
// start the mirroring process (i.e copying the contents from remote drive to local dir)
mirror()
```
--------------------------------
### Initialize Reader App with Hypercore and Hyperswarm
Source: https://github.com/holepunchto/pear-docs/blob/main/howto/replicate-and-persist-with-hypercore.md
Sets up a new Pear terminal application and installs dependencies for Hypercore and Hyperswarm. This application will connect to a writer's Hypercore using its key.
```bash
mkdir reader-app
cd reader-app
pear init -y -t terminal
npm install bare-path hypercore hyperswarm
```
--------------------------------
### Accessing Pear Application Start Identifier
Source: https://github.com/holepunchto/pear-docs/blob/main/reference/api.md
Get the application start identifier. This advanced property can be used with `pear-ipc` to identify and communicate with a specific application instance.
```javascript
Pear.app.startId
```
--------------------------------
### Start Pear Sidecar Server
Source: https://github.com/holepunchto/pear-docs/blob/main/reference/cli.md
Instructs any existing sidecar process to shut down and then becomes the sidecar. Provides access to corestores via HTTP and IPC.
```bash
pear sidecar
```
--------------------------------
### Accessing Pear Application Working Directory
Source: https://github.com/holepunchto/pear-docs/blob/main/reference/api.md
Get the current working directory when `pear run` started the application. This property is useful for locating application-specific files.
```javascript
Pear.app.dir
```
--------------------------------
### Accessing Custom Bootstrap DHT Nodes
Source: https://github.com/holepunchto/pear-docs/blob/main/reference/api.md
Get the list of custom bootstrap nodes Pear was started with. This property is an array of objects specifying 'host' and 'port' for initial DHT connections.
```javascript
Pear.app.dht.bootstrap
```
--------------------------------
### Create New Thread with Callback
Source: https://github.com/holepunchto/pear-docs/blob/main/reference/api.md
Start a new thread using a callback function as its entry point. The callback receives the data buffer passed during thread creation.
```javascript
const thread = new Thread([filename][, options][, callback])
```
--------------------------------
### Initialize a New Pear Project
Source: https://github.com/holepunchto/pear-docs/blob/main/guide/starting-a-pear-desktop-project.md
Use `pear init` to create the base structure for a new Pear project. Navigate into the created directory before initialization.
```bash
mkdir chat
cd chat
pear init ui --yes
```
--------------------------------
### Initialize New Pear Project
Source: https://github.com/holepunchto/pear-docs/blob/main/guide/creating-a-pear-init-template.md
Use this command to initialize a new Pear project from a local template directory or a pear:// link. Replace `[dir]` with the path to your template.
```bash
pear init [dir]
```
--------------------------------
### Build Pear-end Backend
Source: https://github.com/holepunchto/pear-docs/blob/main/guide/making-a-bare-mobile-app.md
Sets up the backend server using Bare, Autopass, and Corestore. Handles RPC communication and file system operations for storing data. Ensure to initialize Autopass with a Corestore and an invite.
```javascript
// /* global Bare, BareKit */
import RPC from 'bare-rpc'
import fs from 'bare-fs'
import URL from 'bare-url'
import goodbye from 'graceful-goodbye'
import { join } from 'bare-path'
import { RPC_RESET, RPC_MESSAGE } from '../rpc-commands.mjs'
import Autopass from 'autopass'
import Corestore from 'corestore'
const { IPC } = BareKit
const path = join(URL.fileURLToPath(Bare.argv[0]), 'autopass-example')
const rpc = new RPC(IPC, (req, error) => {
// Handle two way communication here
})
// For a clean start
if (fs.existsSync(path)) {
fs.rmSync(path, {
recursive: true,
force: true
})
}
fs.mkdirSync(path)
const invite = Bare.argv[1]
const pair = Autopass.pair(new Corestore(path), invite)
const pass = await pair.finished()
goodbye(() => pass.close())
await pass.ready()
pass.on('update', async (e) => {
const req = rpc.request(RPC_RESET)
req.send('data')
for await (const data of pass.list()) {
const value = JSON.parse(data.value)
if (value[0] === 'password') {
const req = rpc.request(RPC_MESSAGE)
req.send(JSON.stringify(value))
}
}
})
```
--------------------------------
### Initialize a new Pear project
Source: https://github.com/holepunchto/pear-docs/blob/main/guide/sharing-a-pear-app.md
Creates a new directory and initializes a Pear project within it. This is the first step before staging an application.
```bash
mkdir staging-example
cd staging-example
pear init -y
```
--------------------------------
### Install libatomic on RHEL/CentOS
Source: https://github.com/holepunchto/pear-docs/blob/main/guide/getting-started.md
Use this command to install the libatomic library on RHEL or CentOS systems.
```bash
sudo yum install libatomic
```
--------------------------------
### Install libatomic on Debian/Ubuntu
Source: https://github.com/holepunchto/pear-docs/blob/main/guide/getting-started.md
Use this command to install the libatomic library on Debian or Ubuntu systems.
```bash
sudo apt install libatomic1
```
--------------------------------
### Create Backend Entry Point
Source: https://github.com/holepunchto/pear-docs/blob/main/guide/making-a-bare-mobile-app.md
Create the main entry point file for the Pear-end code. All Bare code should reside within this file or be imported into it.
```bash
touch backend/backend.mjs
```
--------------------------------
### Install libatomic on Arch Linux
Source: https://github.com/holepunchto/pear-docs/blob/main/guide/getting-started.md
Use this command to install the libatomic library on Arch Linux systems.
```bash
sudo pacman -S libatomic_ops
```
--------------------------------
### Install libatomic on Alpine Linux
Source: https://github.com/holepunchto/pear-docs/blob/main/guide/getting-started.md
Use this command to install the libatomic library on Alpine Linux systems.
```bash
sudo apk add libatomic
```
--------------------------------
### Install Development Dependencies
Source: https://github.com/holepunchto/pear-docs/blob/main/guide/making-a-bare-mobile-app.md
Install development dependencies for packaging and type definitions. These are necessary for the build process and code quality.
```bash
npm i bare-pack @types/b4a --save-dev
```
--------------------------------
### pear init
Source: https://github.com/holepunchto/pear-docs/blob/main/reference/cli.md
Initializes project files. Can create projects from local templates or remote pear:// links.
```APIDOC
## pear init [flags] [dir]
### Description
Create initial project files.
Links: `pear://electron/template`, `pear://your.key.here/your/path/here`
Names: default, ui, node-compat
> Default Project directory path is `.`
Template can also be initialized from a pear:// link, the template should contain a `_template.json` file. This file defines the prompts which are converted to locals that are injected into the template.
### Flags
- `--yes|-y` : Autoselect all defaults
- `--force|-f` : Force overwrite existing files
- `--no-ask` : Suppress permissions dialogs
- `--help|-h` : Show help
```
--------------------------------
### Initialize Project from Local Template
Source: https://github.com/holepunchto/pear-docs/blob/main/reference/templates.md
Use this command to generate a project from a local template directory. Specify the path to the template and the output directory.
```sh
pear init ./path/to/template some-output-dir
```
--------------------------------
### Run Client with Server Key
Source: https://github.com/holepunchto/pear-docs/blob/main/howto/connect-two-peers-by-key-with-hyperdht.md
Executes the client application, passing the server's public key as a command-line argument to establish a connection.
```bash
pear run --dev .
```
--------------------------------
### Create Template Directory Structure
Source: https://github.com/holepunchto/pear-docs/blob/main/guide/creating-a-pear-init-template.md
Use these bash commands to create the necessary directory and files for a new Pear init template.
```bash
mkdir example
cd example
touch index.html package.json _template.json
```
--------------------------------
### Pear.constructor.COMPAT
Source: https://github.com/holepunchto/pear-docs/blob/main/reference/api.md
Compat-mode opt-in for integration. Integration API.
```APIDOC
## Pear.constructor.COMPAT
### Description
Compat-mode opt-in. See [./migration.md#compat-mode](./migration.md#compat-mode). NOTE: Integration APIs may change.
### Method
`Pear.constructor.COMPAT`
### Endpoint
N/A (Constant access)
### Parameters
None
### Request Example
```javascript
Pear.constructor.COMPAT = true
```
### Response
#### Success Response (200)
- **COMPAT** (boolean) - Indicates whether compat-mode is enabled.
#### Response Example
```json
true
```
```
--------------------------------
### Install Dependencies for Drive Reader App
Source: https://github.com/holepunchto/pear-docs/blob/main/howto/create-a-full-peer-to-peer-filesystem-with-hyperdrive.md
Installs necessary npm packages for the drive reader application, including corestore, localdrive, hyperswarm, and hyperdrive.
```bash
mkdir drive-reader-app
cd drive-reader-app
pear init -y -t terminal
npm install corestore localdrive hyperswarm hyperdrive debounceify b4a
```
--------------------------------
### Pear.constructor.RUNTIME
Source: https://github.com/holepunchto/pear-docs/blob/main/reference/api.md
The runtime binary to spawn when running. Integration API.
```APIDOC
## Pear.constructor.RUNTIME
### Description
The runtime binary to spawn when running. Used by [`pear-run`](https://github.com/holepunchto/pear-run). Useful for certain testing scenarios. NOTE: Integration APIs may change.
### Method
`Pear.constructor.RUNTIME`
### Endpoint
N/A (Constant access)
### Parameters
None
### Request Example
```javascript
const runtimeBinary = Pear[Pear.constructor.RUNTIME]
```
### Response
#### Success Response (200)
- **RUNTIME** (string) - The path or identifier of the runtime binary.
#### Response Example
```json
"pear-runtime-linux"
```
```
--------------------------------
### Bare-pack ModuleTraverseError Example
Source: https://github.com/holepunchto/pear-docs/blob/main/reference/troubleshooting.md
An example of a `ModuleTraverseError` that occurs when `bare-pack` attempts to bundle a Node.js module (e.g., 'node:crypto') for the Bare runtime, which is not supported.
```bash
./node_modules/paparam/index.js:514
throw new Bail(bail.reason)
^
Bail: ModuleTraverseError: MODULE_NOT_FOUND: Cannot find module 'node:crypto' imported from 'file://./index.js'
at exports.imports (./node_modules/bare-module-traverse/index.js:331:24)
at exports.imports.next ()
at exports.module (./node_modules/bare-module-traverse/index.js:152:18)
at exports.module.next ()
at process (./node_modules/bare-pack/index.js:50:26)
at async pack (./node_modules/bare-pack/index.js:24:3)
at async Command._runner (./node_modules/bare-pack/bin.js:46:18)
at async runAsync (./node_modules/paparam/index.js:793:5)
at Command._bail (./node_modules/paparam/index.js:514:11)
at Command.bail (./node_modules/paparam.js:127:36)
at runAsync (./node_modules/paparam/index.js:795:7)
```
--------------------------------
### Example Parameter Object with Validation
Source: https://github.com/holepunchto/pear-docs/blob/main/guide/creating-a-pear-init-template.md
An example of a complete parameter object for `_template.json`, including default value, prompt, validation function, and error message.
```json
{
"name": "main",
"default": "index.html",
"prompt": "Enter the main HTML file name",
"validation": "(value) => value.endsWith('.html')",
"msg": "must have an .html file extension"
}
```
--------------------------------
### Install Dependencies for Drive Writer App
Source: https://github.com/holepunchto/pear-docs/blob/main/howto/create-a-full-peer-to-peer-filesystem-with-hyperdrive.md
Installs necessary npm packages for the drive writer application, including corestore, localdrive, hyperswarm, hyperdrive, and debounceify.
```bash
mkdir drive-writer-app
cd drive-writer-app
pear init -y -t terminal
npm install corestore localdrive hyperswarm hyperdrive debounceify b4a pear-stdio
```
--------------------------------
### Initialize Project from Seeded Template
Source: https://github.com/holepunchto/pear-docs/blob/main/reference/templates.md
Use this command to initialize a project from a template that has been staged and seeded, using the provided `pear://` link.
```sh
pear init pear://
```
--------------------------------
### Initialize New Pear Project
Source: https://context7.com/holepunchto/pear-docs/llms.txt
Use `pear init` to create new Pear application project files. The `-y` flag accepts defaults, `-t` specifies project type (e.g., terminal), and `--force` overwrites existing files. Custom templates can be initialized from a pear:// link.
```bash
pear init -y
```
```bash
pear init -y -t terminal
```
```bash
pear init pear://your.key.here/template
```
```bash
pear init --force -y
```
--------------------------------
### Basic Pear Project Configuration in package.json
Source: https://context7.com/holepunchto/pear-docs/llms.txt
Configure basic Pear application metadata, including the main entry point, application name, and staging options for entrypoints, ignores, includes, and deferred dependencies.
```json
{
"name": "my-pear-app",
"main": "index.html",
"pear": {
"name": "My Pear App",
"stage": {
"entrypoints": ["./worker.js", "./service.js"],
"ignore": ["test/**", "docs/**", ".git"],
"includes": ["./assets/**", "./locales/**"],
"defer": ["optional-peer-dep"]
},
"links": {
"myWorker": "pear://worker-app-key",
"api": "https://api.example.com"
},
"routes": ".",
"gui": {
"width": 800,
"height": 600,
"backgroundColor": "#1a1a1a"
}
},
"dependencies": {
"hyperswarm": "^4.0.0",
"b4a": "^1.0.0"
}
}
```
--------------------------------
### Configure Bee Writer App Index.js
Source: https://github.com/holepunchto/pear-docs/blob/main/howto/share-append-only-databases-with-hyperbee.md
Sets up the Hyperbee writer application. It initializes Corestore and Hyperswarm for replication, creates a Hyperbee instance, and populates it with data from 'dict.json' if it's the first run. Otherwise, it seeds the existing data.
```javascript
import fsp from 'bare-fs/promises'
import Hyperswarm from 'hyperswarm'
import Corestore from 'corestore'
import Hyperbee from 'hyperbee'
import b4a from 'b4a'
// create a corestore instance with the given location
const store = new Corestore(Pear.config.storage)
const swarm = new Hyperswarm()
Pear.teardown(() => swarm.destroy())
// replication of corestore instance
swarm.on('connection', conn => store.replicate(conn))
// creation of Hypercore instance (if not already created)
const core = store.get({ name: 'my-bee-core' })
// creation of Hyperbee instance using the core instance
const bee = new Hyperbee(core, {
keyEncoding: 'utf-8',
valueEncoding: 'utf-8'
})
// wait till all the properties of the hypercore are initialized
await core.ready()
// join a topic
const discovery = swarm.join(core.discoveryKey)
// Only display the key once the Hyperbee has been announced to the DHT
discovery.flushed().then(() => {
console.log('bee key:', b4a.toString(core.key, 'hex'))
})
// Only import the dictionary the first time this script is executed
// The first block will always be the Hyperbee header block
if (core.length <= 1) {
console.log('importing dictionary...')
const dict = JSON.parse(await fsp.readFile('./dict.json'))
const batch = bee.batch()
for (const { key, value } of dict) {
await batch.put(key, value)
}
await batch.flush()
} else {
// Otherwise just seed the previously-imported dictionary
console.log('seeding dictionary...')
}
```
--------------------------------
### Pear.exitCode
Source: https://github.com/holepunchto/pear-docs/blob/main/reference/api.md
Gets or sets the code that will be returned once the process exits.
```APIDOC
## Pear.exitCode
### Description
The code that will be returned once the process exits. If the process is exited using `Bare.exit()` without specifying a code, `Bare.exitCode` is used.
### Method
`Pear.exitCode`
### Endpoint
N/A (Property access)
### Parameters
None
### Request Example
```javascript
Pear.exitCode = 0 // Set exit code
console.log(Pear.exitCode) // Get exit code
```
### Response
#### Success Response (200)
- **exitCode** (number) - The process exit code.
#### Response Example
```json
0
```
```
--------------------------------
### Get Bare Version
Source: https://github.com/holepunchto/pear-docs/blob/main/reference/api.md
Retrieve the version string of the Bare runtime.
```javascript
const version = Bare.version;
```
--------------------------------
### Get Current Process ID
Source: https://github.com/holepunchto/pear-docs/blob/main/reference/api.md
Retrieve the unique identifier for the current process.
```javascript
const pid = Bare.pid;
```
--------------------------------
### Get Current Process ID with Pear.pid
Source: https://github.com/holepunchto/pear-docs/blob/main/reference/api.md
Pear.pid returns the ID of the current process.
```javascript
console.log(Pear.pid)
```
--------------------------------
### Advanced Pear Configuration with Assets and Pre-scripts
Source: https://context7.com/holepunchto/pear-docs/llms.txt
Configure advanced desktop application settings in package.json, including pre-scripts, asset bundling with specific inclusion rules, custom routing, unrouted paths, and GUI window properties like minimum size and frame behavior.
```json
{
"name": "desktop-app",
"main": "ui/index.html",
"pear": {
"name": "Desktop App",
"pre": "pear-electron/pre",
"assets": {
"ui": {
"link": "pear://0.940.pkzpbccx8ojp4516p7abompuhyj5gcpqfux1s9e7e4zzcdhyhdto",
"name": "Pear Runtime",
"only": [
"/boot.bundle",
"/by-arch/%%HOST%%",
"/prebuilds/%%HOST%%"
]
}
},
"routes": {
"/settings": "/ui/settings.html",
"/profile": "/ui/profile.html"
},
"unrouted": ["/api", "/static"],
"links": [
"pear://trusted-worker-key",
"https://cdn.example.com",
"https://*"
],
"gui": {
"minWidth": 400,
"minHeight": 300,
"frame": false,
"transparent": true
}
}
}
```
--------------------------------
### Pear.checkpoint() - Persist Application State
Source: https://context7.com/holepunchto/pear-docs/llms.txt
Stores state that will be available as Pear.app.checkpoint on the next application start.
```APIDOC
## Pear.checkpoint() - Persist Application State
Stores state that will be available as `Pear.app.checkpoint` on the next application start.
### Description
This function allows you to save arbitrary data that will be persisted across application restarts. The saved data is accessible via `Pear.app.checkpoint` when the application next launches.
### Usage
```javascript
await Pear.checkpoint(state: any)
```
### Parameters
- **state** (any) - The data to be persisted. This can be any JSON-serializable value.
### Example Usage
```javascript
// Save checkpoint state
await Pear.checkpoint({ lastPage: 5, theme: 'dark' })
// Checkpoint is immediately reflected
console.log(Pear.app.checkpoint) // { lastPage: 5, theme: 'dark' }
// On next app start, restore state
const savedState = Pear.app.checkpoint
if (savedState) {
console.log('Restoring from checkpoint:', savedState)
loadPage(savedState.lastPage)
setTheme(savedState.theme)
}
// Example: Save scroll position on exit
Pear.teardown(async () => {
await Pear.checkpoint({
scrollY: window.scrollY,
timestamp: Date.now()
})
})
```
```
--------------------------------
### Access Worklet IPC
Source: https://github.com/holepunchto/pear-docs/blob/main/guide/making-a-bare-mobile-app.md
Access the IPC stream from the started worklet for communication between the UI and the Pear-end.
```typescript
const { IPC } = worklet
```
--------------------------------
### View Application Information
Source: https://github.com/holepunchto/pear-docs/blob/main/reference/cli.md
Supply a link or channel to view application information. Supply no argument to view platform information.
```bash
pear info [link|channel]
```
--------------------------------
### Get Bare and Dependency Versions
Source: https://github.com/holepunchto/pear-docs/blob/main/reference/api.md
Access an object containing the version strings for Bare and its dependencies.
```javascript
const versions = Bare.versions;
```
--------------------------------
### Access Command Line Arguments
Source: https://github.com/holepunchto/pear-docs/blob/main/reference/api.md
Get the command line arguments passed to the process when it was launched.
```javascript
const args = Bare.argv;
```
--------------------------------
### Stage a Pear application for local development
Source: https://github.com/holepunchto/pear-docs/blob/main/guide/sharing-a-pear-app.md
Stages the current application in the directory to the 'dev' channel. This analyzes the app and stores metadata for faster loading. The application link is output upon completion.
```bash
pear stage dev
```
--------------------------------
### View Pear Application Information
Source: https://context7.com/holepunchto/pear-docs/llms.txt
Use `pear info` to display project details. It can show platform info, application info by channel or link, and specific details like `--key` or `--manifest`. `--json` outputs the information in JSON format.
```bash
pear info
```
```bash
pear info dev
```
```bash
pear info pear://keet
```
```bash
pear info --key dev
```
```bash
pear info --manifest pear://myapp
```
```bash
pear info --json dev
```