Skip to content

Commit 95c7585

Browse files
committed
fix: move cli to a separate npm package
1 parent ed20ac1 commit 95c7585

File tree

10 files changed

+1850
-11
lines changed

10 files changed

+1850
-11
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ stats.json
2525
e2e/.build/
2626
cypress/
2727
bundles
28-
bin/cli.js
28+
cli/index.js
2929

3030
/benchmark/revisions
3131

.npmignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
!bundles/
22
!package.json
3-
!README.md
4-
!bin/cli.js
3+
!README.md

cli/.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
!index.js
2+
!package.json
3+
!README.md

cli/README.md

Whitespace-only changes.

bin/cli.ts renamed to cli/index.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as zlib from 'zlib';
77
import { resolve } from 'path';
88

99
// @ts-ignore
10-
import { Redoc, loadAndBundleSpec, createStore } from '../';
10+
import { Redoc, loadAndBundleSpec, createStore } from 'redoc';
1111

1212
import { createReadStream, writeFileSync, ReadStream, readFileSync, watch, existsSync } from 'fs';
1313

@@ -53,7 +53,7 @@ yargs
5353
try {
5454
await serve(argv.port, argv.spec, { ssr: argv.ssr, watch: argv.watch });
5555
} catch (e) {
56-
console.log(e.message);
56+
console.log(e.stack);
5757
}
5858
},
5959
)
@@ -142,19 +142,24 @@ async function serve(port: number, pathToSpec: string, options: Options = {}) {
142142
}
143143

144144
async function bundle(pathToSpec, options: Options = {}) {
145+
const start = Date.now();
145146
const spec = await loadAndBundleSpec(pathToSpec);
146147
const pageHTML = await getPageHTML(spec, pathToSpec, { ...options, ssr: true });
148+
147149
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+
);
150155
}
151156

152157
async function getPageHTML(spec: any, pathToSpec: string, { ssr, cdn }: Options) {
153158
let html, css, state;
154159
let redocStandaloneSrc;
155160
if (ssr) {
156161
console.log('Prerendering docs');
157-
let store = await createStore(spec, pathToSpec);
162+
const store = await createStore(spec, pathToSpec);
158163
const sheet = new ServerStyleSheet();
159164
html = renderToString(sheet.collectStyles(React.createElement(Redoc, { store })));
160165
css = sheet.getStyleTags();
@@ -165,7 +170,8 @@ async function getPageHTML(spec: any, pathToSpec: string, { ssr, cdn }: Options)
165170
}
166171
}
167172

168-
return `<html>
173+
return `<!DOCTYPE html>
174+
<html>
169175
<head>
170176
<meta charset="utf8" />
171177
<title>ReDoc</title>

0 commit comments

Comments
 (0)