summaryrefslogtreecommitdiffhomepage
path: root/scripts/build_one_click_apps.js
diff options
context:
space:
mode:
authorKasra Bigdeli <[email protected]>2020-06-23 07:04:00 -0400
committerKasra Bigdeli <[email protected]>2020-06-23 07:04:00 -0400
commit48e59ceb8963bf7187217ea6ba769a9213d11ca7 (patch)
tree80bd6395d20711cd743eb95850af11857161391b /scripts/build_one_click_apps.js
parente9966666026abb28cfef5cb86e46043a741cf056 (diff)
downloadcaprover-one-click-apps-48e59ceb8963bf7187217ea6ba769a9213d11ca7.tar.gz
caprover-one-click-apps-48e59ceb8963bf7187217ea6ba769a9213d11ca7.zip
Moved scripts to script dir
Diffstat (limited to 'scripts/build_one_click_apps.js')
-rw-r--r--scripts/build_one_click_apps.js75
1 files changed, 75 insertions, 0 deletions
diff --git a/scripts/build_one_click_apps.js b/scripts/build_one_click_apps.js
new file mode 100644
index 0000000..4047478
--- /dev/null
+++ b/scripts/build_one_click_apps.js
@@ -0,0 +1,75 @@
+ /*jshint esversion: 6 */
+ const path = require('path');
+ const fs = require('fs-extra')
+
+ 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)
+ }) \ No newline at end of file