@@ -7,7 +7,7 @@ import * as zlib from 'zlib';
7
7
import { resolve } from 'path' ;
8
8
9
9
// @ts -ignore
10
- import { Redoc , loadAndBundleSpec , createStore } from '../ ' ;
10
+ import { Redoc , loadAndBundleSpec , createStore } from 'redoc ' ;
11
11
12
12
import { createReadStream , writeFileSync , ReadStream , readFileSync , watch , existsSync } from 'fs' ;
13
13
53
53
try {
54
54
await serve ( argv . port , argv . spec , { ssr : argv . ssr , watch : argv . watch } ) ;
55
55
} catch ( e ) {
56
- console . log ( e . message ) ;
56
+ console . log ( e . stack ) ;
57
57
}
58
58
} ,
59
59
)
@@ -142,19 +142,24 @@ async function serve(port: number, pathToSpec: string, options: Options = {}) {
142
142
}
143
143
144
144
async function bundle ( pathToSpec , options : Options = { } ) {
145
+ const start = Date . now ( ) ;
145
146
const spec = await loadAndBundleSpec ( pathToSpec ) ;
146
147
const pageHTML = await getPageHTML ( spec , pathToSpec , { ...options , ssr : true } ) ;
148
+
147
149
writeFileSync ( options . output ! , pageHTML ) ;
148
- const sizeInKb = Math . ceil ( Buffer . byteLength ( pageHTML ) / 1024 ) ;
149
- console . log ( `\n🎉 bundled successfully in: ${ options . output ! } (${ sizeInKb } kB)` ) ;
150
+ const sizeInKiB = Math . ceil ( Buffer . byteLength ( pageHTML ) / 1024 ) ;
151
+ const time = Date . now ( ) - start ;
152
+ console . log (
153
+ `\n🎉 bundled successfully in: ${ options . output ! } (${ sizeInKiB } KiB) [⏱ ${ time / 1000 } s]` ,
154
+ ) ;
150
155
}
151
156
152
157
async function getPageHTML ( spec : any , pathToSpec : string , { ssr, cdn } : Options ) {
153
158
let html , css , state ;
154
159
let redocStandaloneSrc ;
155
160
if ( ssr ) {
156
161
console . log ( 'Prerendering docs' ) ;
157
- let store = await createStore ( spec , pathToSpec ) ;
162
+ const store = await createStore ( spec , pathToSpec ) ;
158
163
const sheet = new ServerStyleSheet ( ) ;
159
164
html = renderToString ( sheet . collectStyles ( React . createElement ( Redoc , { store } ) ) ) ;
160
165
css = sheet . getStyleTags ( ) ;
@@ -165,7 +170,8 @@ async function getPageHTML(spec: any, pathToSpec: string, { ssr, cdn }: Options)
165
170
}
166
171
}
167
172
168
- return `<html>
173
+ return `<!DOCTYPE html>
174
+ <html>
169
175
<head>
170
176
<meta charset="utf8" />
171
177
<title>ReDoc</title>
0 commit comments