Skip to content

Commit

Permalink
Export empty model index if no model_* files exist (#996)
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Yuan authored Oct 10, 2023
1 parent fcc0c46 commit d5d3c62
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -486,13 +487,23 @@ static void writeModelIndex(Collection<Shape> shapes, SymbolProvider symbolProvi
FileManifest fileManifest) {
TypeScriptWriter writer = new TypeScriptWriter("");
String modelPrefix = String.join("/", ".", CodegenUtils.SOURCE_FOLDER, SHAPE_NAMESPACE_PREFIX);
shapes.stream()
List<String> collectedModelNamespaces = shapes.stream()
.map(shape -> symbolProvider.toSymbol(shape).getNamespace())
.filter(namespace -> namespace.startsWith(modelPrefix))
.distinct()
.sorted(Comparator.naturalOrder())
.map(namespace -> namespace.replaceFirst(Matcher.quoteReplacement(modelPrefix), "."))
.forEach(namespace -> writer.write("export * from $S;", namespace));
.toList();

// Export empty model index if no models_* files are present
if (collectedModelNamespaces.isEmpty()) {
writer.write("export {};");
} else {
for (String namespace : collectedModelNamespaces) {
writer.write("export * from $S;", namespace);
}
}

fileManifest.writeFile(
Paths.get(CodegenUtils.SOURCE_FOLDER, SHAPE_NAMESPACE_PREFIX, "index.ts").toString(),
writer.toString());
Expand Down

0 comments on commit d5d3c62

Please sign in to comment.