diff options
| author | Kasra Bigdeli <[email protected]> | 2020-06-23 07:04:00 -0400 |
|---|---|---|
| committer | Kasra Bigdeli <[email protected]> | 2020-06-23 07:04:00 -0400 |
| commit | 48e59ceb8963bf7187217ea6ba769a9213d11ca7 (patch) | |
| tree | 80bd6395d20711cd743eb95850af11857161391b /scripts | |
| parent | e9966666026abb28cfef5cb86e46043a741cf056 (diff) | |
| download | caprover-one-click-apps-48e59ceb8963bf7187217ea6ba769a9213d11ca7.tar.gz caprover-one-click-apps-48e59ceb8963bf7187217ea6ba769a9213d11ca7.zip | |
Moved scripts to script dir
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/build_one_click_apps.js | 75 | ||||
| -rwxr-xr-x | scripts/publish-from-actions.sh | 93 | ||||
| -rw-r--r-- | scripts/validate_json.js | 71 |
3 files changed, 239 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 diff --git a/scripts/publish-from-actions.sh b/scripts/publish-from-actions.sh new file mode 100755 index 0000000..287b668 --- /dev/null +++ b/scripts/publish-from-actions.sh @@ -0,0 +1,93 @@ +#!/bin/bash + +# FROM: https://raw.githubusercontent.com/maxheld83/ghpages/master/LICENSE +# MIT License + +# Copyright (c) 2019 Maximilian Held + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + +set -e + +# Make sure build_dir content doesn't have leading/trailing slashes. Correct format: +# export BUILD_DIR="public" + +source ./build_dir +SOURCE_DIRECTORY_DEPLOY_GH=~/temp-gh-deploy-src +CLONED_DIRECTORY_DEPLOY_GH=~/temp-gh-deploy-cloned + +echo "#############################################" +echo "######### making directories" +echo "######### $SOURCE_DIRECTORY_DEPLOY_GH" +echo "######### $CLONED_DIRECTORY_DEPLOY_GH" +echo "#############################################" + +mkdir -p $SOURCE_DIRECTORY_DEPLOY_GH +mkdir -p $CLONED_DIRECTORY_DEPLOY_GH + +echo "#############################################" +echo "######### Setting env vars" +echo "#############################################" + +REMOTE_REPO="https://${GITHUB_PERSONAL_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" +REPONAME="$(echo $GITHUB_REPOSITORY| cut -d'/' -f 2)" + +OWNER="$(echo $GITHUB_REPOSITORY| cut -d'/' -f 1)" +GHIO="${OWNER}.github.io" +if [[ "$REPONAME" == "$GHIO" ]]; then + REMOTE_BRANCH="master" +else + REMOTE_BRANCH="gh-pages" +fi +sleep 1s +echo "#############################################" +echo "######### CLONING REMOTE_BRANCH: $REMOTE_BRANCH" +echo "#############################################" + + +cp -r $BUILD_DIR $SOURCE_DIRECTORY_DEPLOY_GH/ +git clone --single-branch --branch=$REMOTE_BRANCH $REMOTE_REPO $CLONED_DIRECTORY_DEPLOY_GH +sleep 1s +echo "#############################################" +echo "######### Removing old files" +echo "#############################################" +cd $CLONED_DIRECTORY_DEPLOY_GH && git rm -rf . && git clean -fdx +sleep 1s +echo "#############################################" +echo "######### Copying files" +echo "#############################################" +cp -r $SOURCE_DIRECTORY_DEPLOY_GH/$BUILD_DIR $CLONED_DIRECTORY_DEPLOY_GH/$BUILD_DIR +mv $CLONED_DIRECTORY_DEPLOY_GH/.git $CLONED_DIRECTORY_DEPLOY_GH/$BUILD_DIR/ +cd $CLONED_DIRECTORY_DEPLOY_GH/$BUILD_DIR/ +sleep 1s +echo "#############################################" +echo "######### Content pre-commit ###" +echo "#############################################" +ls -la +echo "#############################################" +echo "######### Commit and push ###" +echo "#############################################" +sleep 1s +git config user.name "${GITHUB_ACTOR}" +git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" +echo `date` >> forcebuild.date +git add -A +git commit -m 'Deploy to GitHub Pages' +git push $REMOTE_REPO $REMOTE_BRANCH:$REMOTE_BRANCH
\ No newline at end of file diff --git a/scripts/validate_json.js b/scripts/validate_json.js new file mode 100644 index 0000000..51efc52 --- /dev/null +++ b/scripts/validate_json.js @@ -0,0 +1,71 @@ + /*jshint esversion: 6 */ + const path = require('path'); + const fs = require('fs-extra') + + const PUBLIC = `public` + const pathOfPublic = path.join(__dirname, PUBLIC); + + + // validating version 2 + function validate() { + + const version = '2' + const pathOfVersion = path.join(pathOfPublic, 'v' + version); + const pathOfApps = path.join(pathOfVersion, 'apps'); + + 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]}`) + + apps[i] = apps[i].replace('.json', ''); + + 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 = ''; + + const logoFileName = apps[i] + '.png'; + + appDetails[i] = { + name: apps[i], + displayName: content.displayName, + description: content.description, + logoUrl: logoFileName + } + + const logoFullPath = path.join(pathOfVersion, 'logos', logoFileName); + + if (!fs.existsSync(logoFullPath) || + !fs.statSync(logoFullPath).isFile()) { + let printablePath = logoFullPath; + printablePath = printablePath.substr(printablePath.indexOf(`/${PUBLIC}`)) + throw new Error(`Cannot find logo for ${apps[i]} ${printablePath}`); + } + + console.log(`Validated ${apps[i]}`) + + } + + }) + } + + + Promise.resolve() + .then(function () { + return validate() + }) + .catch(function (err) { + console.error(err) + process.exit(127) + })
\ No newline at end of file |
