|
@@ -1,20 +1,26 @@
|
|
|
import fsp from 'node:fs/promises';
|
|
import fsp from 'node:fs/promises';
|
|
|
import { sep } from 'node:path';
|
|
import { sep } from 'node:path';
|
|
|
|
|
|
|
|
-interface TreeFileType {
|
|
|
|
|
- type: 'file',
|
|
|
|
|
|
|
+// eslint-disable-next-line sukka/no-export-const-enum -- TODO: fix this in the future
|
|
|
|
|
+export const enum TreeFileType {
|
|
|
|
|
+ FILE = 1,
|
|
|
|
|
+ DIRECTORY = 2
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+interface TreeFile {
|
|
|
|
|
+ type: TreeFileType.FILE,
|
|
|
name: string,
|
|
name: string,
|
|
|
path: string
|
|
path: string
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
interface TreeDirectoryType {
|
|
interface TreeDirectoryType {
|
|
|
- type: 'directory',
|
|
|
|
|
|
|
+ type: TreeFileType.DIRECTORY,
|
|
|
name: string,
|
|
name: string,
|
|
|
path: string,
|
|
path: string,
|
|
|
children: TreeTypeArray
|
|
children: TreeTypeArray
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export type TreeType = TreeDirectoryType | TreeFileType;
|
|
|
|
|
|
|
+export type TreeType = TreeDirectoryType | TreeFile;
|
|
|
export type TreeTypeArray = TreeType[];
|
|
export type TreeTypeArray = TreeType[];
|
|
|
|
|
|
|
|
type VoidOrVoidArray = void | VoidOrVoidArray[];
|
|
type VoidOrVoidArray = void | VoidOrVoidArray[];
|
|
@@ -35,7 +41,7 @@ export async function treeDir(rootPath: string): Promise<TreeTypeArray> {
|
|
|
|
|
|
|
|
if (child.isDirectory()) {
|
|
if (child.isDirectory()) {
|
|
|
const newNode: TreeDirectoryType = {
|
|
const newNode: TreeDirectoryType = {
|
|
|
- type: 'directory',
|
|
|
|
|
|
|
+ type: TreeFileType.DIRECTORY,
|
|
|
name: child.name,
|
|
name: child.name,
|
|
|
path: childRelativeToRoot,
|
|
path: childRelativeToRoot,
|
|
|
children: []
|
|
children: []
|
|
@@ -45,8 +51,8 @@ export async function treeDir(rootPath: string): Promise<TreeTypeArray> {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
if (child.isFile()) {
|
|
if (child.isFile()) {
|
|
|
- const newNode: TreeFileType = {
|
|
|
|
|
- type: 'file',
|
|
|
|
|
|
|
+ const newNode: TreeFile = {
|
|
|
|
|
+ type: TreeFileType.FILE,
|
|
|
name: child.name,
|
|
name: child.name,
|
|
|
path: childRelativeToRoot
|
|
path: childRelativeToRoot
|
|
|
};
|
|
};
|