Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to a package #10

Merged
merged 3 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: "14" # Adjust according to your needs
node-version: "16" # Adjust according to your needs

- name: Install Dependencies
run: yarn install

- name: Execute Test Tools
run: yarn test:tools
run: yarn test
180 changes: 67 additions & 113 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,16 @@
# bOS-workspace (ALPHA)
# bos-workspace (ALPHA)

bOS-workspace is a comprehensive framework equipped with a build script that streamlines the process of managing, coding and testing bOS widgets. This script performs various operations including parsing the `bos.config.json` file, injecting content via specific comments, replacing widget sources, importing modules, generating SocialDB, and more.
bos-workspace is a framework to help ease the development of bOS widgets. It works like a monorepo, allowing you to develop multiple bos apps in the same time. It also provides a build script to help with the development process.

## Key Features

1. Reads the `bos.config.json` file located in each `app/{appname}` folder. Note: `bos.config.json` is crucial for certain commands to function properly.
2. Utilizes special comments to inject the desired content at the right place.
3. Utilizes the aliases map from `bos.config.json` to replace comments with the correct value, it's specially useful for widget sources. For instance:

```json
"aliases": {
"nui": "nui.sking.near",
"something": "abc"
}
```

This operation will replace all instances of the following:

- From: `/*__@replace:something__*/` to `abc`
- From: `<Widget src="/*__@replace:nui__*//widget/Button" />` to `<Widget src="nui.sking.near/widget/Button" />`

4. Supports module import from the `/modules` folder using the syntax: `/*__@import:moduleName__*/`. All occurrences from the mentioned syntax will be replaced with the content of `/modules/moduleName.js` and from `/*__@import:folder1/folder2/moduleName__*/` with the content of `/modules/folder1/folder2/moduleName.js`.

5. The build script also replace the following special comments:

- From `/*__@appAccount__*/` to the app account defined in `bos.config.json`.

6. File' comments can be excluded from processing by the build script by adding the following comment at the beginning of the file: `/*__@skip__*/`.
## Introduction

## Guidelines
To use bos-workspace, simple install it:

- All bOS specific comments should strictly adhere to the format: `/*__@command:argument__*/` or `/*__@command__*/`.
- The comment commands are operational on `.js`, `.jsx`, `.ts`, `.tsx`, and `.jsonc` files, the only exception being `bos.config.json`.

## Project Structure
```bash
npm install -g bos-workspace
```

The `build.js` or `dev.js` script should execute at the project's root, and the project should maintain the following structure:
Then, create a new folder with the following structure:

```
- apps
Expand All @@ -48,45 +23,82 @@ The `build.js` or `dev.js` script should execute at the project's root, and the
- (any folder structure)
```

Each `app` represents the bOS widgets that can be deployed under the app account specified in `bos.config.json`.
- The `apps` folder is where you store your apps. Each app has its own folder, and each app folder has a `bos.config.json` file.
- The `apps/{appname}/widget` folder is where you store your widgets. You can have any folder structure inside the `widget` folder.
- The `jsonc` files under `apps/{appname}` folder are used to create a data.json, that is used to store data under SocialDB.
- The `modules` folder is where you store your modules. You can have any folder structure inside the `modules` folder.

Upon execution, the build script will generate a `build` folder at the project's root with the following structure:
### Commands

You can run `bw` or `bos-workspace` to see the list of commands.

