Skip to content

Commit 799196e

Browse files
committed
add type to table and have both template and alias in same table
1 parent a51cfe5 commit 799196e

File tree

4 files changed

+1246
-1046
lines changed

4 files changed

+1246
-1046
lines changed

.github/appstore.java

Lines changed: 47 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
//DEPS org.commonmark:commonmark-ext-gfm-strikethrough:0.17.1
99
//DEPS org.commonmark:commonmark-ext-task-list-items:0.17.1
1010

11+
import java.io.*;
12+
import java.nio.file.*;
13+
import java.util.*;
14+
import java.util.concurrent.Callable;
15+
1116
import com.google.gson.*;
1217
import com.google.gson.annotations.SerializedName;
1318

@@ -19,21 +24,9 @@
1924
import org.commonmark.parser.Parser;
2025
import org.commonmark.renderer.html.HtmlRenderer;
2126
import org.kohsuke.github.*;
22-
import picocli.CommandLine;
23-
import picocli.CommandLine.Command;
24-
import picocli.CommandLine.Option;
25-
import picocli.CommandLine.Parameters;
2627

27-
import java.io.*;
28-
import java.nio.file.Files;
29-
import java.nio.file.OpenOption;
30-
import java.nio.file.Path;
31-
import java.nio.file.Paths;
32-
import java.time.ZonedDateTime;
33-
import java.time.format.DateTimeFormatter;
34-
import java.util.*;
35-
import java.util.concurrent.Callable;
36-
import java.util.stream.Collectors;
28+
import picocli.CommandLine;
29+
import picocli.CommandLine.*;
3730

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

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

5246
@Option(names = { "-d",
@@ -92,13 +86,15 @@ public Integer call() throws Exception {
9286
}
9387
}
9488

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

98-
List<CatalogItem> sortedTemplates = templateItems.stream()
99-
.sorted(Comparator.comparing(catalogerItem -> -catalogerItem.stars)).collect(Collectors.toList());
100-
101-
var cataloger = new Cataloger(sortedAliases,sortedTemplates);
91+
sortedItems.addAll(aliasItems);
92+
sortedItems.addAll(templateItems);
93+
sortedItems.sort(Comparator.comparing((CatalogItem item) -> item.link )
94+
//.thenComparing(catalogerItem -> -catalogerItem.stars)
95+
);
96+
97+
var cataloger = new Cataloger(sortedItems);
10298
String catalogerContent = gson.toJson(cataloger);
10399
destinationDir.toFile().mkdirs();
104100
var path = destinationDir.resolve("jbang-appstore.json");
@@ -107,26 +103,6 @@ public Integer call() throws Exception {
107103
return 0;
108104
}
109105

110-
private CatalogItem templateToItem(Map.Entry<String, Template> entry, GHContent ghContent) {
111-
var item = new CatalogItem();
112-
item.alias = entry.getKey();
113-
item.scriptRef = null;
114-
item.description = entry.getValue().description;
115-
116-
if (item.description != null) {
117-
item.description = md2html(item.description);
118-
}
119-
120-
setupGeneralInfo(ghContent, item);
121-
122-
StringBuffer cmd = aliasToCommand(ghContent, item.alias, item.repoName, item.repoOwner);
123-
124-
item.command = cmd.toString();
125-
item.fullcommand = "jbang init -t " + item.command + " app.java";
126-
127-
return item;
128-
}
129-
130106
private void setupGeneralInfo(GHContent ghContent, CatalogItem item) {
131107

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

131+
private CatalogItem templateToItem(Map.Entry<String, Template> entry, GHContent ghContent) {
132+
var item = new CatalogItem();
133+
item.type = "template";
134+
item.alias = entry.getKey();
135+
item.scriptRef = null;
136+
item.description = entry.getValue().description;
137+
138+
if (item.description != null) {
139+
item.description = md2html(item.description);
140+
}
141+
142+
setupGeneralInfo(ghContent, item);
143+
144+
StringBuffer cmd = aliasToCommand(ghContent, item.alias, item.repoName, item.repoOwner);
145+
146+
item.command = cmd.toString();
147+
item.fullcommand = "jbang init -t " + item.command + " app.java";
148+
149+
return item;
150+
}
151+
152+
155153
private CatalogItem toCatalogerItem(Map.Entry<String, Alias> entry, GHContent ghContent) {
156154
var item = new CatalogItem();
155+
item.type = "alias";
157156
item.alias = entry.getKey();
158157
item.scriptRef = entry.getValue().scriptRef;
159158
item.description = entry.getValue().description;
@@ -162,15 +161,13 @@ private CatalogItem toCatalogerItem(Map.Entry<String, Alias> entry, GHContent gh
162161
item.description = md2html(item.description);
163162
}
164163

165-
166164
setupGeneralInfo(ghContent, item);
167165

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

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

173-
174171
return item;
175172
}
176173

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

@@ -206,7 +203,7 @@ private Catalog toJsonElement(Gson gson, GHContent catalogContent) throws IOExce
206203
try (InputStream stream = catalogContent.read(); InputStreamReader streamR = new InputStreamReader(stream)) {
207204
try {
208205
json = gson.fromJson(streamR, Catalog.class);
209-
206+
210207
} catch (JsonParseException e) {
211208
e.printStackTrace();
212209
json = null;
@@ -222,8 +219,8 @@ class Catalog {
222219

223220
@Override
224221
public String toString() {
225-
226-
return aliases.toString() +" - " + templates.toString();
222+
223+
return aliases.toString() + " - " + templates.toString();
227224

228225
}
229226
}
@@ -241,20 +238,16 @@ class Template {
241238
class Cataloger {
242239
public final int aliasCount;
243240
public final List<CatalogItem> aliases;
244-
private List<CatalogItem> templates;
245-
private int templateCount;
246-
247-
public Cataloger(List<CatalogItem> items, List<CatalogItem> sortedTemplates) {
241+
242+
public Cataloger(List<CatalogItem> items) {
248243
this.aliases = items;
249244
aliasCount = items.size();
250-
251-
this.templates = sortedTemplates;
252-
this.templateCount = sortedTemplates.size();
253245
}
254246
}
255247

256248
class CatalogItem {
257249
public String url;
250+
public String type;
258251
public int stars;
259252
public String icon_url;
260253
public String repoOwner;

0 commit comments

Comments
 (0)