From 63dfdebf6a3f962c85392f9d6ece8f4d64364d95 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Wed, 22 Nov 2017 13:02:15 +0200 Subject: [PATCH] Add version and revision to standalone bundle exports --- custom.d.ts | 2 ++ src/standalone.tsx | 3 +++ tsconfig.json | 1 + webpack.config.ts | 10 ++++++++++ 4 files changed, 16 insertions(+) diff --git a/custom.d.ts b/custom.d.ts index 7f77b4c2..0154cc79 100644 --- a/custom.d.ts +++ b/custom.d.ts @@ -14,6 +14,8 @@ declare module '*.css' { } declare var __DEV__: boolean; +declare var __REDOC_VERSION__: string; +declare var __REDOC_REVISION__: string; declare type Dict = { [key: string]: T; diff --git a/src/standalone.tsx b/src/standalone.tsx index 16500b34..4b94e8ec 100644 --- a/src/standalone.tsx +++ b/src/standalone.tsx @@ -3,6 +3,9 @@ import * as React from 'react'; import { RedocStandalone } from './components/RedocStandalone'; +export const version = __REDOC_VERSION__; +export const revision = __REDOC_REVISION__; + function attributesMap(element: Element) { var res = {}; var elAttrs = element.attributes; diff --git a/tsconfig.json b/tsconfig.json index f150934b..43a26e52 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -35,6 +35,7 @@ "./custom.d.ts", "./demo/playground/hmr-playground.tsx", "./src/index.ts", + "./src/standalone.tsx", "demo/*.tsx" ], "awesomeTypescriptLoaderOptions": { diff --git a/webpack.config.ts b/webpack.config.ts index 166e3a2c..333a1983 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -6,6 +6,14 @@ const nodeExternals = require('webpack-node-externals')({ whitelist: ['swagger2openapi', 'reftools', /\.(?!(?:jsx?|json)$).{1,5}$/i], }); +const VERSION = JSON.stringify(require('./package.json').version); +const REVISION = JSON.stringify( + require('child_process') + .execSync('git rev-parse --short HEAD') + .toString() + .trim(), +); + export default env => { env = env || {}; @@ -101,6 +109,8 @@ export default env => { plugins: [ new webpack.DefinePlugin({ 'process.env.NODE_ENV': env.prod ? '"production"' : '"development"', + __REDOC_VERSION__: VERSION, + __REDOC_REVISION__: REVISION, __DEV__: env.prod ? 'false' : 'true', }), new webpack.NamedModulesPlugin(),