@@ -6,54 +6,75 @@ const REPO_DESCRIPTION_PATH = "./description.md";
6
6
const TARGET_PATH = "./README.md" ;
7
7
8
8
/**
9
- * Reads the library list from the YAML file and returns it as a JavaScript object.
9
+ * Reads the package list from the YAML file and returns it as a JavaScript object.
10
10
* @param {String } path
11
- * @returns an Object representing the library list
11
+ * @returns an Object representing the package list
12
12
*/
13
- function getLibraryListFromYaml ( path ) {
13
+ function getPackageListFromYaml ( path ) {
14
14
try {
15
- return load ( readFileSync ( path , 'utf8' ) ) . libraries ;
15
+ let libraries = load ( readFileSync ( path , 'utf8' ) ) . packages ;
16
+
17
+ // Sort libraries by name alphabetically
18
+ libraries . sort ( ( a , b ) => {
19
+ if ( a . name < b . name ) { return - 1 ; }
20
+ if ( a . name > b . name ) { return 1 ; }
21
+ return 0 ;
22
+ } ) ;
23
+
24
+ return libraries ;
16
25
} catch ( e ) {
17
26
console . log ( e ) ;
18
27
}
19
28
}
20
29
21
30
/**
22
31
* Turns the properties of the library list into a Markdown string.
23
- * @param {Object } libraryList
32
+ * @param {Object } packageList
24
33
* @returns A string containing the library list in Markdown format
25
34
*/
26
- function getMarkdownFromLibraryList ( libraryList ) {
27
- const libraryData = libraryList . map ( library => {
28
- let entry = `### ${ library . name } \n\n${ library . description } \n\n` ;
29
-
30
- if ( library . url ) {
31
- entry += `- 🌐 **URL:** ${ library . url } \n` ;
32
- }
33
- if ( library . author ) {
34
- entry += `- 👤 **Author:** ${ library . author } \n` ;
35
+ function getMarkdownFromPackageList ( packageList ) {
36
+ const libraryData = packageList . map ( aPackage => {
37
+ let entry = `### [${ aPackage . name } ](${ aPackage . url } )\n\n` ;
38
+
39
+ if ( aPackage . description ) {
40
+ entry += `${ aPackage . description } \n\n` ;
41
+ }
42
+
43
+ entry += "<details><summary>Details</summary>\n" ;
44
+ entry += "<ul>\n" ;
45
+
46
+ if ( aPackage . url ) {
47
+ entry += `<li>🌐 <strong>URL:</strong> ${ aPackage . url } </li>\n` ;
35
48
}
36
- if ( library . license ) {
37
- entry += `- 📜 **License:** ${ library . license } \n` ;
49
+ if ( aPackage . author ) {
50
+ entry += `<li>👤 <strong>Author:</strong> ${ aPackage . author } </li> \n` ;
38
51
}
39
- if ( library . tags ) {
40
- entry += `- 🏷️ **Tags:** ${ library . tags . join ( ', ' ) } \n` ;
52
+ if ( aPackage . license ) {
53
+ entry += `<li>📜 <strong>License:</strong> ${ aPackage . license } </li>\n` ;
54
+ }
55
+ if ( aPackage . tags ) {
56
+ entry += `<li>🏷️ <strong>Tags:</strong> ${ aPackage . tags . join ( ', ' ) } </li>\n` ;
41
57
}
42
58
43
- if ( library . verification ) {
44
- entry += "- ✅ ** Verification:** \n" ;
45
- let verification = library . verification . map ( verification => {
59
+ if ( aPackage . verification ) {
60
+ entry += "<li>✅ <strong> Verification:</strong>\n<ul> \n" ;
61
+ let verification = aPackage . verification . map ( verification => {
46
62
const libraryVersion = verification . library_version ? ` v${ verification . library_version } ` : "" ;
47
- return ` - Verified${ libraryVersion } with \` ${ verification . fqbn } \` on MicroPython v${ verification . micropython_version } ` ;
63
+ return `<li> Verified${ libraryVersion } with <code> ${ verification . fqbn } </code> on MicroPython v${ verification . micropython_version } </li> ` ;
48
64
} ) . join ( "\n" ) ;
49
- entry += `${ verification } \n` ;
65
+ entry += `${ verification } \n</ul></li>\n ` ;
50
66
}
67
+
68
+ entry += "</ul>\n" ;
69
+ entry += "</details>\n\n" ;
70
+
51
71
return entry ;
52
-
72
+
53
73
} ) . join ( "<hr />\n\n" ) ;
54
74
return `## 📦 Packages\n${ libraryData } ` ;
55
75
}
56
76
77
+
57
78
/**
58
79
* Merges the repo description and the library list into a
59
80
* single Markdown string and writes it to the target file.
@@ -67,8 +88,8 @@ function writeMarkdownFile(descriptionPath, targetPath, markdownLibraryList) {
67
88
writeFileSync ( targetPath , content ) ;
68
89
}
69
90
70
- console . log ( "📚 Rendering library list..." ) ;
71
- const libraryList = getLibraryListFromYaml ( REGISTRY_FILE_PATH ) ;
72
- const markdownLibraryList = getMarkdownFromLibraryList ( libraryList ) ;
91
+ console . log ( "📚 Rendering package list..." ) ;
92
+ const packageList = getPackageListFromYaml ( REGISTRY_FILE_PATH ) ;
93
+ const markdownLibraryList = getMarkdownFromPackageList ( packageList ) ;
73
94
writeMarkdownFile ( REPO_DESCRIPTION_PATH , TARGET_PATH , markdownLibraryList ) ;
74
95
console . log ( "✅ Done" ) ;
0 commit comments