# th-remote-build-cli

> 脚手架监听当前的文件修改，将修改的文件上传远程编译服务，和主项目的代码进行合并后编译完整项目，然后将产出物返回给客户端

Latest version **0.0.17** (published 2022-08-22) · ISC license · 0 weekly downloads

## Install

```sh
npm install th-remote-build-cli
pnpm add th-remote-build-cli
yarn add th-remote-build-cli
bun add th-remote-build-cli
```

Provides the command `thbuild`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.17 |
| Published | 2022-08-22 |
| First published | 2021-11-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 19 |
| Unpacked size | 27.1 KB |
| Known vulnerabilities | 0 (+8 in 3 direct dependencies) |
| Install scripts | no |
| Maintainers | hellking66666, niujingliang |

## Links

- npm: https://www.npmjs.com/package/th-remote-build-cli
- npm.io page: https://npm.io/package/th-remote-build-cli

## Dependencies (19)

- [ora](https://npm.io/package/ora.md) ^5.4.1
- [uuid](https://npm.io/package/uuid.md) ^8.3.2
- [chalk](https://npm.io/package/chalk.md) ^4.1.2
- [merge](https://npm.io/package/merge.md) ^2.1.1
- [crypto](https://npm.io/package/crypto.md) ^1.0.1
- [is-glob](https://npm.io/package/is-glob.md) ^4.0.3
- [js-yaml](https://npm.io/package/js-yaml.md) ^4.1.0
- [request](https://npm.io/package/request.md) ^2.88.2
- [webpack](https://npm.io/package/webpack.md) ^5.64.4
- [anymatch](https://npm.io/package/anymatch.md) ^3.1.2
- [chokidar](https://npm.io/package/chokidar.md) ^3.5.2
- [commander](https://npm.io/package/commander.md) ^8.3.0
- [env-paths](https://npm.io/package/env-paths.md) ^2.2.1
- [exit-hook](https://npm.io/package/exit-hook.md) ^2.2.1
- [js-base64](https://npm.io/package/js-base64.md) ^3.7.2
- [args-parser](https://npm.io/package/args-parser.md) ^1.3.0
- [request-promise](https://npm.io/package/request-promise.md) ^4.2.6
- [webpack-dev-server](https://npm.io/package/webpack-dev-server.md) ^4.7.4
- [html-webpack-plugin](https://npm.io/package/html-webpack-plugin.md) ^5.5.0

## Recent versions

- 0.0.17 (latest) — 2022-08-22
- 0.0.15 — 2022-04-20
- 0.0.14 — 2022-04-07
- 0.0.12 — 2022-03-18
- 0.0.11 — 2022-02-22
- 0.0.10 — 2022-02-18
- 0.0.9 — 2021-12-23
- 0.0.8 — 2021-12-08
- 0.0.7 — 2021-12-03
- 0.0.6 — 2021-12-02
- 0.0.5 — 2021-12-02
- 0.0.4 — 2021-12-02
- 0.0.3 — 2021-11-30
- 0.0.2 — 2021-11-26

## README

# 远程镜像编译构建脚手架

脚手架监听当前的文件修改，将修改的文件上传远程编译服务，和主项目的代码进行合并后编译完整项目，然后将产出物返回给客户端

PS. 目前仅支持小程序远程开发


## 使用

### 1. 安装脚手架
```bash
# 全局安装脚手架
$ npm i th-remote-build-cli -g
```
### 2. 项目中增加配置文件

在子项目根目录下创建thbuild.config.js文件

```js
export default {
    // 远端项目名称（必须）
    appname: 'my-app-mini',

    // 本地项目源码监听目录，用于监听文件改动，只能相对路径，默认：'./src'
    rootDir: './src',

    // 构建产出物目录，只能相对路径，默认：'./dist'
    outDir: './dist',

    // 构建环境服务的地址，默认：空
    buildUrl: 'http://www.test.com/dev/compile/',

    // 源码和远程项目的对应路径(和本地路径是相对路径关系)，慎用此选项，一般用于映射目录
    // 例如：项目源代码监听目录为./，远端项目目录./src/customer-service-mini，此字段配置为./src/customer-service-mini
    // 监听到pages/index.vue文件改动，则组装成./src/customer-service-mini/pages/index.vue上传至远端
    // 暂时不支持路径穿越，待废弃，准备迁移至远端配置
    remoteRootDir: '',

    // 代码合并模式， 可选值：0: 整文件合并（默认值）,1: 片段
    // 片段模式下，配合startTag和endTag来按规则匹配
    mergeType: 0,
    startTag: "<template>",
    endTag: "</template>",

    checkStatusSleepTime: 1500, // 检查状态等待时间（单位毫秒），默认: 1500

    // 忽略在rootDir下文件监听
    ignored: [
        /node_modules/,
        /dist/,
        /scripts/,
        /\.git/,
        /submodules/,
        /package-lock\.json/,
        /README\.md/,
        /\.gitignore/,
        /\.gitmodules/,
        /package\.json/
    ],
}
```

## 编译命令

### **thbuild [cmd] --help**
查询帮助
```bash
$ thbuild --help
$ thbuild exec --help
```

### **thbuild login [option]**
登录命令

|  选项  |  是否必填  |  默认值  | 描述 |
|  ----  | ----  | ----  | ---- |
| -u, --username | 是 |   | 用户名 |
| -s, --secret-key | 是 |   | secret |

```bash
# 登录命令（Demo）
$ thbuild login -u test -s abcdefg
```

### **thbuild logout**
退出登录
```bash
# 退出登录命令（Demo）
$ thbuild logout
```

### **thbuild status**
查询远程构建环境的运行状态（包括当前分支、构建命令以及远端构建环境状态）
```bash
$ thbuild status
# 输出（Demo）
branch: sprint 
cmd: npm run dev:minitest 
status: 已就绪
```

### **thbuild branch [option] <branch>**
1.查询远程构建环境可以支持切换的所有分支

2.切换远程构建环境分支

|  选项  |  是否必填  |  默认值  | 描述 |
|  ----  | ----  | ----  | ---- |
| -l, --list | 否 |   | 列出远程的所有可用分支 |

|  参数  |  是否必填  |  默认值  | 描述 |
|  ----  | ----  | ----  | ---- |
| branch | 是 |   | 切换远程构建环境分支 |

```bash
$ thbuild branch -l # 列出远程的所有可用分支
# 输出（Demo）
* sprint
master

$ thbuild branch sprint # 切换构建环境到sprint分支
```

### **thbuild exec [option] <cmd>**
在远程环境下执行指定的命令

|  选项  |  是否必填  |  默认值  | 描述 |
|  ----  | ----  | ----  | ---- |
| -n, --appname | 否 |   | 对应远程环境的项目名称(可用项目配置文件代替读取) |
| -opt, --option | 否 |   | 远程编译使用的配置参数(可用项目配置文件代替读取) |
| -l, --list | 否 |   | 列出远程可使用的执行命令 |

|  参数  |  是否必填  |  默认值  | 描述 |
|  ----  | ----  | ----  | ---- |
| cmd | 是 |   | 远程构建环境执行的命令 |

```bash
$ thbuild exec 'npm run dev' # 远程构建环境执行npm run dev

$ thbuild exec -l # 列出远程可使用的执行命令
# 输出（Demo）
npm run dev
npm run dev:prod
npm run dev:txjk
* npm run dev:minitest
```

### **thbuild rebuild**
重新部署远端项目（更新远端项目代码）
```bash
$ thbuild rebuild
```

### **thbuild reset**
重置远端项目（撤销已改动的文件）
```bash
$ thbuild reset
```

### **thbuild watch**
启动编译&&监听文件修改
```bash
$ thbuild watch
```

### **thbuild start**
启动远端编译进程
```bash
thbuild start
```

### **thbuild stop**
停止远端编译进程
```bash
thbuild stop
```

---
_Source: https://npm.io/package/th-remote-build-cli · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
