Skip to content

Commit

Permalink
Merge pull request #430 from Inist-CNRS/ignore-hidden-files
Browse files Browse the repository at this point in the history
refactor: 💡 list files
  • Loading branch information
touv authored Nov 8, 2024
2 parents 26a4f3e + e02c1c3 commit 4c0ea07
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 36 deletions.
3 changes: 2 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"debug": "4.3.3",
"deep-object-diff": "1.1.0",
"end-of-stream": "1.4.4",
"fdir": "6.4.2",
"filename-regex": "2.0.1",
"filtrex": "1.0.0",
"from": "0.1.7",
Expand All @@ -30,12 +31,12 @@
"merge2": "1.4.1",
"nanoid": "2.1.8",
"nanoid-dictionary": "2.0.0",
"node-dir": "0.1.17",
"node-object-hash": "2.3.10",
"object-sizeof": "1.6.1",
"once": "1.4.0",
"p-wait-for": "3.1.0",
"path-exists": "4.0.0",
"picomatch": "4.0.2",
"prom-client": "14.0.0",
"readable-stream": "3.6.0",
"retimer": "^3.0.0",
Expand Down
67 changes: 40 additions & 27 deletions packages/core/src/server/serverInformation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import debug from 'debug';
import dir from 'node-dir';
import { fdir as FileScan } from 'fdir';
import loadJsonFile from 'load-json-file';
import pathExists from 'path-exists';
import autocast from 'autocast';
Expand Down Expand Up @@ -177,34 +177,47 @@ const collectMetadata = async (dirPath, hostName) => {
return globalSwagger;
};

const collectPaths = (ezs, dirPath) => new Promise((resolve) => {
dir.files(dirPath, (err, files) => {
const filenames = err ? [] : files;
const localPaths = filenames
.filter((f) => (f.search(/\.(ini|ezs)$/) > 0))
.map((f) => ({
[f.replace(dirPath, '').replace(/\.\w+/, '')]:
_.reduce(
ezs.metaFile(f),
(object, value, key) => _.set(
_.pick(
_.set(object, key, autocast(value)),
keyOfPathItemObject,
),
'post.x-config-filename',
f.replace(dirname(dirPath), ''),
const collectPaths = async (ezs, dirPath) => {
const files = await new FileScan()
.withBasePath()
.withFullPaths()
.exclude((dirName) =>
dirName.startsWith('.') || dirName.startsWith('~')
)
.globWithOptions([
'./**/*.ini',
'./**/*.ezs',
], {
ignore: [
'./**/~*.*',
'./**/$*.*',
]
})
.crawl(dirPath)
.withPromise();
const localPaths = files
.map((f) => ({
[f.replace(dirPath, '').replace(/\.\w+/, '')]:
_.reduce(
ezs.metaFile(f),
(object, value, key) => _.set(
_.pick(
_.set(object, key, autocast(value)),
keyOfPathItemObject,
),
{},
'post.x-config-filename',
f.replace(dirname(dirPath), ''),
),
})).reduce(
(obj, cur) => ({
...obj,
...cur,
}), {},
);
resolve(_.merge(globalSwaggerPaths, localPaths));
});
});
{},
),
})).reduce(
(obj, cur) => ({
...obj,
...cur,
}), {},
);
return _.merge(globalSwaggerPaths, localPaths);
};

const collectAll = async (ezs, request) => {
const infos = await collectMetadata(request.serverPath, request.headers.host);
Expand Down
19 changes: 11 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5627,6 +5627,11 @@ fb-watchman@^2.0.0:
dependencies:
bser "2.1.1"

[email protected]:
version "6.4.2"
resolved "https://registry.yarnpkg.com/fdir/-/fdir-6.4.2.tgz#ddaa7ce1831b161bc3657bb99cb36e1622702689"
integrity sha512-KnhMXsKSPZlAhp7+IjUkRZKPb4fUyccpDrdFXbi4QL1qkmFh9kVY09Yox+n4MaOb3lHZ1Tv829C3oaaXoMYPDQ==

[email protected]:
version "4.2.2"
resolved "https://registry.yarnpkg.com/feed/-/feed-4.2.2.tgz#865783ef6ed12579e2c44bbef3c9113bc4956a7e"
Expand Down Expand Up @@ -8869,7 +8874,7 @@ min-indent@^1.0.0:
resolved "https://registry.yarnpkg.com/min-indent/-/min-indent-1.0.1.tgz#a63f681673b30571fbe8bc25686ae746eefa9869"
integrity sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg==

minimatch@^3.0.2, minimatch@^3.0.4, minimatch@^3.1.1:
minimatch@^3.0.4, minimatch@^3.1.1:
version "3.1.2"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b"
integrity sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==
Expand Down Expand Up @@ -9186,13 +9191,6 @@ node-abort-controller@^1.1.0:
resolved "https://registry.yarnpkg.com/node-abort-controller/-/node-abort-controller-1.2.1.tgz#1eddb57eb8fea734198b11b28857596dc6165708"
integrity sha512-79PYeJuj6S9+yOHirR0JBLFOgjB6sQCir10uN6xRx25iD+ZD4ULqgRn3MwWBRaQGB0vEgReJzWwJo42T1R6YbQ==

[email protected]:
version "0.1.17"
resolved "https://registry.yarnpkg.com/node-dir/-/node-dir-0.1.17.tgz#5f5665d93351335caabef8f1c554516cf5f1e4e5"
integrity sha512-tmPX422rYgofd4epzrNoOXiE8XFZYOcCq1vD7MAXCDO+O+zndlA2ztdKKMa+EeuBG5tHETpr4ml4RGgpqDCCAg==
dependencies:
minimatch "^3.0.2"

[email protected]:
version "2.6.7"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
Expand Down Expand Up @@ -10042,6 +10040,11 @@ picocolors@^1.1.0:
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.1.1.tgz#3d321af3eab939b083c8f929a1d12cda81c26b6b"
integrity sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==

[email protected]:
version "4.0.2"
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-4.0.2.tgz#77c742931e8f3b8820946c76cd0c1f13730d1dab"
integrity sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==

picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42"
Expand Down

0 comments on commit 4c0ea07

Please sign in to comment.