mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 17:12:43 +00:00
feat: tests
This commit is contained in:
@@ -12,15 +12,36 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import path from "path";
|
||||
import {readdirSync, statSync} from "fs";
|
||||
import {readdirSync, statSync} from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
/**
|
||||
* Expand a path to a list of all files deeply contained in it
|
||||
*/
|
||||
export function expandPathToFilesSync(sourcePath: string, accept: (fileName: string) => boolean): string[] {
|
||||
const fullPath = path.resolve(sourcePath);
|
||||
const directory = statSync(fullPath);
|
||||
|
||||
return directory.isDirectory()
|
||||
? readdirSync(fullPath).flatMap(fragment =>
|
||||
expandPathToFilesSync(path.resolve(sourcePath, fragment), accept),
|
||||
)
|
||||
: [fullPath].filter(accept);
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a Windows path and make a Unix path out of it
|
||||
*/
|
||||
export function toUnixPath(pathString: string): string {
|
||||
return pathString.replaceAll(path.sep, path.posix.sep);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters only defined elements
|
||||
*/
|
||||
export function rejectNil<T>(array: Array<T | undefined | null>): T[] {
|
||||
// eslint-disable-next-line unicorn/no-null
|
||||
return array.filter(it => it == null) as T[];
|
||||
return array.filter(it => it != null) as T[];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,17 +66,3 @@ export function cleanupEmpty<T extends object>(object: T): T {
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Expand a path to a list of all files deeply contained in it
|
||||
*/
|
||||
export function expandPathToFilesSync(sourcePath: string, accept: (fileName: string) => boolean): string[] {
|
||||
const fullPath = path.resolve(sourcePath);
|
||||
const directory = statSync(fullPath);
|
||||
|
||||
return directory.isDirectory()
|
||||
? readdirSync(fullPath).flatMap(fragment =>
|
||||
expandPathToFilesSync(path.resolve(sourcePath, fragment), accept),
|
||||
)
|
||||
: [fullPath].filter(accept);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user