Skip to content

Commit

Permalink
fix: ignore hidden folders from oa
Browse files Browse the repository at this point in the history
  • Loading branch information
devthejo committed Dec 15, 2023
1 parent a027ec2 commit 27a4151
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
4 changes: 2 additions & 2 deletions packages/core/libs/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ function treeFileLoader(filename) {
return `require("${src}")`
}

function buildDirTree(treeDirs) {
function buildDirTree(treeDirs, { filter } = {}) {
for (const { dir, pattern, dirName } of treeDirs) {
const dirPath = path.resolve(srcDir, dir)
const content = fs.existsSync(dirPath)
? dirtree2static(dirPath, { pattern, loader: treeFileLoader })
? dirtree2static(dirPath, { pattern, loader: treeFileLoader, filter })
: JSON.stringify({})
const dest = path.join(buildDir, `${dirName || dir}.js`)
ensureFileHasDir(dest)
Expand Down
25 changes: 14 additions & 11 deletions packages/core/utils/fs/dirtree2static.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,22 @@ module.exports = function dirtree2static(
defaultsDeep(options, defaultOptions)
rootDir = filename
}
const { pattern, loader } = options
const { pattern, loader, filter = () => true } = options
const stats = fs.lstatSync(filename)
if (stats.isDirectory()) {
const files = fs.readdirSync(filename).filter((file) => {
const absPath = `${filename}/${file}`
const relPath = absPath.slice(rootDir.length)
return (
(typeof pattern === "function"
? pattern(relPath)
: relPath.match(pattern)) ||
fs.lstatSync(`${filename}/${file}`).isDirectory()
)
})
const files = fs
.readdirSync(filename)
.filter(filter)
.filter((file) => {
const absPath = `${filename}/${file}`
const relPath = absPath.slice(rootDir.length)
return (
(typeof pattern === "function"
? pattern(relPath)
: relPath.match(pattern)) ||
fs.lstatSync(`${filename}/${file}`).isDirectory()
)
})

const results = {}
for (const file of files) {
Expand Down
31 changes: 18 additions & 13 deletions plugins/oa/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,25 @@ module.exports.build = (options = {}) => {

compileDirList(apiPath)

buildDirTree([
{
dir: apiPath,
pattern:
/^\/v\d+\/(formats|operations|security|spec|validators|services)\/(.*)\.(js|yaml|yml)$/,
dirName: "api",
},
buildDirTree(
[
{
dir: apiPath,
pattern:
/^\/v\d+\/(formats|operations|security|spec|validators|services)\/(.*)\.(js|yaml|yml)$/,
dirName: "api",
},
{
dir: sharedApiPath,
pattern:
/^\/(formats|operations|security|spec|validators|services)\/(.*)\.(js|yaml|yml)$/,
dirName: "sharedApi",
},
],
{
dir: sharedApiPath,
pattern:
/^\/(formats|operations|security|spec|validators|services)\/(.*)\.(js|yaml|yml)$/,
dirName: "sharedApi",
},
])
filter: (p) => !/(^|\/)\.[^/]+/.test(p),
}
)

fs.copySync(
path.dirname(require.resolve("swagger-ui-dist")),
Expand Down

0 comments on commit 27a4151

Please sign in to comment.