mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-31 17:19:56 +08:00
chore: add monorepo tools (#9196)
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import { existsSync, statSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { fileURLToPath, pathToFileURL } from 'node:url';
|
||||
|
||||
export class Path {
|
||||
static dir(url: string) {
|
||||
return new Path(join(fileURLToPath(url), '..'));
|
||||
}
|
||||
|
||||
get value() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
get relativePath() {
|
||||
return './' + this.path.slice(ProjectRoot.path.length).replace(/\\/g, '/');
|
||||
}
|
||||
|
||||
constructor(public readonly path: string) {}
|
||||
|
||||
join(...paths: string[]) {
|
||||
return new Path(join(this.path, ...paths));
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
exists() {
|
||||
return existsSync(this.path);
|
||||
}
|
||||
|
||||
stats() {
|
||||
return statSync(this.path);
|
||||
}
|
||||
|
||||
isFile() {
|
||||
return this.exists() && this.stats().isFile();
|
||||
}
|
||||
|
||||
isDirectory() {
|
||||
return this.exists() && this.stats().isDirectory();
|
||||
}
|
||||
|
||||
toFileUrl() {
|
||||
return pathToFileURL(this.path);
|
||||
}
|
||||
}
|
||||
|
||||
export const ProjectRoot = Path.dir(import.meta.url).join('../../../');
|
||||
Reference in New Issue
Block a user