From 1b52c317a7beb3fd24ac3f453b054d1ac7aa1779 Mon Sep 17 00:00:00 2001 From: "Jose J. Cruz Torres" Date: Sun, 5 Jan 2020 17:54:51 -0500 Subject: [PATCH] Add release link to changelog --- CHANGELOG.md | 8 +++++++- cli.js | 24 +++++++++++++++--------- package-lock.json | 2 +- package.json | 2 +- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a785bd..8cab075 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to this project will be documented in this file. +## [0.1.2] - 2020-01-05 + +### Fixed +- Set the project root as the root directory for default file paths and port when reading from `package.json` + ## [0.1.1] - 2020-01-05 ### Fixed @@ -14,5 +19,6 @@ All notable changes to this project will be documented in this file. - CHANGELOG.md file - README.md file -[0.1.1]: https://github.com/jjzcru/swagger-ui-loader/releases/tag/v0.1.1 + +[0.1.2]: https://github.com/jjzcru/swagger-ui-loader/releases/tag/v0.1.2[0.1.1]: https://github.com/jjzcru/swagger-ui-loader/releases/tag/v0.1.1 [0.1.0]: https://github.com/jjzcru/swagger-ui-loader/releases/tag/v0.1.0 \ No newline at end of file diff --git a/cli.js b/cli.js index 5ac9ed0..0613ca2 100755 --- a/cli.js +++ b/cli.js @@ -9,11 +9,11 @@ const swaggerUi = require('swagger-ui-express'); const YAML = require('yamljs'); const app = express(); -const port = getPort(); -const swaggerFile = getTargetFile(); const rootProjectPath = path.join(__dirname, '..', '..'); -swaggerFile.file = path.join(rootProjectPath, swaggerFile.file); + +const port = getPort(); +const swaggerFile = getTargetFile(); let swaggerDocument; switch(swaggerFile.ext) { @@ -37,8 +37,9 @@ app.listen(port, async () => { }); function getPort() { - if(fs.existsSync('./package.json')) { - const pkg = require('./package.json'); + const pkgPath = path.join(rootProjectPath, './package.json'); + if(fs.existsSync(pkgPath)) { + const pkg = require(pkgPath); if(!!pkg.swagger && !!pkg.swagger.port) { return parseInt(pkg.swagger.port); } @@ -79,17 +80,22 @@ function getTargetFile() { } function getFileFromPkg() { - if(fs.existsSync('./package.json')) { - const pkg = require('./package.json'); + const pkgPath = path.join(rootProjectPath, './package.json'); + if(fs.existsSync(pkgPath)) { + const pkg = require(pkgPath); if(!!pkg.swagger && !!pkg.swagger.file) { - return pkg.swagger.file; + return path.join(rootProjectPath, pkg.swagger.file); } } return null; } function getDefaultPath() { - const defaultFiles = ['./swagger.json', './swagger.yml', './swagger.yaml']; + const defaultFiles = [ + path.join(rootProjectPath, './swagger.json'), + path.join(rootProjectPath, './swagger.yml'), + path.join(rootProjectPath, './swagger.yaml'), + ]; for(const file of defaultFiles) { if(fs.existsSync(file)) { const ext = path.extname(file); diff --git a/package-lock.json b/package-lock.json index dae61e8..60043d6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "swagger-ui-loader", - "version": "0.1.1", + "version": "0.1.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index b72f7d0..b47e850 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "swagger-ui-loader", - "version": "0.1.1", + "version": "0.1.2", "description": "Swagger ui server that loads from a config file", "main": "cli.js", "repository": "https://github.com/jjzcru/swagger-ui-loader",