Skip to content

Commit

Permalink
Merge pull request #9 from ohos-rs/feat-doc
Browse files Browse the repository at this point in the history
feat: add some zh doc
  • Loading branch information
richerfu authored Jun 25, 2024
2 parents 2821876 + 4b716bd commit 9c9c1ba
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 58 deletions.
1 change: 1 addition & 0 deletions .vitepress/i18n/zh/BasicSideBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const BasicSideBar: DefaultTheme.SidebarItem[] = [
{ text: "init", link: "/docs/cli/init" },
{ text: "build", link: "/docs/cli/build" },
{ text: "artifact", link: "/docs/cli/artifact" },
{ text: "cargo", link: "/docs/cli/cargo" },
],
},
{
Expand Down
21 changes: 9 additions & 12 deletions src/docs/cli/artifact.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,21 @@
editLink: true
---

# Artifact
# artifact

This command will help us to generate the package for `ohpm`.
这个子命令能够帮助我们去生成对应的 ohpm 平台的 har 文件。

## Usage
## 用法

Standard command will be:
标准用法如下所示:

```shell
ohrs artifact
```

## 参数

## Arguments

It supports some special options.

| Options | description | type | default |
|---------|:--------------------------------------------------------------------------------------------------------|:---------|:----------|
| dist | The build command should be aligned and kept consistent with the `dist` parameter in the build command. | `string` | `dist` |
| package | The name of the final har package | `string` | `package` |
| 参数 | 描述 | 类型 | 示例 |
|---------|:--------------------------------------------------|:---------|:-------------------------------|
| dist |`build``dist`参数匹配,当构建时修改了输出目录时,构建 har 文件时也需要修改。 | `string` | `ohrs artifact --dist=test` |
| package | 构建的 har 文件名,默认是`package` | `string` | `ohrs artifact --package=test` |
Binary file removed src/docs/cli/assets/dist.png
Binary file not shown.
Binary file removed src/docs/cli/assets/new_folder.png
Binary file not shown.
60 changes: 27 additions & 33 deletions src/docs/cli/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,64 +3,58 @@ editLink: true
outline: "deep"
---

# Build
# build

As another useful subcommand, it helps us to build the final binary and generate `.d.ts`. Standard command will be:
作为另一个常见的子命令,`build`命令提供给我们构建产物、收集产物以及输出类型声明文件等能力。

## 用法

一个标准的 build 命令使用如下所示:

```shell
ohrs build
```

It supports some special options.
## 参数

| Options | description | type | default |
|---------|:------------------------------------------------------------------------------------------------------|:----------|:--------|
| release | build mode,if it be set with true, project will build with `release` mode | `boolean` | false |
| dist | The final binary's folder | `string` | dist |
| strip | Use `llvm-strip` to reduce the size of the binary files. Set the mode to true if it's in release mode | `boolean` | true |
| 参数 | 描述 | 类型 | 使用示例 |
|---------|:--------------------------------------------------|:----------|:--------------------------|
| release | 构建模式,默认为`debug`模式,设置后将构建`release`产物 | `boolean` | `ohrs build --release` |
| dist | 收集产物的最终输出文件夹 | `string` | `ohrs build --dist=test` |
| arch | 构建的目标架构,支持 `arm64/aarch` `arm/arm32` `x86_64/x64` | `string` | `ohrs build --arch=aarch` |


## Usage
## 额外的一些使用案例

Here are some examples to use them.
### 支持自定义参数

### --release
在之前的脚手架版本,我们只能使用脚手架预置的参数来参与到构建中去,现在我们的`build`命令已经支持完全的自定义参数了。

比如我们想要输出更加详细的构建过程,我们一般会使用如下的构建命令来实现:
```shell
ohrs build --release
cargo build -v
```

If we use `--release`, project will build with `release` mode.

### --compact
在 ohrs 中我们现在可以使用如下的脚本来实现类似的能力:

```shell
ohrs build --compact
ohrs build -- -v
```

If we use `--compact`, the final folder will be:
这样既提供了 ohos 的环境也能够满足业务的自定义使用场景。

![Dist](assets/dist.png)
### 构建多目标产物

All the final binary will in a same folder.
在上面的支持参数中可以发现,我们其实是支持构建指定的架构内容。当我们不传入`arch`参数的时候,默认会构建全部架构(arm64-v8a、armeabi-v7a、x86_64)。通过 arch 参数我们可以指定构建的平台。

### --dist new_folder
构建一个平台

```shell
cargo build --dist new_folder
ohrs build --arch aarch
```

Now, the final project structure will be:

![Dist](assets/new_folder.png)


### --strip
构建两个平台

```shell
# enabled
cargo build --strip

# disabled
cargo build --strip=false
```
ohrs build --arch aarch --arch x64
```
18 changes: 18 additions & 0 deletions src/docs/cli/cargo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
editLink: true
outline: "deep"
---

# cargo

该命令从`0.5.0`的版本开始支持,用于提供给需要构建环境的 cargo 子命令执行。

## 用法

标准用法如下所示:

```shell
ohrs cargo expand
```

实际上就是提供了 ohos 的构建环境去执行`cargo expand`命令。
25 changes: 12 additions & 13 deletions src/docs/cli/init.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
editLink: true
---

# Init
# init

`ohrs` provide some useful subcommand to help us initial and build project.
`ohrs` 提供了一些有用的子命令来协助我们进行项目初始化、构建以及其他操作。

## Usage
## 用法

`init` is a subcommand with `ohrs`, a standard command just be here:
`init` ohrs 的一个子命令,其标准使用方法如下所示:

```shell
ohrs init xx
```

Tool will create a folder named `xx`, and it will be also as project's name in `Cargo.toml`. So `Cargo.toml` will be like:
脚手架将会创建一个名为`xx`的文件夹,并且其在`Cargo.toml`文件中的项目名也会为这个名字,其文件内容如下所示:

```toml
[package]
Expand All @@ -23,15 +23,14 @@ version = "0.1.0"
edition = "2021"
```

And the final prebuild binary's name will be `libxx.so`.
当然最终的构建产物名会变成跟这个保持一致: `libxx.so`

::: danger Don't do it
Don't use some special name. For example: `test` `crate` `fn` etc.
::: danger 注意
不要使用一些特殊的字符。 比如: `test` `crate` `fn` 等等.
:::

## Arguments
## 支持参数


| Options | description | type | default |
|---------|:----------------------------------------------------------------------------------------------------------------------------------------------------|:--------------------|:--------|
| package | This will generate an OHPM package, which won't be created by default. If you input a string, it will replace the `name` field in oh-package.json5. | `boolean \| string` | false |
| 参数名 | 描述 | 类型 | 示例 |
|---------|:---------------------|:---------|:---------------------------------|
| package | 创建 ohpm 的包模版,名称可以自定义 | `string` | `ohrs init hello -p=@ohrs/hello` |

0 comments on commit 9c9c1ba

Please sign in to comment.