Search in sources :

Example 1 with TSExport

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;
}
Also used : HashMap(java.util.HashMap) TSExport(io.crnk.gen.typescript.model.TSExport) TSSource(io.crnk.gen.typescript.model.TSSource) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Aggregations

TSExport (io.crnk.gen.typescript.model.TSExport)1 TSSource (io.crnk.gen.typescript.model.TSSource)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1