mirror of
				https://github.com/Redocly/redoc.git
				synced 2025-10-31 15:57:30 +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/ | ||||
| cypress/ | ||||
| bundles | ||||
| bin/cli.js | ||||
| cli/index.js | ||||
| 
 | ||||
| /benchmark/revisions | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,4 +1,3 @@ | |||
| !bundles/ | ||||
| !package.json | ||||
| !README.md | ||||
| !bin/cli.js | ||||
| !README.md | ||||
							
								
								
									
										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'; | ||||
| 
 | ||||
| // @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
									
								
							
							
						
						
									
										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", | ||||
|   "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", | ||||
|  |  | |||
|  | @ -23,6 +23,7 @@ export default (env: { standalone?: boolean } = {}) => ({ | |||
|     path: path.join(__dirname, '/bundles'), | ||||
|     library: 'Redoc', | ||||
|     libraryTarget: 'umd', | ||||
|     globalObject: 'this', | ||||
|   }, | ||||
| 
 | ||||
|   devtool: 'source-map', | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user