From 234e6d5d57291db1e7fd03e18bb3acc08e02fc86 Mon Sep 17 00:00:00 2001 From: Dylan Date: Fri, 9 Jun 2017 07:54:42 -0700 Subject: [PATCH 1/5] add `absolutePath` to swagger-ui-dist --- swagger-ui-dist-package/index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/swagger-ui-dist-package/index.js b/swagger-ui-dist-package/index.js index f8b7191c..00fa198b 100644 --- a/swagger-ui-dist-package/index.js +++ b/swagger-ui-dist-package/index.js @@ -1,2 +1,6 @@ +const path = require('path') + module.exports.SwaggerUIBundle = require('./swagger-ui-bundle.js') module.exports.SwaggerUIStandalonePreset = require('./swagger-ui-standalone-preset.js') + +module.exports.absolutePath = path.resolve(__dirname) From d6d5b1d06e4d648826b87153eee63978ff360cf2 Mon Sep 17 00:00:00 2001 From: Dylan Date: Fri, 9 Jun 2017 08:12:35 -0700 Subject: [PATCH 2/5] add documentation of absolutePath as well as npm version badge --- swagger-ui-dist-package/README.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/swagger-ui-dist-package/README.md b/swagger-ui-dist-package/README.md index eff7655c..c5165765 100644 --- a/swagger-ui-dist-package/README.md +++ b/swagger-ui-dist-package/README.md @@ -1,8 +1,22 @@ -This module, `swagger-ui-dist`, exposes Swagger-UI's entire dist folder as a dependency-free npm module. Use `swagger-ui` instead, if you'd like to have npm install dependencies for you. +# Swagger UI Dist +[![NPM version](https://badge.fury.io/js/swagger-ui-dist.svg)](http://badge.fury.io/js/swagger-ui-dist) + +# API + +This module, `swagger-ui-dist`, exposes Swagger-UI's entire dist folder as a dependency-free npm module. +Use `swagger-ui` instead, if you'd like to have npm install dependencies for you. `SwaggerUIBundle` and `SwaggerUIStandalonePreset` can be imported: ```javascript import { SwaggerUIBundle, SwaggerUIStandalonePreset } from 'swagger-ui-dist' ``` +To get an absolute path to this directory for static file serving, use the exported `absolutePath` property: + +```javascript +const swaggerUiAssetPath = require('swagger-ui-dist').absolutePath; + +// then instantiate server that serves files from the swaggerUiAssetPath +``` + For anything else, check the [Swagger-UI](https://github.com/swagger-api/swagger-ui) repository. From df149c543b9dc197ed4465313d14b509242bbc66 Mon Sep 17 00:00:00 2001 From: Dylan Date: Sat, 10 Jun 2017 15:58:34 -0700 Subject: [PATCH 3/5] make dist absolutePath browser-safe, add test --- package.json | 2 +- swagger-ui-dist-package/absolute-path.js | 14 ++++++++++++++ swagger-ui-dist-package/index.js | 8 +++----- test/swagger-ui-dist-package/absolute-path.js | 13 +++++++++++++ 4 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 swagger-ui-dist-package/absolute-path.js create mode 100644 test/swagger-ui-dist-package/absolute-path.js diff --git a/package.json b/package.json index 405fddc1..40ad9d5a 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "test": "npm run lint-errors && npm run just-test-in-node", "test-in-node": "npm run lint-errors && npm run just-test-in-node", "just-test": "karma start --config karma.conf.js", - "just-test-in-node": "mocha --recursive --compilers js:babel-core/register test/core test/components test/bugs" + "just-test-in-node": "mocha --recursive --compilers js:babel-core/register test/core test/components test/bugs test/swagger-ui-dist-package" }, "dependencies": { "babel-polyfill": "^6.23.0", diff --git a/swagger-ui-dist-package/absolute-path.js b/swagger-ui-dist-package/absolute-path.js new file mode 100644 index 00000000..650e7dbf --- /dev/null +++ b/swagger-ui-dist-package/absolute-path.js @@ -0,0 +1,14 @@ +/* + * getAbsoluteFSPath + * @return {string} When run in NodeJS env, returns the absolute path to the current directory + * When run outside of NodeJS, will return an error message + */ +const getAbsoluteFSPath = () => { + // detect whether we are running in a browser or nodejs + if (typeof module !== "undefined" && module.exports) { + return require("path").resolve(__dirname) + } + return "Error! absolutePath only available when running in NodeJS" +} + +module.exports = getAbsoluteFSPath() diff --git a/swagger-ui-dist-package/index.js b/swagger-ui-dist-package/index.js index 00fa198b..018196a9 100644 --- a/swagger-ui-dist-package/index.js +++ b/swagger-ui-dist-package/index.js @@ -1,6 +1,4 @@ -const path = require('path') +module.exports.SwaggerUIBundle = require("./swagger-ui-bundle.js") +module.exports.SwaggerUIStandalonePreset = require("./swagger-ui-standalone-preset.js") +module.exports.absolutePath = require("./.absolute-path.js") -module.exports.SwaggerUIBundle = require('./swagger-ui-bundle.js') -module.exports.SwaggerUIStandalonePreset = require('./swagger-ui-standalone-preset.js') - -module.exports.absolutePath = path.resolve(__dirname) diff --git a/test/swagger-ui-dist-package/absolute-path.js b/test/swagger-ui-dist-package/absolute-path.js new file mode 100644 index 00000000..aba27933 --- /dev/null +++ b/test/swagger-ui-dist-package/absolute-path.js @@ -0,0 +1,13 @@ +/* eslint-env mocha */ +import expect from "expect" +import path from "path" +import absolutePath from "../../swagger-ui-dist-package/absolute-path" + +describe("swagger-ui-dist", function(){ + describe("absolutePath", function(){ + it("has absolute path", function(){ + const expectedPath = path.resolve(__dirname, "../../swagger-ui-dist-package") + expect(absolutePath).toEqual(expectedPath) + }) + }) +}) From 3311f3e95fad4d934c7121b7810e4e86d3320124 Mon Sep 17 00:00:00 2001 From: Dylan Date: Mon, 12 Jun 2017 22:21:47 -0700 Subject: [PATCH 4/5] export getAbsoluteFSPath method instead of property --- swagger-ui-dist-package/README.md | 6 +++--- swagger-ui-dist-package/absolute-path.js | 4 ++-- test/swagger-ui-dist-package/absolute-path.js | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/swagger-ui-dist-package/README.md b/swagger-ui-dist-package/README.md index c5165765..3737c8ae 100644 --- a/swagger-ui-dist-package/README.md +++ b/swagger-ui-dist-package/README.md @@ -8,13 +8,13 @@ Use `swagger-ui` instead, if you'd like to have npm install dependencies for you `SwaggerUIBundle` and `SwaggerUIStandalonePreset` can be imported: ```javascript - import { SwaggerUIBundle, SwaggerUIStandalonePreset } from 'swagger-ui-dist' + import { SwaggerUIBundle, SwaggerUIStandalonePreset } from "swagger-ui-dist" ``` -To get an absolute path to this directory for static file serving, use the exported `absolutePath` property: +To get an absolute path to this directory for static file serving, use the exported `getAbsoluteFSPath` method: ```javascript -const swaggerUiAssetPath = require('swagger-ui-dist').absolutePath; +const swaggerUiAssetPath = require("swagger-ui-dist").getAbsoluteFSPath // then instantiate server that serves files from the swaggerUiAssetPath ``` diff --git a/swagger-ui-dist-package/absolute-path.js b/swagger-ui-dist-package/absolute-path.js index 650e7dbf..26a3cc01 100644 --- a/swagger-ui-dist-package/absolute-path.js +++ b/swagger-ui-dist-package/absolute-path.js @@ -8,7 +8,7 @@ const getAbsoluteFSPath = () => { if (typeof module !== "undefined" && module.exports) { return require("path").resolve(__dirname) } - return "Error! absolutePath only available when running in NodeJS" + throw new Error('getAbsoluteFSPath can only be called within a Nodejs environment'); } -module.exports = getAbsoluteFSPath() +module.exports = getAbsoluteFSPath diff --git a/test/swagger-ui-dist-package/absolute-path.js b/test/swagger-ui-dist-package/absolute-path.js index aba27933..252a298a 100644 --- a/test/swagger-ui-dist-package/absolute-path.js +++ b/test/swagger-ui-dist-package/absolute-path.js @@ -1,13 +1,13 @@ /* eslint-env mocha */ import expect from "expect" import path from "path" -import absolutePath from "../../swagger-ui-dist-package/absolute-path" +import getAbsoluteFSPath from "../../swagger-ui-dist-package/absolute-path" describe("swagger-ui-dist", function(){ - describe("absolutePath", function(){ - it("has absolute path", function(){ + describe("getAbsoluteFSPath", function(){ + it("returns absolute path", function(){ const expectedPath = path.resolve(__dirname, "../../swagger-ui-dist-package") - expect(absolutePath).toEqual(expectedPath) + expect(getAbsoluteFSPath()).toEqual(expectedPath) }) }) }) From 5f8ffb870ceb2eb267c296f1808a43c629676566 Mon Sep 17 00:00:00 2001 From: shockey Date: Mon, 12 Jun 2017 23:14:00 -0700 Subject: [PATCH 5/5] Add function invocation to method example --- swagger-ui-dist-package/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swagger-ui-dist-package/README.md b/swagger-ui-dist-package/README.md index 3737c8ae..66284227 100644 --- a/swagger-ui-dist-package/README.md +++ b/swagger-ui-dist-package/README.md @@ -14,7 +14,7 @@ Use `swagger-ui` instead, if you'd like to have npm install dependencies for you To get an absolute path to this directory for static file serving, use the exported `getAbsoluteFSPath` method: ```javascript -const swaggerUiAssetPath = require("swagger-ui-dist").getAbsoluteFSPath +const swaggerUiAssetPath = require("swagger-ui-dist").getAbsoluteFSPath() // then instantiate server that serves files from the swaggerUiAssetPath ```