# bt_app 快速开始

## 纯 HTML 项目
在空目录创建 `index.html`：

```html
<!doctype html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
</head>
<body>
  <h1>Hello BT App</h1>
</body>
</html>
```

在该目录运行：

```bash
./bt_app.exe run
```

首次运行时，如果目录中没有 `app.json`，bt_app 会自动生成默认 `app.json`，并在缺少 `main.bt` 时创建空的 `main.bt`。窗口标题、尺寸、入口、资源等配置都以 `app.json` 为准。

也可以直接双击 `bt_app.exe`，前提是当前工作目录就是项目目录。

## app.json 项目
创建 `app.json`：

```json
{
  "app": {
    "name": "HelloApp",
    "title": "Hello BT App",
    "mode": "static",
    "entry": "index.html",
    "main": "main.bt"
  },
  "window": {
    "width": 900,
    "height": 700,
    "resizable": true
  },
  "dev": {
    "watch": true,
    "delay": 500,
    "devtools": true,
    "console": true
  },
  "resources": [
    "index.html",
    "main.bt",
    "assets/**"
  ],
  "exclude": []
}
```

创建 `main.bt`：

```bt
fn hello(args) {
    return {
        error:false,
        message:'ok',
        data:'Hello ' + args.name
    }
}
```

在页面中调用：

```html
<button id="btn">调用 BT</button>
<pre id="out"></pre>
<script>
document.getElementById('btn').onclick = async () => {
  const result = await window.bt.call('hello', { name: 'BT' });
  document.getElementById('out').textContent = JSON.stringify(result, null, 2);
};
</script>
```

## 打包
在项目目录运行：

```bash
./bt_app.exe build
```

打包结果输出到：

```text
dist/HelloApp.exe
```

## 注意事项
- `static` 模式下 `entry` 必须是项目内相对路径。
- `server` 和 `remote` 模式下 `entry` 必须是 `http://` 或 `https://` 地址。
- `app.main` 省略、`true` 或 `null` 时会自动尝试执行 `main.bt`；写成 `false` 或空字符串表示不执行主脚本。
- 当前 `app.icon` 只支持项目内 `.ico` 文件。
- `index.html` 不再提供应用配置；需要打包的样式、脚本和图片请写入 `resources`。
- 开发目录运行时，`resources - exclude` 中的文件保存后会自动刷新页面；也可以按 `F5`、`Ctrl+R` 或 `Cmd+R` 手动刷新。
