1+ /**
2+ *
3+ * Copyright 2020 Tencent
4+ *
5+ * Licensed under the Apache License, Version 2.0 (the "License");
6+ * you may not use this file except in compliance with the License.
7+ * You may obtain a copy of the License at
8+ *
9+ * http://www.apache.org/licenses/LICENSE-2.0
10+ *
11+ * Unless required by applicable law or agreed to in writing, software
12+ * distributed under the License is distributed on an "AS IS" BASIS,
13+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ * See the License for the specific language governing permissions and
15+ * limitations under the License.
16+ *
17+ */
18+
119const spawnPromise = require ( './spawn' ) ;
220const path = require ( 'path' ) ;
321const { readFileSync } = require ( 'fs' ) ;
@@ -11,19 +29,15 @@ const config = {
1129 // 渲染用户案例
1230 usercases : {
1331 async get ( ) {
14- const data = JSON . parse (
15- readFileSync ( path . join ( __dirname , '../community/usercases/index.json' ) )
16- ) ;
17- const renderCell = ( item ) => {
18- return `<td align="center"><a target="_blank" href="${
19- item . repo || item . link
20- } "><img width="100px;" src="${
21- item . logo ||
22- 'https://main.qcloudimg.com/raw/d56f7877c8fec451718459a3aa8bbc9a.png'
23- } "><br /><sub><b>${
24- item . name
25- } </b></sub></a><br/><a target="_blank" href="${ item . link } ">🌐</a></td>`;
26- } ;
32+ const data = JSON . parse ( readFileSync ( path . join ( __dirname , '../community/usercases/index.json' ) ) ) ;
33+ const renderCell = item => `<td align="center"><a target="_blank" href="${
34+ item . repo || item . link
35+ } "><img width="100px;" src="${
36+ item . logo
37+ || 'https://main.qcloudimg.com/raw/d56f7877c8fec451718459a3aa8bbc9a.png'
38+ } "><br /><sub><b>${
39+ item . name
40+ } </b></sub></a><br/><a target="_blank" href="${ item . link } ">🌐</a></td>`;
2741 const maxWidth = 5 ;
2842 return `
2943${ renderTable ( data , renderCell , maxWidth ) }
@@ -35,31 +49,25 @@ ${renderTable(data, renderCell, maxWidth)}
3549 // 渲染插件
3650 plugins : {
3751 async get ( ) {
38- const data = JSON . parse (
39- readFileSync ( path . join ( __dirname , '../community/plugins/index.json' ) )
40- ) ;
52+ const data = JSON . parse ( readFileSync ( path . join ( __dirname , '../community/plugins/index.json' ) ) ) ;
4153
4254 return `
4355| 插件链接 | 插件 | 最新版本 | 插件介绍 |
4456| -------- | ---- | -------- | -------- |
4557${ data
46- . map ( ( item ) => {
47- return (
48- `| <a href="${ item . link } "><img width="200" src="${ item . cover } "></a> | [${ item . npmPackageName } ](${ item . link } ) ` +
49- `|[]` +
50- `(https://www.npmjs.com/package/${ item . npmPackageName } )` +
51- ` | ${ item . description } |`
52- ) ;
53- } )
54- . join ( '\n' ) }
58+ . map ( item => `| <a href="${ item . link } "><img width="200" src="${ item . cover } "></a> | [${ item . npmPackageName } ](${ item . link } ) `
59+ + `|[]`
60+ + `(https://www.npmjs.com/package/${ item . npmPackageName } )`
61+ + ` | ${ item . description } |` )
62+ . join ( '\n' ) }
5563<!-- 新增/删除/修改插件信息,请修改 community/plugins/index.json,然后执行 npm run build:markdown-->
5664` ;
5765 } ,
5866 } ,
5967} ;
6068
6169function renderTable ( data , renderCell , maxWidth = 10 ) {
62- let rowsCount = Math . ceil ( data . length / maxWidth ) ;
70+ const rowsCount = Math . ceil ( data . length / maxWidth ) ;
6371 let content = '' ;
6472 for ( let i = 0 ; i < rowsCount ; i ++ ) {
6573 content += `
@@ -81,18 +89,10 @@ ${content}
8189
8290( async ( ) => {
8391 const defines = (
84- await Promise . all (
85- Object . entries ( config ) . map ( async ( [ define , defineConfig ] ) => {
86- return `--define.${ define } '${ await defineConfig . get ( ) } '` ;
87- } )
88- )
92+ await Promise . all ( Object . entries ( config ) . map ( async ( [ define , defineConfig ] ) => `--define.${ define } '${ await defineConfig . get ( ) } '` ) )
8993 ) . join ( ' ' ) ;
9094
91- await Promise . all (
92- markdownFiles . map ( ( mdFile ) =>
93- spawnPromise ( `npx mdmod ${ mdFile } ${ defines } ` , {
94- cwd : path . join ( __dirname , '../' ) ,
95- } )
96- )
97- ) ;
95+ await Promise . all ( markdownFiles . map ( mdFile => spawnPromise ( `npx mdmod ${ mdFile } ${ defines } ` , {
96+ cwd : path . join ( __dirname , '../' ) ,
97+ } ) ) ) ;
9898} ) ( ) ;
0 commit comments