@@ -9,6 +9,7 @@ const fg = require("fast-glob");
9
9
const write = require ( "write" ) ;
10
10
const ora = require ( "ora" ) ;
11
11
const chalk = require ( "chalk" ) ;
12
+ const fs = require ( "fs" ) ;
12
13
const resolve = util . resolve ;
13
14
14
15
module . exports = function (
@@ -19,6 +20,9 @@ module.exports = function(
19
20
) {
20
21
path = resolve ( path || "." ) ;
21
22
const config = util . getConfig ( configFile ) ;
23
+ // docs absolute path
24
+ config . path = path ;
25
+
22
26
const server = connect ( ) ;
23
27
const indexFile = resolve ( path , indexName || "index.html" ) ;
24
28
const render = new Renderer ( config ) ;
@@ -31,21 +35,28 @@ module.exports = function(
31
35
spinner . start ( "Rendering" ) ;
32
36
33
37
getPort ( )
34
- . then ( port => {
38
+ . then ( async port => {
35
39
server . use ( serveStatic ( path , { index : indexFile } ) ) ;
36
40
app = server . listen ( port ) ;
37
41
38
- return Promise . all ( files . map ( file => render . render ( file ) ) ) ;
42
+ const queue = [ ] ;
43
+ for ( const file of files ) {
44
+ const res = await render . render ( file ) ;
45
+ queue . push ( res ) ;
46
+ spinner . text = "Rendering " + file ;
47
+ }
48
+ return queue ;
39
49
} )
40
50
. then ( data => {
41
51
// 保存文件
42
52
return Promise . all (
43
- data . map ( ( { url, content } ) => {
53
+ data . map ( ( { url, content, path } ) => {
44
54
const filePath = url
45
55
. replace ( / R E A D M E \. m d $ / , "index.html" )
46
56
. replace ( / \. m d $ / , ".html" ) ;
47
57
spinner . text = `Rendering ${ url } ` ;
48
58
write ( resolve ( util . cwd ( ) , dest , filePath ) , content ) ;
59
+ fs . copyFileSync ( path , resolve ( util . cwd ( ) , dest , url ) ) ;
49
60
} )
50
61
) ;
51
62
} )
0 commit comments