Skip to content

Commit cbac973

Browse files
committed
✨ Support root dir configuration in .api-to-go.yml
1 parent b880f1a commit cbac973

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ node_modules
66
tmp
77
.node-version
88
tests/docs
9-
tests/jsonplaceholder.typicode.com
9+
tests/jsonplaceholder.typicode.com
10+
tests/jsonplaceholder

src/buildPath.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
const {loadConfig, toPascalCase} = require("./common");
22

33
function buildPath(url, configFile, opts) {
4-
const path = _buildPath(url, configFile)
4+
const hostCfg = loadConfig(url, configFile)
5+
const path = _buildPath(url, hostCfg)
56
const pathArr = path.replacedUrl.split("/")
67
const pkg = pathArr[pathArr.length - 2].replace(/\./g, '')
78
const last = pathArr[pathArr.length - 1] || "index"
89
const struct = toPascalCase(last)
910
pathArr.pop()
11+
12+
if (hostCfg.root !== undefined) {
13+
console.log(pathArr)
14+
pathArr[0] = hostCfg.root
15+
}
16+
1017
const dir = pathArr.join("/")
1118
let method = opts?.method.toLowerCase()
1219

@@ -24,8 +31,7 @@ function buildPath(url, configFile, opts) {
2431
}
2532
}
2633

27-
function _buildPath(url, configFile) {
28-
const hostCfg = loadConfig(url, configFile)
34+
function _buildPath(url, hostCfg) {
2935
let ret = {
3036
pathname: url.pathname,
3137
pathFormat: null,

tests/.api-to-go.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"jsonplaceholder.typicode.com":
2+
root: jsonplaceholder
23
docs:
34
- https://jsonplaceholder.typicode.com/
45
format:

0 commit comments

Comments
 (0)