根据提供的 schema 和配置生成服务文件。
Kind: global function
Returns: Promise.<void> -
- 返回一个 Promise,当所有操作完成时 resolve。
| Param | Type | Description |
|---|---|---|
| schemaPath | string |
schema 的路径。 |
| config | ConfigOptions |
配置选项。 |
| config.templateDir | string |
模板目录的路径。 |
| config.outputPath | string |
输出目录的路径。 |
| config.prefix | string |
api 的前缀。 |
| config.pathReg | string |
对路径进行正则判断,不符合的路径不生成。 |
| config.ignore | Array.<string> |
忽略的路径列表。 |
| config.dir | string |
生成的 api 文件的目录。 |
| config.requestStr | string |
请求方法代码,默认为import request from '@/utils/request'; |
| config.mode | 'ts' | 'js' |
生成文件的模式('ts' 或 'js')。 |
Example
// generateService 的使用示例
generateService('schemaPath', {
templateDir: 'path/to/template',
outputPath: 'path/to/output',
prefix: 'api',
ignore: ['ignore1', 'ignore2'],
dir: 'api',
mode: 'ts'
});