greybel-js
Version:
Transpiler/Interpreter for GreyScript. (GreyHack)
31 lines • 1.11 kB
JavaScript
import pathUtil from 'path';
import { configurationManager } from './configuration-manager.js';
import { GlobalFileSystemManager } from './fs.js';
export class DocumentURIBuilder {
rootPath;
fileExtensions;
fileSystemManager;
constructor(rootPath, fileSystemManager = GlobalFileSystemManager) {
this.rootPath = rootPath;
this.fileExtensions = configurationManager.get('fileExtensions');
this.fileSystemManager = fileSystemManager;
}
getFromRootPath(path) {
return pathUtil.join(this.rootPath, path);
}
getAlternativePaths(path) {
return this.fileExtensions.map((ext) => {
return this.getFromRootPath(`${path}.${ext}`);
});
}
getOriginalPath(path) {
return this.getFromRootPath(path);
}
async getPathUseReturnOriginal(path) {
return (await this.getPath(path)) ?? this.getOriginalPath(path);
}
getPath(path) {
return this.fileSystemManager.findExistingPath(this.getOriginalPath(path), ...this.getAlternativePaths(path));
}
}
//# sourceMappingURL=document-uri-builder.js.map