diff options
| author | Kasra Bigdeli <[email protected]> | 2020-06-23 08:35:58 -0400 |
|---|---|---|
| committer | Kasra Bigdeli <[email protected]> | 2020-06-23 08:35:58 -0400 |
| commit | a0e1fb0ac8744f396dc81330b841a2d1447fd422 (patch) | |
| tree | 5fddab12cbc045ba0f8efbb1a4ce3838fdc605a3 /scripts | |
| parent | 9ee75a559ff51f7edf423c25f3d5a90b4ad34533 (diff) | |
| download | caprover-one-click-apps-a0e1fb0ac8744f396dc81330b841a2d1447fd422.tar.gz caprover-one-click-apps-a0e1fb0ac8744f396dc81330b841a2d1447fd422.zip | |
Changed build chain
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/build_one_click_apps.js | 159 | ||||
| -rwxr-xr-x | scripts/publish-from-actions.sh | 2 |
2 files changed, 84 insertions, 77 deletions
diff --git a/scripts/build_one_click_apps.js b/scripts/build_one_click_apps.js index be96b2b..67260fc 100644 --- a/scripts/build_one_click_apps.js +++ b/scripts/build_one_click_apps.js @@ -1,76 +1,83 @@ - /*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) - })
\ No newline at end of file +/*jshint esversion: 6 */ +const path = require('path'); +const fs = require('fs-extra'); + +const pathOfPublic = path.join(__dirname, '..', `public`); + +const pathOfDist = path.join(__dirname, '..', `dist`); +// const pathOfDistV1 = path.join(pathOfDist, 'v1'); +const pathOfDistV2 = path.join(pathOfDist, 'v2'); +const pathOfDistV3 = path.join(pathOfDist, 'v3'); + +const pathOfSourceDirectory = path.join(pathOfPublic, 'v2'); +const pathOfSourceDirectoryApps = path.join(pathOfSourceDirectory, 'apps'); +const pathOfSourceDirectoryLogos = path.join(pathOfSourceDirectory, 'logos'); + + +function createAppList(appsList, pathOfApps) { + const apps = appsList.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 + ''); + + 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' + }; + } else { + throw new Error('Unknown captain-version: ' + captainVersion); + } + + } + + return { + appList: apps, + appDetails: appDetails + }; +} + + +function buildDist() { + return fs.readdir(pathOfSourceDirectoryApps) + .then(function (appsFileNames) { // [ app1.json app2.json .... ] + + appsFileNames.forEach(appFileName => { + fs.copySync(path.join(pathOfSourceDirectoryApps, appFileName), path.join(pathOfDistV2, `apps`, appFileName)); + fs.copySync(path.join(pathOfSourceDirectoryApps, appFileName), path.join(pathOfDistV3, `apps`, appFileName.split('.')[0])); + }); + + fs.copySync(pathOfSourceDirectoryLogos, path.join(pathOfDistV2, `logos`)); + fs.copySync(pathOfSourceDirectoryLogos, path.join(pathOfDistV3, `logos`)); + + fs.outputJsonSync(path.join(pathOfDistV2, 'autoGeneratedList.json'), createAppList(appsFileNames, pathOfSourceDirectoryApps)); + fs.outputJsonSync(path.join(pathOfDistV2, 'list'), createAppList(appsFileNames, pathOfSourceDirectoryApps)); // TODO delete + fs.outputJsonSync(path.join(pathOfDistV3, 'list'), createAppList(appsFileNames, pathOfSourceDirectoryApps)); + }) + .then(function () { + return fs.copySync(path.join(pathOfPublic, 'CNAME'), path.join(pathOfDist, 'CNAME')) + }); +} + + +Promise.resolve() + .then(function () { + return buildDist(); + }) + .catch(function (err) { + console.error(err); + process.exit(127); + });
\ No newline at end of file diff --git a/scripts/publish-from-actions.sh b/scripts/publish-from-actions.sh index 05466dd..404086b 100755 --- a/scripts/publish-from-actions.sh +++ b/scripts/publish-from-actions.sh @@ -26,7 +26,7 @@ set -e -BUILD_DIR=public +BUILD_DIR=dist SOURCE_DIRECTORY_DEPLOY_GH=~/temp-gh-deploy-src CLONED_DIRECTORY_DEPLOY_GH=~/temp-gh-deploy-cloned |
