From 48e59ceb8963bf7187217ea6ba769a9213d11ca7 Mon Sep 17 00:00:00 2001 From: Kasra Bigdeli Date: Tue, 23 Jun 2020 07:04:00 -0400 Subject: Moved scripts to script dir --- build_one_click_apps.js | 75 --------------------------------- package.json | 9 ++-- publish-from-actions.sh | 93 ----------------------------------------- scripts/build_one_click_apps.js | 75 +++++++++++++++++++++++++++++++++ scripts/publish-from-actions.sh | 93 +++++++++++++++++++++++++++++++++++++++++ scripts/validate_json.js | 71 +++++++++++++++++++++++++++++++ validate_json.js | 71 ------------------------------- 7 files changed, 243 insertions(+), 244 deletions(-) delete mode 100644 build_one_click_apps.js delete mode 100755 publish-from-actions.sh create mode 100644 scripts/build_one_click_apps.js create mode 100755 scripts/publish-from-actions.sh create mode 100644 scripts/validate_json.js delete mode 100644 validate_json.js diff --git a/build_one_click_apps.js b/build_one_click_apps.js deleted file mode 100644 index 4047478..0000000 --- a/build_one_click_apps.js +++ /dev/null @@ -1,75 +0,0 @@ - /*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/package.json b/package.json index 2543d5a..d81d1f6 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,11 @@ { - "name": "CapRover-one-click-apps", + "name": "caprover-one-click-apps", "version": "1.0.0", "description": "One Click App Repository for CapRover", - "main": "build_and_publish_to_github_pages.js", "scripts": { - "build": "node ./build_one_click_apps.js", - "validate_json": "node ./validate_json.js", - "publish": "npm run build && ./publish-from-actions.sh" + "build": "node ./scripts/build_one_click_apps.js", + "validate_json": "node ./scripts/validate_json.js", + "publish": "npm run build && ./scripts/publish-from-actions.sh" }, "repository": { "type": "git", diff --git a/publish-from-actions.sh b/publish-from-actions.sh deleted file mode 100755 index 287b668..0000000 --- a/publish-from-actions.sh +++ /dev/null @@ -1,93 +0,0 @@ -#!/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/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 diff --git a/validate_json.js b/validate_json.js deleted file mode 100644 index 51efc52..0000000 --- a/validate_json.js +++ /dev/null @@ -1,71 +0,0 @@ - /*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 -- cgit v1.2.3