Skip to content

Commit

Permalink
Merge pull request #11 from nkmr-jp/develop
Browse files Browse the repository at this point in the history
✨ Support root dir configuration in .api-to-go.yml
  • Loading branch information
nkmr-jp authored Dec 17, 2023
2 parents 116703f + cbac973 commit 24ad239
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ node_modules
tmp
.node-version
tests/docs
tests/jsonplaceholder.typicode.com
tests/jsonplaceholder.typicode.com
tests/jsonplaceholder
12 changes: 9 additions & 3 deletions src/buildPath.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
const {loadConfig, toPascalCase} = require("./common");

function buildPath(url, configFile, opts) {
const path = _buildPath(url, configFile)
const hostCfg = loadConfig(url, configFile)
const path = _buildPath(url, hostCfg)
const pathArr = path.replacedUrl.split("/")
const pkg = pathArr[pathArr.length - 2].replace(/\./g, '')
const last = pathArr[pathArr.length - 1] || "index"
const struct = toPascalCase(last)
pathArr.pop()

if (hostCfg.root !== undefined) {
console.log(pathArr)
pathArr[0] = hostCfg.root
}

const dir = pathArr.join("/")
let method = opts?.method.toLowerCase()

Expand All @@ -24,8 +31,7 @@ function buildPath(url, configFile, opts) {
}
}

function _buildPath(url, configFile) {
const hostCfg = loadConfig(url, configFile)
function _buildPath(url, hostCfg) {
let ret = {
pathname: url.pathname,
pathFormat: null,
Expand Down
1 change: 1 addition & 0 deletions tests/.api-to-go.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"jsonplaceholder.typicode.com":
root: jsonplaceholder
docs:
- https://jsonplaceholder.typicode.com/
format:
Expand Down

0 comments on commit 24ad239

Please sign in to comment.