diff --git a/cli/index.ts b/cli/index.ts index 19f75fde..ae989620 100644 --- a/cli/index.ts +++ b/cli/index.ts @@ -4,7 +4,7 @@ import { renderToString } from 'react-dom/server'; import { ServerStyleSheet } from 'styled-components'; import { createServer, ServerResponse, ServerRequest } from 'http'; import * as zlib from 'zlib'; -import { resolve } from 'path'; +import { join, dirname } from 'path'; // @ts-ignore import { Redoc, loadAndBundleSpec, createStore } from 'redoc'; @@ -20,6 +20,8 @@ type Options = { output?: string; }; +const BUNDLES_DIR = dirname(require.resolve('redoc')); + yargs .command( 'serve [spec]', @@ -98,9 +100,14 @@ async function serve(port: number, pathToSpec: string, options: Options = {}) { const server = createServer((request, response) => { console.time('GET ' + request.url); if (request.url === '/redoc.standalone.js') { - respondWithGzip(createReadStream('bundles/redoc.standalone.js', 'utf8'), request, response, { - 'Content-Type': 'application/javascript', - }); + respondWithGzip( + createReadStream(join(BUNDLES_DIR, 'redoc.standalone.js'), 'utf8'), + request, + response, + { + 'Content-Type': 'application/javascript', + }, + ); } else if (request.url === '/') { respondWithGzip(pageHTML, request, response); } else if (request.url === '/spec.json') { @@ -166,7 +173,7 @@ async function getPageHTML(spec: any, pathToSpec: string, { ssr, cdn }: Options) state = await store.toJS(); if (!cdn) { - redocStandaloneSrc = readFileSync(resolve(__dirname, '../bundles/redoc.standalone.js')); + redocStandaloneSrc = readFileSync(join(BUNDLES_DIR, 'redoc.standalone.js')); } } diff --git a/cli/package.json b/cli/package.json index 5ae4eb1b..e223f0d1 100644 --- a/cli/package.json +++ b/cli/package.json @@ -1,6 +1,6 @@ { "name": "redoc-cli", - "version": "0.1.0", + "version": "0.2.0", "description": "ReDoc's Command Line Interface", "main": "index.js", "bin": {