Server/scripts/util/walk.js

37 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2024-09-26 04:01:06 -07:00
/*
ValkyrieChat: A re-implementation and extension of the Discord.com backend.
Copyright (C) 2024 ValkyrieChat
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
2024-09-05 00:21:51 -07:00
const fs = require("fs");
/** dir: string. types: string[] ( file types ) */
module.exports = function walk(dir, types = ["ts"]) {
var results = [];
var list = fs.readdirSync(dir);
list.forEach(function (file) {
file = dir + "/" + file;
var stat = fs.statSync(file);
if (stat && stat.isDirectory()) {
/* Recurse into a subdirectory */
results = results.concat(walk(file, types));
} else {
if (!types.find((x) => file.endsWith(x))) return;
results.push(file);
}
});
return results;
};