Skip to content

Commit

Permalink
Merge branch 'hotfix/0.1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
jjzcru committed Jan 5, 2020
2 parents c0e4976 + 1b52c31 commit aee290e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
24 changes: 15 additions & 9 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit aee290e

Please sign in to comment.