Fixes #3300 - Updates to versions.swaggerUi information

This commit is contained in:
Owen Conti
2017-07-09 14:17:18 -06:00
parent 42efd8a60e
commit d8400f8729
2 changed files with 42 additions and 34 deletions

View File

@@ -1,11 +1,12 @@
var path = require('path') var path = require("path")
var webpack = require('webpack') var webpack = require("webpack")
var ExtractTextPlugin = require('extract-text-webpack-plugin') var ExtractTextPlugin = require("extract-text-webpack-plugin")
var deepExtend = require('deep-extend') var deepExtend = require("deep-extend")
const {gitDescribeSync} = require('git-describe'); const {gitDescribeSync} = require("git-describe")
const os = require("os")
var pkg = require('./package.json') var pkg = require("./package.json")
let gitInfo let gitInfo
@@ -13,7 +14,7 @@ try {
gitInfo = gitDescribeSync(__dirname) gitInfo = gitDescribeSync(__dirname)
} catch(e) { } catch(e) {
gitInfo = { gitInfo = {
hash: 'noGit', hash: "noGit",
dirty: false dirty: false
} }
} }
@@ -21,21 +22,21 @@ try {
var commonRules = [ var commonRules = [
{ test: /\.(js(x)?)(\?.*)?$/, { test: /\.(js(x)?)(\?.*)?$/,
use: [{ use: [{
loader: 'babel-loader', loader: "babel-loader",
options: { options: {
retainLines: true retainLines: true
} }
}], }],
include: [ path.join(__dirname, 'src') ] include: [ path.join(__dirname, "src") ]
}, },
{ test: /\.(txt|yaml)(\?.*)?$/, { test: /\.(txt|yaml)(\?.*)?$/,
loader: 'raw-loader' }, loader: "raw-loader" },
{ test: /\.(png|jpg|jpeg|gif|svg)(\?.*)?$/, { test: /\.(png|jpg|jpeg|gif|svg)(\?.*)?$/,
loader: 'url-loader?limit=10000' }, loader: "url-loader?limit=10000" },
{ test: /\.(woff|woff2)(\?.*)?$/, { test: /\.(woff|woff2)(\?.*)?$/,
loader: 'url-loader?limit=100000' }, loader: "url-loader?limit=100000" },
{ test: /\.(ttf|eot)(\?.*)?$/, { test: /\.(ttf|eot)(\?.*)?$/,
loader: 'file-loader' } loader: "file-loader" }
] ]
module.exports = function(rules, options) { module.exports = function(rules, options) {
@@ -54,7 +55,7 @@ module.exports = function(rules, options) {
if( specialOptions.separateStylesheets ) { if( specialOptions.separateStylesheets ) {
plugins.push(new ExtractTextPlugin({ plugins.push(new ExtractTextPlugin({
filename: '[name].css' + (specialOptions.longTermCaching ? '?[contenthash]' : ''), filename: "[name].css" + (specialOptions.longTermCaching ? "?[contenthash]" : ""),
allChunks: true allChunks: true
})) }))
} }
@@ -78,35 +79,36 @@ module.exports = function(rules, options) {
plugins.push( plugins.push(
new webpack.DefinePlugin({ new webpack.DefinePlugin({
'process.env': { "process.env": {
NODE_ENV: specialOptions.minimize ? JSON.stringify('production') : null, NODE_ENV: specialOptions.minimize ? JSON.stringify("production") : null,
WEBPACK_INLINE_STYLES: !Boolean(specialOptions.separateStylesheets) WEBPACK_INLINE_STYLES: !specialOptions.separateStylesheets
}, },
'buildInfo': JSON.stringify({ "buildInfo": JSON.stringify({
PACKAGE_VERSION: (pkg.version), PACKAGE_VERSION: (pkg.version),
GIT_COMMIT: gitInfo.hash, GIT_COMMIT: gitInfo.hash,
GIT_DIRTY: gitInfo.dirty GIT_DIRTY: gitInfo.dirty,
HOSTNAME: os.hostname(),
BUILD_TIME: new Date().toUTCString()
}) })
})) }))
delete options._special delete options._special
var completeConfig = deepExtend({ var completeConfig = deepExtend({
entry: {}, entry: {},
output: { output: {
path: path.join(__dirname, 'dist'), path: path.join(__dirname, "dist"),
publicPath: '/', publicPath: "/",
filename: '[name].js', filename: "[name].js",
chunkFilename: '[name].js' chunkFilename: "[name].js"
}, },
target: 'web', target: "web",
// yaml-js has a reference to `fs`, this is a workaround // yaml-js has a reference to `fs`, this is a workaround
node: { node: {
fs: 'empty' fs: "empty"
}, },
module: { module: {
@@ -114,17 +116,17 @@ module.exports = function(rules, options) {
}, },
resolveLoader: { resolveLoader: {
modules: [path.join(__dirname, 'node_modules')], modules: [path.join(__dirname, "node_modules")],
}, },
externals: { externals: {
'buffertools': true // json-react-schema/deeper depends on buffertools, which fails. "buffertools": true // json-react-schema/deeper depends on buffertools, which fails.
}, },
resolve: { resolve: {
modules: [ modules: [
path.join(__dirname, './src'), path.join(__dirname, "./src"),
'node_modules' "node_modules"
], ],
extensions: [".web.js", ".js", ".jsx", ".json", ".less"], extensions: [".web.js", ".js", ".jsx", ".json", ".less"],
alias: { alias: {
@@ -132,7 +134,7 @@ module.exports = function(rules, options) {
} }
}, },
devtool: specialOptions.sourcemaps ? 'cheap-module-source-map' : null, devtool: specialOptions.sourcemaps ? "cheap-module-source-map" : null,
plugins, plugins,

View File

@@ -11,12 +11,18 @@ const CONFIGS = [ "url", "urls", "urls.primaryName", "spec", "validatorUrl", "on
"showRequestHeaders", "custom", "modelPropertyMacro", "parameterMacro", "displayOperationId" , "displayRequestDuration"] "showRequestHeaders", "custom", "modelPropertyMacro", "parameterMacro", "displayOperationId" , "displayRequestDuration"]
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
const { GIT_DIRTY, GIT_COMMIT, PACKAGE_VERSION } = buildInfo const { GIT_DIRTY, GIT_COMMIT, PACKAGE_VERSION, HOSTNAME, BUILD_TIME } = buildInfo
module.exports = function SwaggerUI(opts) { module.exports = function SwaggerUI(opts) {
win.versions = win.versions || {} win.versions = win.versions || {}
win.versions.swaggerUi = `${PACKAGE_VERSION}/${GIT_COMMIT || "unknown"}${GIT_DIRTY ? "-dirty" : ""}` win.versions.swaggerUi = {
version: PACKAGE_VERSION,
gitRevision: GIT_COMMIT,
gitDirty: GIT_DIRTY,
buildTimestamp: BUILD_TIME,
machine: HOSTNAME
}
const defaults = { const defaults = {
// Some general settings, that we floated to the top // Some general settings, that we floated to the top