fix: move cli to a separate npm package

This commit is contained in:
Roman Hotsiy 2018-03-18 11:15:17 +02:00
parent ed20ac1298
commit 95c7585628
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
10 changed files with 1850 additions and 11 deletions

2
.gitignore vendored
View File

@ -25,7 +25,7 @@ stats.json
e2e/.build/
cypress/
bundles
bin/cli.js
cli/index.js
/benchmark/revisions

View File

@ -1,4 +1,3 @@
!bundles/
!package.json
!README.md
!bin/cli.js
!README.md

3
cli/.npmignore Normal file
View File

@ -0,0 +1,3 @@
!index.js
!package.json
!README.md

0
cli/README.md Normal file
View File

View File

@ -7,7 +7,7 @@ import * as zlib from 'zlib';
import { resolve } from 'path';
// @ts-ignore
import { Redoc, loadAndBundleSpec, createStore } from '../';
import { Redoc, loadAndBundleSpec, createStore } from 'redoc';
import { createReadStream, writeFileSync, ReadStream, readFileSync, watch, existsSync } from 'fs';
@ -53,7 +53,7 @@ yargs
try {
await serve(argv.port, argv.spec, { ssr: argv.ssr, watch: argv.watch });
} catch (e) {
console.log(e.message);
console.log(e.stack);
}
},
)
@ -142,11 +142,16 @@ async function serve(port: number, pathToSpec: string, options: Options = {}) {
}
async function bundle(pathToSpec, options: Options = {}) {
const start = Date.now();
const spec = await loadAndBundleSpec(pathToSpec);
const pageHTML = await getPageHTML(spec, pathToSpec, { ...options, ssr: true });
writeFileSync(options.output!, pageHTML);
const sizeInKb = Math.ceil(Buffer.byteLength(pageHTML) / 1024);
console.log(`\n🎉 bundled successfully in: ${options.output!} (${sizeInKb} kB)`);
const sizeInKiB = Math.ceil(Buffer.byteLength(pageHTML) / 1024);
const time = Date.now() - start;
console.log(
`\n🎉 bundled successfully in: ${options.output!} (${sizeInKiB} KiB) [⏱ ${time / 1000}s]`,
);
}
async function getPageHTML(spec: any, pathToSpec: string, { ssr, cdn }: Options) {
@ -154,7 +159,7 @@ async function getPageHTML(spec: any, pathToSpec: string, { ssr, cdn }: Options)
let redocStandaloneSrc;
if (ssr) {
console.log('Prerendering docs');
let store = await createStore(spec, pathToSpec);
const store = await createStore(spec, pathToSpec);
const sheet = new ServerStyleSheet();
html = renderToString(sheet.collectStyles(React.createElement(Redoc, { store })));
css = sheet.getStyleTags();
@ -165,7 +170,8 @@ async function getPageHTML(spec: any, pathToSpec: string, { ssr, cdn }: Options)
}
}
return `<html>
return `<!DOCTYPE html>
<html>
<head>
<meta charset="utf8" />
<title>ReDoc</title>

1342
cli/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

20
cli/package.json Normal file
View File

@ -0,0 +1,20 @@
{
"name": "@redoc/cli",
"version": "0.0.1",
"description": "ReDoc's Command Line Interface",
"main": "index.js",
"bin": {
"redoc": "index.js"
},
"repository": "https://github.com/Rebilly/ReDoc",
"author": "Roman Hotsiy <gotsijroman@gmail.com>",
"license": "MIT",
"dependencies": {
"react": "^16.3.0-alpha.2",
"react-dom": "^16.3.0-alpha.2",
"redoc": "^2.0.0-alpha.15"
},
"publishConfig": {
"access": "public"
}
}

469
cli/redoc-static.html Normal file

File diff suppressed because one or more lines are too long

View File

@ -3,7 +3,6 @@
"version": "2.0.0-alpha.15",
"description": "ReDoc",
"main": "bundles/redoc.lib.js",
"bin": "bin/cli.js",
"scripts": {
"start": "webpack-dev-server --mode=development --env.playground --hot --config demo/webpack.config.ts ",
"start:prod": "webpack-dev-server --env.playground --mode=production --config demo/webpack.config.ts",
@ -24,7 +23,7 @@
"lint": "tslint --project tsconfig.json",
"benchmark": "node ./benchmark/benchmark.js",
"start:demo": "webpack-dev-server --hot --config demo/webpack.config.ts",
"compile:cli": "tsc bin/cli.ts --target es6 --module commonjs --types yargs"
"compile:cli": "tsc cli/index.ts --target es6 --module commonjs --types yargs"
},
"author": "",
"license": "MIT",

View File

@ -23,6 +23,7 @@ export default (env: { standalone?: boolean } = {}) => ({
path: path.join(__dirname, '/bundles'),
library: 'Redoc',
libraryTarget: 'umd',
globalObject: 'this',
},
devtool: 'source-map',