﻿# fa-toolkit

## 使用指南

1. 安装 fa-toolkit

```
npm install fa-toolkit -D
```

2. 构建快应用

在编译之前，请确保项目中存在签名文件。

1) 在安装fa-toolkit的路径下编译项目。

```
node node_modules/webpack/bin/webpack.js --config ./node_modules/fa-toolkit/webpack.config.js
```

查看编译进度。

```
node node_modules/webpack/bin/webpack.js --progress --config ./node_modules/fa-toolkit/webpack.config.js
```

2) 在任意路径中编译项目。

安装依赖项。

```
npm install cross-env -D
```

使用**projectRoot**参数指定快应用工程根路径。

```
node ./node_modules/cross-env/src/bin/cross-env.js projectRoot=D:\com.quick.app node_modules/webpack/bin/webpack.js --config ./node_modules/fa-toolkit/webpack.config.js
```

参数描述。

| 参数 | 数据类型 | 默认值| 描述 |
| -------  | --------- | --------- | --------- |
| projectRoot | string | *Current path*| Root directory, which must contain the **src** and **sign** directories and is the path where fa-toolkit is installed by default.|
| versionType | `debug` \| `beta` \| `release` | debug | Compilation version. The code will be compressed and the signature file for release is needed except for the debug version.|
| showtime | boolean | false | Indicates whether to display the compilation duration.|
| norpk | boolean | false | Indicates whether to not generate an RPK file.|
| --env privateKey | string | | Private key, which is a webpack compilation parameter. The **private.pem** file under the same directory of the certificate file is used by default if the certificate file matches the private key. However, if the **private.pem** is deleted, you can use this parameter to specify the private key. The private key is the string left after you delete the start line, end line, and line breaks. The characters contained in the private key string should match the regular expression of **\/[a-zA-Z0-9+/=]\/**.|

样例:

编译生成Release包。

```
node ./node_modules/cross-env/src/bin/cross-env.js projectRoot=D:\com.quick.app versionType=release node_modules/webpack/bin/webpack.js --config ./node_modules/fa-toolkit/webpack.config.js
```

使用指定证书。

```
node ./node_modules/cross-env/src/bin/cross-env.js projectRoot=D:\com.quick.app versionType=release node_modules/webpack/bin/webpack.js --config ./node_modules/fa-toolkit/webpack.config.js --env privateKey=***
```

[OPEN SOURCE SOFTWARE NOTICE](https://developer.huawei.com/consumer/en/doc/development/quickApp-Guides/quickapp-v2-open-source-software-notice-0000001668157297)

3. 从微信小程序工程生成快应用工程
```
node ./lib/bin/wx2qa.js input.json
```
1) input.json替换成真实的配置文件路径, 配置文件内容如下：
```
{
    "method": "convert",
    "projectConfig": {
        "sourceType": "wx",
        "path": "",
        "dist": ""
    },
    "appConfig":{
        "packageName": "", 
        "appName": "",
        "versionCode": "1",
        "versionName": "1.0.0",
        "icon": ""
    },
    "resConfig": {
        
    }
}
```
2) 参数描述

| 参数 | 数据类型 | 默认值| 是否必填 | 描述 |
| -------  | --------- | --------- | --------- | --------- |
| method | string | convert| yes | 可选值 [convert\|check], 分别代表 转化 和 检查输入工程是否符合规范 |
| sourceType | string | wx | yes |  输入工程的平台, 当前仅支持 [wx] |
| path | string | - | yes |  输入微信工程的路径 |
| dist | string | - | yes |  快应用工程的输出路径 |
| packageName | string | - | yes |  package name |
| appName | string | - | yes |  app name |
| versionCode | string | 1 | yes |  版本号 |
| versionName | string | 1.0.0 | yes |  版本名 |
| icon | string | - | yes |  图标文件的路径 |

3. 输出

运行结果可以在console窗口查看, 根据两种不同的method [convert\|check]，有两种输出结果。

当method是convert时, 输出结果如下
```
{
    command: 'completeTransform',
    errorMessage: '...',
    folderUrl: '...'
}
```
| 参数 | 数据类型 | 默认值| 是否必填 | 描述 |
| -------  | --------- | --------- | --------- | --------- |
| command | string | completeTransform| yes | 可能的值有 [completeTransform\|failedTransform\|notifyConfig], 分别代表成功\|失败\|提示缺少文件 |
| errorMessage | string | - | no | 当转换失败时，提示失败原因 |
| folderUrl | string | - | no |  转换成功时，提示转换后的快应用工程路径 |

当method是check时, 输出结果如下
```
{
    command: 'postInputPath',
    data: {
        returnCode: true,
        outPath: '...'
    }
}
```
| 参数 | 数据类型 | 默认值| 是否必填 | 描述 |
| -------  | --------- | --------- | --------- | --------- |
| command | string | postInputPath| yes | 仅可能为postInputPath |
| returnCode | boolean | true | yes | 检查结果 |
| outPath | string | - | no |  建议的快应用工程输出路径 |