# @tuax/cli

> tuax 脚手架

Latest version **1.0.11** (published 2022-01-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install @tuax/cli
pnpm add @tuax/cli
yarn add @tuax/cli
bun add @tuax/cli
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.11 |
| Published | 2022-01-19 |
| First published | 2019-07-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 226.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | stevezyyang |
| Maintainers | knightwu, pastest, buptsteve |
| Keywords | 脚手架, 自动化 |

## Links

- npm: https://www.npmjs.com/package/@tuax/cli
- npm.io page: https://npm.io/package/@tuax/cli

## Dependencies (6)

- [treeify](https://npm.io/package/treeify.md) ^1.1.0
- [fs-extra](https://npm.io/package/fs-extra.md) ^8.1.0
- [handlebars](https://npm.io/package/handlebars.md) ^4.4.3
- [log-symbols](https://npm.io/package/log-symbols.md) ^3.0.0
- [inquirer-fuzzy-path](https://npm.io/package/inquirer-fuzzy-path.md) ^1.0.0
- [babel-plugin-module-resolver](https://npm.io/package/babel-plugin-module-resolver.md) ^3.2.0

## Recent versions

- 1.0.11 (latest) — 2022-01-19
- 1.0.7-4 (next) — 2019-10-21
- 1.0.10 — 2020-07-17
- 1.0.9 — 2019-10-31
- 1.0.7-3 — 2019-10-17
- 1.0.7-2 — 2019-10-17
- 1.0.7-1 — 2019-10-17
- 1.0.7 — 2019-10-17
- 1.0.6 — 2019-10-17
- 1.0.5 — 2019-08-08
- 1.0.4 — 2019-07-31
- 1.0.3 — 2019-07-31
- 1.0.2 — 2019-07-31
- 1.0.1 — 2019-07-31
- 1.0.0 — 2019-07-30

## README

<h1 align="center">@tuax/cli</h1>

<p align="center">
    <a href="https://www.npmjs.com/package/@tuax/cli">
        <img src="https://img.shields.io/npm/v/@tuax/cli.svg" alt="Version">
        <img src="https://img.shields.io/npm/v/@tuax/cli/next.svg" alt="Next Version">
        <img src="https://img.shields.io/npm/l/@tuax/cli.svg" alt="License">
    </a>
</p>

## 介绍
这个包为tua提供了一些方便的命令，可以用于一键生成项目、创建页面、创建组件、创建 api 等功能。

## 安装

```bash
$ npm i -g tua
# OR
$ yarn global add tua
```

## 使用
### 初始化项目 `init`
这个命令从用户输入的模版地址拉取项目模版，替换package.json中的项目相关信息

```bash
$ tua init <project-name>
```

![](https://git.code.oa.com/sports-team/tua/uploads/69CB73D8CE7C4974B20302ADD481CF1C/tua-init.gif)

### 添加接口命令 `add api`
这个命令将添加一个新文件 `<name>.js` 到 `src/apis/` 下，并且如果不存在 `src/apis/index.js` 则会自动创建。

```bash
# 添加 api
$ tua add api <name>
# OR
$ tua a api <name>
```

该命令会自动在 `src/apis/index.js` 中导出该 `api`，例如 `<name>` 为 `foo-bar`，那么导出的接口名称为 `fooBarApi`（已转成小驼峰，并在结尾加上 `Api`）。


![](https://git.code.oa.com/sports-team/tua/uploads/6E62A5836E8643BF9FE6C333003963C4/tua-add-api.gif)

### 添加页面命令 `add page`
这个命令将添加一个新文件夹 `<name>` 到 `src/pages/` 下，

并且如果页面以**连字符**命名，那么相关的 `.vue` 文件会被转成**大驼峰**风格。

```
└─ pages
   ├─ ...
   └─ a-b           // 连字符
      ├─ AB.vue     // 大驼峰
      └─ index.js
```

options包含:
--wx -w 是否是小程序
--ssr -s 是否支持同构渲染

1. web端
```bash
# 添加简单页面 page
$ tua add page <name>
# OR
$ tua a page <name>
```

```bash
# 添加支持同构的页面 page
$ tua add page <name> --ssr
# OR
$ tua a page <name> -s
```

2. 小程序端
```bash
# 添加小程序端 page
$ tua add page <name> --wx
# OR
$ tua a page <name> -w
```

在小程序端，该命令会自动读取 `src/app/app.json` 中的 `pages` 字段，并将新页面加入。

![](https://git.code.oa.com/sports-team/tua/uploads/8522B64633C843369AB0D1C57F1C24D0/tua-add-page.gif)

### 添加组件命令 `add comp`
由于组件一般分为两种：

* 全局组件（位于 `src/comps/` 下）
* 页面组件（位于 `src/pages/foo-bar/comps/` 下）

所以这个命令有两种用法，添加可选的 `-g, --global` 参数表示添加全局组件，将添加一个新文件夹 `<name>` 到 `src/comps/` 下，否则会进行交互式询问模板文件夹的路径。

组件建议都使用**大驼峰**命名风格

options包含:
--wx -w 是否是小程序
--ssr -s 是否支持同构渲染
--global -g 是否添加全局组件

1. web端
```
└─ comps
   ├─ ...
   └─ TuaImage.vue   // 大驼峰
```
* 全局添加简单组件
```bash
$ tua add comp <name> --global
# OR
$ tua a comp <name> -g
```

* 局部添加简单组件
```bash
$ tua add comp <name>
# OR
$ tua a comp <name>
```

* 全局添加支持同构的组件
```bash
$ tua add comp <name> --global --ssr
# OR
$ tua a comp <name> -g -s
```

* 局部添加支持同构的组件
```bash
$ tua add comp <name> --ssr
# OR
$ tua a comp <name> -s
```

2. 小程序端
```
└─ comps
   ├─ ...
   └─ TuaImage          // 大驼峰
      ├─ TuaImage.vue   // 大驼峰
      └─ index.js
```

* 全局添加小程序端 comp(-g, --global)

```bash
$ tua add comp <name> --global --wx
# OR
$ tua a comp <name> -g -w
```

* 局部添加小程序端 comp

```bash
$ tua add comp <name> --wx
# OR
$ tua a comp <name> -w
```

> 注意使用 `<Tab>` 键补全路径，输入不存在的文件夹时会自动创建。

![](https://git.code.oa.com/sports-team/tua/uploads/C3D8FED6634A4059A6639DA577E43D77/tua-add-comp.gif)

### 导出模板命令 `eject` <Badge text="0.3.0+"/>
这个命令将包中的默认模板导出到当前项目的 `.templates/` 中。

这样通过修改`.templates/` 下的模板文件，即可实现自定义模板功能。

```bash
$ tua eject
# OR
$ tua e
```

### 生成接口声明命令 `declare` <Badge text="0.4.0+"/>
这个命令将读取导出的 apis 然后自动生成 `index.d.ts`。

```bash
$ tua declare [apisPath]
# OR
$ tua dc [apisPath]
```

* `apisPath` 默认值为 `src/apis/index.js`
* `index.d.ts` 将生成在 `apisPath` 同级目录下

在 `index.d.ts` 已存在的情况下，默认会提示是否覆盖，每次都要手动确认有点儿不方便。所以添加了一个参数 `--yes, -y`，表示默认覆盖文件。<Badge text="0.5.0+"/>

```bash
$ tua declare --yes [apisPath]
# OR
$ tua dc -y [apisPath]
```

由于使用 `require` 读取导出 apis 对象的文件，所以可能会碰到 `alias` 问题。例如项目中设置了 `@` 作为 `./src/` 的别名。虽然 `@tua/cli` 已内置了一些 `alias`，但你仍然可以自由配置。

在 `.tuarc` 中的 `alias` 选项会透传给 [babel-plugin-module-resolver](https://github.com/tleunen/babel-plugin-module-resolver)，例如将 `foobar` 指向 './src/foobar' 可以这么配置：

```js
// .tuarc
module.exports = {
    alias: {
        'foobar': './src/foobar',
    },
}
```

## 配置
### templateDir <Badge text="0.3.0+"/>
* 类型：`String`
* 默认值：`.templates`

自定义模板的路径。

### alias <Badge text="0.4.0+"/>
* 类型：`Object`
* 默认值：[请点击这里查看源码](https://git.code.oa.com/sports-team/tua/blob/master/packages/@tuax/cli/src/constants.js)

设置路径别名对象。

**读取模板的优先级逻辑是：**

1. 首先尝试使用 `.tuarc` 中的 `templateDir` 字段
2. 接着尝试读取 `.templates/`
3. 最后读取默认模板

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