use of io.crnk.gen.typescript.model.TSExport in project crnk-framework by crnk-project.
the class TSIndexFileProcessor method process.
@Override
public Set<TSSource> process(Set<TSSource> sources) {
Set<TSSource> newSources = new HashSet<>(sources);
Map<String, List<TSSource>> directoryIndex = new HashMap<>();
for (TSSource fileSource : sources) {
String dir = fileSource.getDirectory();
if (!directoryIndex.containsKey(dir)) {
directoryIndex.put(dir, new ArrayList<TSSource>());
}
directoryIndex.get(dir).add(fileSource);
}
List<String> keys = new ArrayList<>(directoryIndex.keySet());
Collections.sort(keys);
for (String key : keys) {
List<TSSource> sourceFiles = new ArrayList<>(directoryIndex.get(key));
Collections.sort(sourceFiles, new Comparator<TSSource>() {
@Override
public int compare(TSSource o1, TSSource o2) {
return o1.getName().compareTo(o2.getName());
}
});
TSSource indexSource = new TSSource();
indexSource.setName("index");
indexSource.setNpmPackage(sourceFiles.get(0).getNpmPackage());
indexSource.setDirectory(key);
for (TSSource sourceFile : sourceFiles) {
TSExport exportElement = new TSExport();
exportElement.setAny(true);
exportElement.setPath("./" + sourceFile.getName());
indexSource.getExports().add(exportElement);
}
newSources.add(indexSource);
}
return newSources;
}