Skip to content

Instantly share code, notes, and snippets.

@maggiben
Created June 9, 2021 16:50
Show Gist options
  • Select an option

  • Save maggiben/32b42e000e17c55c00b3446417b9d83c to your computer and use it in GitHub Desktop.

Select an option

Save maggiben/32b42e000e17c55c00b3446417b9d83c to your computer and use it in GitHub Desktop.
Given a file path get the suffix
private getSuffixByFileName(fsPath: string): string | undefined {
const metadataFileExt = '-meta.xml';
const fileName = path.basename(fsPath);
if (fileName.endsWith(metadataFileExt)) {
return fileName.substring(0, fileName.indexOf('-meta.xml')).split('.').slice(1, 2).pop();
}
return undefined;
}
private getTypeDefinitionByFileName(fsPath: string): MetadataType | undefined {
if (fs.fileExistsSync(fsPath)) {
const suffix = this.getSuffixByFileName(fsPath);
const registryAccess = new RegistryAccess();
return registryAccess.getTypeBySuffix(suffix);
}
return undefined;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment