summaryrefslogtreecommitdiffhomepage
path: root/scripts/build_one_click_apps.js
blob: be96b2bf0dc55f94a0c301aff3da8b17a0c5aa3c (plain)
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
 /*jshint esversion: 6 */
 const path = require('path');
 const fs = require('fs-extra')

 const PUBLIC = `public`
 const pathOfPublic = path.join(__dirname, '..', PUBLIC);


 function copyVersion(version) {

     const pathOfVersion = path.join(pathOfPublic, 'v' + version);
     const pathOfApps = path.join(pathOfVersion, 'apps');
     const pathOfList = path.join(pathOfVersion, 'autoGeneratedList.json'); //kept for backward compat
     const pathOfList2 = path.join(pathOfVersion, 'list');

     return fs.readdir(pathOfApps)
         .then(function (items) {

             const apps = items.filter(v => v.includes('.json'));
             const appDetails = [];

             for (var i = 0; i < apps.length; i++) {
                 const contentString = fs.readFileSync(path.join(pathOfApps, apps[i]));
                 const content = JSON.parse(contentString)
                 const captainVersion = (content.captainVersion + '');
                 const versionString = (version + '');
                 if (versionString !== captainVersion)
                     throw new Error(`unmatched versions   ${versionString}  ${captainVersion} for ${apps[i]}`)
                 if (captainVersion === "1") {
                     if (contentString.includes("$$cap_root_domain"))
                         throw new Error('V1 should not have root domain')
                 }

                 apps[i] = apps[i].replace('.json', '');

                 if (captainVersion + '' === '2') {
                     if (!content.displayName) {
                         content.displayName = apps[i]
                         content.displayName = content.displayName.substr(0, 1).toUpperCase() + content.displayName.substring(1, content.displayName.length)
                     }
                     if (!content.description) content.description = ''

                     appDetails[i] = {
                         name: apps[i],
                         displayName: content.displayName,
                         description: content.description,
                         logoUrl: apps[i] + '.png'
                     }
                 }

             }

             fs.outputJsonSync(pathOfList, {
                 appList: apps,
                 appDetails: appDetails
             });

             fs.outputJsonSync(pathOfList2, {
                 oneClickApps: appDetails
             });

         })
 }


 Promise.resolve()
     .then(function () {
         return copyVersion(1)
     })
     .then(function () {
         return copyVersion(2)
     })
     .catch(function (err) {
         console.error(err)
         process.exit(127)
     })