```bash
Usage: bos-workspace [options] [command]

BOS Workspace CLI

Options:
-V, --version output the version number
-h, --help display help for command

Commands:
dev Run the development server
build Build the project
deploy Deploy the project
upload Upload data to SocialDB
```
- build
- {appname}
- src: the widgets code identical to the widget folder but prepared for deployment.
- data.json: a JSON file that encompasses all .jsonc files from the {appname} folder, including its subfolders.
```

Example of `bos.config.json`:
> If the gateway can't fetch local components, try disabling brave shields or your adblock.

> If the commands don't work, try again using Node >=16

## Key Features

### 1. **App Configuration**

In the `bos.config.json` file, you can specify the app account. It will be used as for development and deployment. And the build script will replace the `/*__@appAccount__*/` comment with the app account.

### 2. **Alias Mapping**

The aliases from `bos.config.json` are used to replace comments with correct values, useful for widget sources.

For example:

```json
{
"appAccount": "nui.sking.near",
"aliases": {
"aliases": {
"nui": "nui.sking.near",
"imageWidget": "mob.near/widget/Image",
"something": "abc"
}
}
```

## The `data.json` File
Replacements:

- `/*__@replace:something__*/` to `abc`
- `<Widget src="/*__@replace:nui__*//widget/Button" />` to `<Widget src="nui.sking.near/widget/Button" />`

### 3. **Module Importing**

The build script will replace `/*__@import:moduleName__*/` with the module's source code from the `modules` folder.

### 4. **Exclude Files**

The `data.json` file is utilized to store data in SocialDB under the app account. It employs folders as keys and files as values, supporting only `.jsonc` and `.txt` files.
The build script will exclude files that have `/*__@skip__*/` comment.

### 5. **Data.json**

The build script will create a `data.json` file based on the `jsonc` and `txt` files under `apps/{appname}` folder. The `data.json` file will be used to store data under SocialDB.

For instance, consider the following structure:

```
- apps
- {appname}
- {appname}
- something.txt
- types
- ui
- ui
- imageType.jsonc
- widget
- Button.metadata.jsonc
- Button.metadata.jsonc
```

The `data.json` file will appear as follows:
Expand All @@ -105,68 +117,10 @@ The `data.json` file will appear as follows:
}
```

### Excluding Files from `data.json`

The `@ignore` comment can be leveraged to omit a file from the `data.json` file. To execute this, add the following comment at the beginning of the file: `/*__@ignore__*/`.
To exclude files from the `data.json` file, add the `/*__@ignore__*/` comment to the file.

### jsonc Files
#### jsonc files

The jsonc files will be passed through JSON.stringify and stored in the `data.json` file, the build script will also remove all the comments and spaces from the jsonc files.
If you want to skip the JSON.stringify operation, add the following comment at the beginning of the file:
The jsonc files will be passed through JSON.stringify before being stored in the `data.json` file, the build script will also remove all the comments and spaces from the jsonc files.
If you want to skip the JSON.stringify operation and keep the structure, add the following comment at the beginning of the file:
`/*__@noStringify__*/`

## Development

bOS-workspace allows you to run a local server similar to `bos-loader` that can supply the widget's code to the bOS gateways for development purposes. To do so, run the following command:

```bash
# Install dependencies
yarn install
# Run the server
yarn dev
```

To access the local widgets, go to https://near.org/flags and add the following URL:
`http://127.0.0.1:4040/`

Note: The server will serve all the widgets from all the apps, each app under the account specified in `bos.config.json`. If an app uses a widget from another account that you have in the workspace, the gateway will show you the local widget instead of the remote one. That's great for working on multiple apps/accounts simultaneously.

## Build

To build the widgets for deployment, run the following command:

```bash
# Install dependencies
yarn install
# Build the widgets
yarn build
```

## Deploy

To start the deploy cli, run the following command:

```bash
yarn deploy
```

To deploy a specific app, run the following command:

```bash
yarn deploy {appname}
```

## Testing

To test the build/dev scripts, run the following command:

```bash
yarn test:tools
```

## Future Improvements (TODO)

- Improve the deployment of `data.json` to SocialDB.
- The build script should initially try to fetch the `data.json` structure file from SocialDB and will then only generate a `data.json` file containing the new changes, bypassing the remaining files.
- Testing framework for the bOS widgets, with the ability to mock the SocialDB, near and fetch.
- Make this README.md more clear, it's a mess right now.
6 changes: 0 additions & 6 deletions apps/dummyapp/bos.config.json

This file was deleted.

5 changes: 0 additions & 5 deletions apps/dummyapp/widget/hello.jsx

This file was deleted.

Loading
Loading