Skip to content

Commit

Permalink
add type to table and have both template and alias in same table
Browse files Browse the repository at this point in the history
  • Loading branch information
maxandersen committed May 16, 2021
1 parent bb1fe10 commit 6b1c6ca
Show file tree
Hide file tree
Showing 4 changed files with 1,117 additions and 971 deletions.
101 changes: 47 additions & 54 deletions .github/appstore.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
//DEPS org.commonmark:commonmark-ext-gfm-strikethrough:0.17.1
//DEPS org.commonmark:commonmark-ext-task-list-items:0.17.1

import java.io.*;
import java.nio.file.*;
import java.util.*;
import java.util.concurrent.Callable;

import com.google.gson.*;
import com.google.gson.annotations.SerializedName;

Expand All @@ -19,21 +24,9 @@
import org.commonmark.parser.Parser;
import org.commonmark.renderer.html.HtmlRenderer;
import org.kohsuke.github.*;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.OpenOption;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.stream.Collectors;
import picocli.CommandLine;
import picocli.CommandLine.*;

/**
* To run this script, set two environment variables GH_USER and GH_TOKEN. These
Expand All @@ -46,7 +39,8 @@ class appstore implements Callable<Integer> {

static {
excludedCatalogs.add("jbangdev/jbang/itests/jbang-catalog.json");
// excludedCatalogs.add("jbangdev/jbang/src/main/resources/jbang-catalog.json"); // todo: treat special to just have it be jbang -t xxx ?
// excludedCatalogs.add("jbangdev/jbang/src/main/resources/jbang-catalog.json");
// // todo: treat special to just have it be jbang -t xxx ?
}

@Option(names = { "-d",
Expand Down Expand Up @@ -92,13 +86,15 @@ public Integer call() throws Exception {
}
}

List<CatalogItem> sortedAliases = aliasItems.stream()
.sorted(Comparator.comparing(catalogerItem -> -catalogerItem.stars)).collect(Collectors.toList());
List<CatalogItem> sortedItems = new ArrayList<>();

List<CatalogItem> sortedTemplates = templateItems.stream()
.sorted(Comparator.comparing(catalogerItem -> -catalogerItem.stars)).collect(Collectors.toList());

var cataloger = new Cataloger(sortedAliases,sortedTemplates);
sortedItems.addAll(aliasItems);
sortedItems.addAll(templateItems);
sortedItems.sort(Comparator.comparing((CatalogItem item) -> item.link)
//.thenComparing(catalogerItem -> -catalogerItem.stars)
);

var cataloger = new Cataloger(sortedItems);
String catalogerContent = gson.toJson(cataloger);
destinationDir.toFile().mkdirs();
var path = destinationDir.resolve("jbang-appstore.json");
Expand All @@ -107,26 +103,6 @@ public Integer call() throws Exception {
return 0;
}

private CatalogItem templateToItem(Map.Entry<String, Template> entry, GHContent ghContent) {
var item = new CatalogItem();
item.alias = entry.getKey();
item.scriptRef = null;
item.description = entry.getValue().description;

if (item.description != null) {
item.description = md2html(item.description);
}

setupGeneralInfo(ghContent, item);

StringBuffer cmd = aliasToCommand(ghContent, item.alias, item.repoName, item.repoOwner);

item.command = cmd.toString();
item.fullcommand = "jbang init -t " + item.command + " app.java";

return item;
}

private void setupGeneralInfo(GHContent ghContent, CatalogItem item) {

item.repoOwner = ghContent.getOwner().getOwnerName();
Expand All @@ -152,8 +128,31 @@ private void setupGeneralInfo(GHContent ghContent, CatalogItem item) {
}
}

private CatalogItem templateToItem(Map.Entry<String, Template> entry, GHContent ghContent) {
var item = new CatalogItem();
item.type = "template";
item.alias = entry.getKey();
item.scriptRef = null;
item.description = entry.getValue().description;

if (item.description != null) {
item.description = md2html(item.description);
}

setupGeneralInfo(ghContent, item);

StringBuffer cmd = aliasToCommand(ghContent, item.alias, item.repoName, item.repoOwner);

item.command = cmd.toString();
item.fullcommand = "jbang init -t " + item.command + " app.java";

return item;
}


private CatalogItem toCatalogerItem(Map.Entry<String, Alias> entry, GHContent ghContent) {
var item = new CatalogItem();
item.type = "alias";
item.alias = entry.getKey();
item.scriptRef = entry.getValue().scriptRef;
item.description = entry.getValue().description;
Expand All @@ -162,15 +161,13 @@ private CatalogItem toCatalogerItem(Map.Entry<String, Alias> entry, GHContent gh
item.description = md2html(item.description);
}


setupGeneralInfo(ghContent, item);

StringBuffer cmd = aliasToCommand(ghContent, item.alias, item.repoName, item.repoOwner);

item.command = cmd.toString();
item.fullcommand = "jbang init -t " + item.command + " app.java";


return item;
}

Expand All @@ -195,7 +192,7 @@ private String md2html(String markdown) {
var document = parser.parse(markdown);
HtmlRenderer renderer = HtmlRenderer.builder().extensions(extensions).sanitizeUrls(true).escapeHtml(true).build();
var html = renderer.render(document);
//System.out.println(item.description + "=>" + html);
// System.out.println(item.description + "=>" + html);
return html;
}

Expand All @@ -206,7 +203,7 @@ private Catalog toJsonElement(Gson gson, GHContent catalogContent) throws IOExce
try (InputStream stream = catalogContent.read(); InputStreamReader streamR = new InputStreamReader(stream)) {
try {
json = gson.fromJson(streamR, Catalog.class);

} catch (JsonParseException e) {
e.printStackTrace();
json = null;
Expand All @@ -222,8 +219,8 @@ class Catalog {

@Override
public String toString() {
return aliases.toString() +" - " + templates.toString();

return aliases.toString() + " - " + templates.toString();

}
}
Expand All @@ -241,20 +238,16 @@ class Template {
class Cataloger {
public final int aliasCount;
public final List<CatalogItem> aliases;
private List<CatalogItem> templates;
private int templateCount;

public Cataloger(List<CatalogItem> items, List<CatalogItem> sortedTemplates) {

public Cataloger(List<CatalogItem> items) {
this.aliases = items;
aliasCount = items.size();

this.templates = sortedTemplates;
this.templateCount = sortedTemplates.size();
}
}

class CatalogItem {
public String url;
public String type;
public int stars;
public String icon_url;
public String repoOwner;
Expand Down
3 changes: 2 additions & 1 deletion _layouts/appstore.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ <h2>JBang AppStore</h2>
data-url="{{ page.store-data-url }}">
<thead>
<tr>
<th class="appstore-alias" data-field="command" data-formatter="aliasFormatter">{{page.thing-single | capitalize}}</th>
<th class="appstore-alias" data-field="type"></th>
<th class="appstore-alias" data-field="command" data-formatter="aliasFormatter">{{page.thing-single | capitalize}}</th>
</tr>
</thead>
</table>
Expand Down
1 change: 0 additions & 1 deletion assets/css/test.xss

This file was deleted.

Loading

0 comments on commit 6b1c6ca

Please sign in to comment.