mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-13 04:16:34 +03:00
fix: move cli to a separate npm package
This commit is contained in:
parent
ed20ac1298
commit
95c7585628
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -25,7 +25,7 @@ stats.json
|
||||||
e2e/.build/
|
e2e/.build/
|
||||||
cypress/
|
cypress/
|
||||||
bundles
|
bundles
|
||||||
bin/cli.js
|
cli/index.js
|
||||||
|
|
||||||
/benchmark/revisions
|
/benchmark/revisions
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
!bundles/
|
!bundles/
|
||||||
!package.json
|
!package.json
|
||||||
!README.md
|
!README.md
|
||||||
!bin/cli.js
|
|
3
cli/.npmignore
Normal file
3
cli/.npmignore
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
!index.js
|
||||||
|
!package.json
|
||||||
|
!README.md
|
0
cli/README.md
Normal file
0
cli/README.md
Normal file
|
@ -7,7 +7,7 @@ import * as zlib from 'zlib';
|
||||||
import { resolve } from 'path';
|
import { resolve } from 'path';
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import { Redoc, loadAndBundleSpec, createStore } from '../';
|
import { Redoc, loadAndBundleSpec, createStore } from 'redoc';
|
||||||
|
|
||||||
import { createReadStream, writeFileSync, ReadStream, readFileSync, watch, existsSync } from 'fs';
|
import { createReadStream, writeFileSync, ReadStream, readFileSync, watch, existsSync } from 'fs';
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ yargs
|
||||||
try {
|
try {
|
||||||
await serve(argv.port, argv.spec, { ssr: argv.ssr, watch: argv.watch });
|
await serve(argv.port, argv.spec, { ssr: argv.ssr, watch: argv.watch });
|
||||||
} catch (e) {
|
} 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 = {}) {
|
async function bundle(pathToSpec, options: Options = {}) {
|
||||||
|
const start = Date.now();
|
||||||
const spec = await loadAndBundleSpec(pathToSpec);
|
const spec = await loadAndBundleSpec(pathToSpec);
|
||||||
const pageHTML = await getPageHTML(spec, pathToSpec, { ...options, ssr: true });
|
const pageHTML = await getPageHTML(spec, pathToSpec, { ...options, ssr: true });
|
||||||
|
|
||||||
writeFileSync(options.output!, pageHTML);
|
writeFileSync(options.output!, pageHTML);
|
||||||
const sizeInKb = Math.ceil(Buffer.byteLength(pageHTML) / 1024);
|
const sizeInKiB = Math.ceil(Buffer.byteLength(pageHTML) / 1024);
|
||||||
console.log(`\n🎉 bundled successfully in: ${options.output!} (${sizeInKb} kB)`);
|
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) {
|
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;
|
let redocStandaloneSrc;
|
||||||
if (ssr) {
|
if (ssr) {
|
||||||
console.log('Prerendering docs');
|
console.log('Prerendering docs');
|
||||||
let store = await createStore(spec, pathToSpec);
|
const store = await createStore(spec, pathToSpec);
|
||||||
const sheet = new ServerStyleSheet();
|
const sheet = new ServerStyleSheet();
|
||||||
html = renderToString(sheet.collectStyles(React.createElement(Redoc, { store })));
|
html = renderToString(sheet.collectStyles(React.createElement(Redoc, { store })));
|
||||||
css = sheet.getStyleTags();
|
css = sheet.getStyleTags();
|
||||||
|
@ -165,7 +170,8 @@ async function getPageHTML(spec: any, pathToSpec: string, { ssr, cdn }: Options)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return `<html>
|
return `<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf8" />
|
<meta charset="utf8" />
|
||||||
<title>ReDoc</title>
|
<title>ReDoc</title>
|
1342
cli/package-lock.json
generated
Normal file
1342
cli/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
20
cli/package.json
Normal file
20
cli/package.json
Normal 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
469
cli/redoc-static.html
Normal file
File diff suppressed because one or more lines are too long
|
@ -3,7 +3,6 @@
|
||||||
"version": "2.0.0-alpha.15",
|
"version": "2.0.0-alpha.15",
|
||||||
"description": "ReDoc",
|
"description": "ReDoc",
|
||||||
"main": "bundles/redoc.lib.js",
|
"main": "bundles/redoc.lib.js",
|
||||||
"bin": "bin/cli.js",
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "webpack-dev-server --mode=development --env.playground --hot --config demo/webpack.config.ts ",
|
"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",
|
"start:prod": "webpack-dev-server --env.playground --mode=production --config demo/webpack.config.ts",
|
||||||
|
@ -24,7 +23,7 @@
|
||||||
"lint": "tslint --project tsconfig.json",
|
"lint": "tslint --project tsconfig.json",
|
||||||
"benchmark": "node ./benchmark/benchmark.js",
|
"benchmark": "node ./benchmark/benchmark.js",
|
||||||
"start:demo": "webpack-dev-server --hot --config demo/webpack.config.ts",
|
"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": "",
|
"author": "",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|
|
@ -23,6 +23,7 @@ export default (env: { standalone?: boolean } = {}) => ({
|
||||||
path: path.join(__dirname, '/bundles'),
|
path: path.join(__dirname, '/bundles'),
|
||||||
library: 'Redoc',
|
library: 'Redoc',
|
||||||
libraryTarget: 'umd',
|
libraryTarget: 'umd',
|
||||||
|
globalObject: 'this',
|
||||||
},
|
},
|
||||||
|
|
||||||
devtool: 'source-map',
|
devtool: 'source-map',
|
||||||
|
|
Loading…
Reference in New Issue
Block a user