-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmake-list.js
97 lines (85 loc) · 3.38 KB
/
make-list.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* Software Name : abcdesktop.io
* Version: 0.2
* SPDX-FileCopyrightText: Copyright (c) 2020-2021 Orange
* SPDX-License-Identifier: GPL-2.0-only
*
* This software is distributed under the GNU General Public License v2.0 only
* see the "license.txt" file for more details.
*
* Author: abcdesktop.io team
* Software description: cloud native desktop service
*/
/* eslint-disable no-console */
const fs = require('fs');
const path = require('path');
const dockerRegistryPath = 'abcdesktopio';
// function to encode file data to base64 encoded string
function base64Encode(file) {
// read binary data
const bitmap = fs.readFileSync(file);
// convert binary data to base64 encoded string
return bitmap.toString('base64');
}
const docarray = {};
function makedocArray(e) {
const displayname = e.displayname ? e.displayname : e.name;
const filename = e.name.toLowerCase();
const icon = e.icon;
const appname = e.name.toLowerCase() + '.d';
if (e.desktopfile) {
var command = `docker run --rm ${dockerRegistryPath}/${appname} cat ${e.desktopfile} | grep 'Comment='`;
try {
var description = "no description found";
stdout = require('child_process').execSync(command ).toString();
var description = "no description found";
const comment = 'Comment=';
const indexOfFirst = stdout.indexOf(comment);
if ( indexOfFirst != -1 ) {
var i = indexOfFirst + comment.length;
var end = stdout.length;
description = stdout.substr(i, end-comment.length-1);
}
docarray[appname] = `|![${e.icon}](icons/${e.icon}){: style="height:32px;width:32px"}|${displayname}|${description}|[${filename}.md](${filename}.md)|`;
} catch (error) {
docarray[appname] = `|![${e.icon}](icons/${e.icon}){: style="height:32px;width:32px"}|${displayname}|${description}|[${filename}.md](${filename}.md)|`;
// error.status; // 0 : successful exit, but here in exception it has to be greater than 0
// error.message; // Holds the message you typically want.
// error.stderr; // Holds the stderr output. Use `.toString()`.
// error.stdout; // Holds the stdout output. Use `.toString()`.
}
}
else
docarray[appname] = `|![${e.icon}](icons/${e.icon}){: style="height:32px;width:32px"}|${displayname}|no description found|[${filename}.md](${filename}.md)|`;
// console.log( docarray[appname] );
}
function sortByKey(array, key) {
return array.sort((a, b) => {
const x = a[key];
const y = b[key];
if (x < y) return -1;
if (x > y) return 1;
return 0;
});
}
function getDescription(jsonArray) {
var arrayLength = jsonArray.length;
for (var i = 0; i < arrayLength; i++) {
makedocArray( jsonArray[i] );
}
}
const content = fs.readFileSync('applist.json');
const jsoncontent = JSON.parse(content);
getDescription(jsoncontent);
const wstreamlist = fs.createWriteStream('list.md');
wstreamlist.write('# Application list\n');
wstreamlist.write('This array describe the application list ready to use with abcdesktop.\n\n');
wstreamlist.write('|icon|displayname|description|file md|\n');
wstreamlist.write('|----|-----------|-----------|-------|\n');
var keys = Object.keys(docarray); // or loop over the object to get the array
keys.sort(); // maybe use custom sort, to change direction use .reverse()
for (var i=0; i<keys.length; i++) { // now lets iterate in sort order
var key = keys[i];
wstreamlist.write( docarray[key] + '\n');
}
wstreamlist.end();