(...params: Array<any>)
| 44 | } |
| 45 | |
| 46 | async function main(...params: Array<any>) { |
| 47 | const contents = fs.readFileSync(jsFile, 'utf8'); |
| 48 | |
| 49 | const comments = getFormulaComments(contents); |
| 50 | const result = comments.map(item => { |
| 51 | const ast = doctrine.parse(item.comments, { |
| 52 | unwrap: true |
| 53 | }); |
| 54 | const result: any = { |
| 55 | name: item.fnName, |
| 56 | description: ast.description |
| 57 | }; |
| 58 | |
| 59 | let example = ''; |
| 60 | let params: Array<any> = []; |
| 61 | let returns: any = undefined; |
| 62 | let namespace = ''; |
| 63 | ast.tags.forEach(tag => { |
| 64 | if (tag.title === 'example') { |
| 65 | example = tag.description!; |
| 66 | } else if (tag.title === 'namespace') { |
| 67 | namespace = tag.name!; |
| 68 | } else if (tag.title === 'param') { |
| 69 | params.push({ |
| 70 | type: formatType(tag.type), |
| 71 | name: tag.name, |
| 72 | description: tag.description |
| 73 | }); |
| 74 | } else if (tag.title === 'returns') { |
| 75 | returns = { |
| 76 | type: formatType(tag.type), |
| 77 | description: tag.description |
| 78 | }; |
| 79 | } |
| 80 | }); |
| 81 | |
| 82 | result.example = example; |
| 83 | result.params = params; |
| 84 | result.returns = returns; |
| 85 | result.namespace = namespace; |
| 86 | |
| 87 | return result; |
| 88 | }); |
| 89 | |
| 90 | fs.writeFileSync( |
| 91 | outputFile, |
| 92 | `/**\n * 公式文档 请运行 \`npm run genDoc\` 自动生成\n */\n |
| 93 | import {bulkRegisterFunctionDoc} from './function'; |
| 94 | |
| 95 | bulkRegisterFunctionDoc(${JSON.stringify(result, null, 2).replace( |
| 96 | /\"(\w+)\"\:/g, |
| 97 | (_, key) => `${key}:` |
| 98 | )}); |
| 99 | `, |
| 100 | 'utf8' |
| 101 | ); |
| 102 | console.log(`公式文档生成 > ${outputFile}`); |
| 103 |
no test coverage detected