build project in command line

This commit is contained in:
codetypes committed 2025-01-25 21:55:00 +08:00
1 parent da41704322
commit a0d0ca0ca9
5 files changed
+110 -11

No files matched your search

+18
View File
@@ -1,3 +1,4 @@
import * as fs from "fs";
import path from "path";
const Path = path;
@@ -6,6 +7,7 @@ declare module "path" {
interface PlatformPath {
basenameWithoutExt(path: string): string;
posixPath(path: string): string;
ls(path: string, recursive?: boolean): string[];
}
}
@@ -17,4 +19,20 @@ path.posixPath = (str: string) => {
return path.normalize(str).replace(/\\/g, "/");
};
const readdir = (dir: string, recursive: boolean, callback: (file: string) => void) => {
fs.readdirSync(dir).forEach((file) => {
file = Path.posixPath(dir + "/" + file);
callback(file);
if (recursive && fs.statSync(file).isDirectory()) {
readdir(file, recursive, callback);
}
});
};
path.ls = (dir: string, recursive?: boolean) => {
const paths: string[] = [];
readdir(dir, recursive ?? false, (file) => paths.push(file));
return paths.sort();
};
export default Path;