From 2e96b2d72d77f1ec2ca1ef00b260b7fe7cca07c9 Mon Sep 17 00:00:00 2001 From: Alin Voinea Date: Tue, 17 Nov 2020 15:36:45 +0200 Subject: [PATCH] Initial commit --- .gitignore | 16 +++++++ .release-it.json | 17 +++++++ CHANGELOG.md | 5 ++ DEVELOP.md | 52 ++++++++++++++++++++ Jenkinsfile | 122 +++++++++++++++++++++++++++++++++++++++++++++++ LICENSE.md | 9 ++++ README.md | 62 ++++++++++++++++++++++++ bootstrap | 30 ++++++++++++ package.json | 32 +++++++++++++ src/index.js | 5 ++ 10 files changed, 350 insertions(+) create mode 100644 .gitignore create mode 100644 .release-it.json create mode 100644 CHANGELOG.md create mode 100644 DEVELOP.md create mode 100644 Jenkinsfile create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 bootstrap create mode 100644 package.json create mode 100644 src/index.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..211dab2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ +.vscode/ +.history +logs +*.log +npm-debug.log* +.DS_Store +*.swp +yarn-error.log + +node_modules +build +dist +.env.local +.env.development.local +.env.test.local +.env.production.local diff --git a/.release-it.json b/.release-it.json new file mode 100644 index 0000000..a029900 --- /dev/null +++ b/.release-it.json @@ -0,0 +1,17 @@ +{ + "npm": { + "publish": false + }, + "git": { + "changelog": "npx auto-changelog --stdout --commit-limit false -u --template https://github.com/raw/release-it/release-it/master/templates/changelog-compact.hbs", + "tagName": "${version}" + }, + "github": { + "release": true, + "releaseName": "${version}", + "releaseNotes": "npx auto-changelog --stdout --commit-limit false -u --template https://github.com/raw/release-it/release-it/master/templates/changelog-compact.hbs" + }, + "hooks": { + "after:bump": "npx auto-changelog --commit-limit false -p" + } +} diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..3742d31 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +# Changelog + +## 0.1.0 + +- Initial release diff --git a/DEVELOP.md b/DEVELOP.md new file mode 100644 index 0000000..c8850b2 --- /dev/null +++ b/DEVELOP.md @@ -0,0 +1,52 @@ +# volto-addon-template + +## Develop + +Before starting make sure your development environment is properly set. See [Volto Developer Documentation](https://docs.voltocms.com/getting-started/install/) + +1. Make sure you have installed `yo`, `@plone/generator-volto` and `mrs-developer` + + $ npm install -g yo + $ npm install -g @plone/generator-volto + $ npm install -g mrs-developer + +1. Create new volto app + + $ yo @plone/volto my-volto-project --addon @eeacms/volto-addon-template + $ cd my-volto-project + +1. Add the following to `mrs.developer.json`: + + { + "volto-addon-template": { + "url": "https://github.com/eea/volto-addon-template.git", + "package": "@eeacms/volto-addon-template", + "branch": "develop", + "path": "src" + } + } + +1. Install + + $ yarn develop + $ yarn + +1. Start backend + + $ docker run -d --name plone -p 8080:8080 -e SITE=Plone plone + + ...wait for backend to setup and start - `Ready to handle requests`: + + $ docker logs -f plone + + ...you can also check http://localhost:8080/Plone + +1. Start frontend + + $ yarn start + +1. Go to http://localhost:3000 + +1. Happy hacking! + + $ cd src/addons/volto-addon-template/ diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..8b8a524 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,122 @@ +pipeline { + agent any + + environment { + GIT_NAME = "volto-addon-template" + NAMESPACE = "@eeacms" + SONARQUBE_TAGS = "volto.eea.europa.eu" + DEPENDENCIES = "" + } + + stages { + + stage('Code') { + steps { + parallel( + + "ES lint": { + node(label: 'docker') { + sh '''docker run -i --rm --name="$BUILD_TAG-eslint" -e NAMESPACE="$NAMESPACE" -e DEPENDENCIES="$DEPENDENCIES" -e GIT_NAME=$GIT_NAME -e GIT_BRANCH="$BRANCH_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" eeacms/volto-test eslint''' + } + }, + + "Style lint": { + node(label: 'docker') { + sh '''docker run -i --rm --name="$BUILD_TAG-stylelint" -e NAMESPACE="$NAMESPACE" -e DEPENDENCIES="$DEPENDENCIES" -e GIT_NAME=$GIT_NAME -e GIT_BRANCH="$BRANCH_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" eeacms/volto-test stylelint''' + } + }, + + "Prettier": { + node(label: 'docker') { + sh '''docker run -i --rm --name="$BUILD_TAG-prettier" -e NAMESPACE="$NAMESPACE" -e DEPENDENCIES="$DEPENDENCIES" -e GIT_NAME=$GIT_NAME -e GIT_BRANCH="$BRANCH_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" eeacms/volto-test prettier''' + } + } + ) + } + } + + stage('Tests') { + steps { + parallel( + + "Volto": { + node(label: 'docker') { + script { + try { + sh '''docker pull eeacms/volto-test''' + sh '''docker run -i --name="$BUILD_TAG-volto" -e NAMESPACE="$NAMESPACE" -e DEPENDENCIES="$DEPENDENCIES" -e GIT_NAME=$GIT_NAME -e GIT_BRANCH="$BRANCH_NAME" -e GIT_CHANGE_ID="$CHANGE_ID" eeacms/volto-test''' + sh '''mkdir -p xunit-reports''' + sh '''docker cp $BUILD_TAG-volto:/opt/frontend/my-volto-project/coverage xunit-reports/''' + sh '''docker cp $BUILD_TAG-volto:/opt/frontend/my-volto-project/junit.xml xunit-reports/''' + sh '''docker cp $BUILD_TAG-volto:/opt/frontend/my-volto-project/unit_tests_log.txt xunit-reports/''' + stash name: "xunit-reports", includes: "xunit-reports/**/*" + junit 'xunit-reports/junit.xml' + archiveArtifacts artifacts: 'xunit-reports/unit_tests_log.txt', fingerprint: true + publishHTML (target : [ + allowMissing: false, + alwaysLinkToLastBuild: true, + keepAll: true, + reportDir: 'xunit-reports/coverage/lcov-report', + reportFiles: 'index.html', + reportName: 'UTCoverage', + reportTitles: 'Unit Tests Code Coverage' + ]) + } finally { + sh '''docker rm -v $BUILD_TAG-volto''' + } + } + } + } + ) + } + } + + stage('Report to SonarQube') { + // Exclude Pull-Requests + when { + allOf { + environment name: 'CHANGE_ID', value: '' + } + } + steps { + node(label: 'swarm') { + script{ + checkout scm + unstash "xunit-reports" + def scannerHome = tool 'SonarQubeScanner'; + def nodeJS = tool 'NodeJS11'; + withSonarQubeEnv('Sonarqube') { + sh '''sed -i "s#/opt/frontend/my-volto-project/src/addons/${GIT_NAME}/##g" xunit-reports/coverage/lcov.info''' + sh "export PATH=$PATH:${scannerHome}/bin:${nodeJS}/bin; sonar-scanner -Dsonar.javascript.lcov.reportPaths=./xunit-reports/coverage/lcov.info -Dsonar.sources=./src -Dsonar.coverage.exclusions=src/**/*.test.js -Dsonar.projectKey=$GIT_NAME-$BRANCH_NAME -Dsonar.projectVersion=$BRANCH_NAME-$BUILD_NUMBER" + sh '''try=2; while [ \$try -gt 0 ]; do curl -s -XPOST -u "${SONAR_AUTH_TOKEN}:" "${SONAR_HOST_URL}api/project_tags/set?project=${GIT_NAME}-${BRANCH_NAME}&tags=${SONARQUBE_TAGS},${BRANCH_NAME}" > set_tags_result; if [ \$(grep -ic error set_tags_result ) -eq 0 ]; then try=0; else cat set_tags_result; echo "... Will retry"; sleep 60; try=\$(( \$try - 1 )); fi; done''' + } + } + } + } + } + + } + + post { + changed { + script { + def url = "${env.BUILD_URL}/display/redirect" + def status = currentBuild.currentResult + def subject = "${status}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'" + def summary = "${subject} (${url})" + def details = """

${env.JOB_NAME} - Build #${env.BUILD_NUMBER} - ${status}

+

Check console output at ${env.JOB_BASE_NAME} - #${env.BUILD_NUMBER}

+ """ + + def color = '#FFFF00' + if (status == 'SUCCESS') { + color = '#00FF00' + } else if (status == 'FAILURE') { + color = '#FF0000' + } + + emailext (subject: '$DEFAULT_SUBJECT', to: '$DEFAULT_RECIPIENTS', body: details) + } + } + } +} diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..0992c00 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2020 European Environment Agency + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..636cbd6 --- /dev/null +++ b/README.md @@ -0,0 +1,62 @@ +# volto-addon-template +[![Releases](https://img.shields.io/github/v/release/eea/volto-addon-template)](https://github.com/eea/volto-addon-template/releases) +[![Pipeline](https://ci.eionet.europa.eu/buildStatus/icon?job=volto-addons%2Fvolto-addon-template%2Fmaster&subject=master)](https://ci.eionet.europa.eu/view/Github/job/volto-addons/job/volto-addon-template/job/master/display/redirect) +[![Pipeline](https://ci.eionet.europa.eu/buildStatus/icon?job=volto-addons%2Fvolto-addon-template%2Fdevelop&subject=develop)](https://ci.eionet.europa.eu/view/Github/job/volto-addons/job/volto-addon-template/job/develop/display/redirect) + +[Volto](https://github.com/plone/volto) add-on + +## Features + +### + +Demo GIF + +## Getting started + +1. Create new volto project if you don't already have one: + + ``` + $ npm install -g yo @plone/generator-volto + $ yo @plone/volto my-volto-project --addon @eeacms/volto-addon-template + + $ cd my-volto-project + $ yarn add -W @eeacms/volto-addon-template + ``` + +1. If you already have a volto project, just update `package.json`: + + ```JSON + "addons": [ + "@eeacms/volto-addon-template" + ], + + "dependencies": { + "@eeacms/volto-addon-template": "^1.0.0" + } + ``` + +1. Install new add-ons and restart Volto: + + ``` + $ yarn + $ yarn start + ``` + +1. Go to http://localhost:3000 + +1. Happy editing! + +## How to contribute + +See [DEVELOP.md](https://github.com/eea/volto-addon-template/blob/master/DEVELOP.md). + +## Copyright and license + +The Initial Owner of the Original Code is European Environment Agency (EEA). +All Rights Reserved. + +See [LICENSE.md](https://github.com/eea/volto-addon-template/blob/master/LICENSE.md) for details. + +## Funding + +[European Environment Agency (EU)](http://eea.europa.eu) diff --git a/bootstrap b/bootstrap new file mode 100644 index 0000000..8b2c40f --- /dev/null +++ b/bootstrap @@ -0,0 +1,30 @@ +const path = require('path'); +const fs = require('fs'); + +const currentDir = path.basename(process.cwd()); + +const bootstrap = function (ofile) { + fs.readFile(ofile, 'utf8', function (err, data) { + if (err) { + return console.log(err); + } + var result = data.replace(/volto-addon-template/g, currentDir); + + fs.writeFile(ofile, result, 'utf8', function (err) { + if (err) { + return console.log(err); + } + }); + }); +} + +fs.readdir(".", { withFileTypes: true }, (err, dirents) => { + const files = dirents + .filter(dirent => dirent.isFile()) + .map(dirent => dirent.name); + files.forEach(function (file) { + if (file != 'bootstrap') { + bootstrap(file); + } + }); +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..cc01f02 --- /dev/null +++ b/package.json @@ -0,0 +1,32 @@ +{ + "name": "@eeacms/volto-addon-template", + "version": "0.1.0", + "description": "volto-addon-template: Volto add-on", + "main": "src/index.js", + "author": "European Environment Agency: IDM2 A-Team", + "license": "MIT", + "homepage": "https://github.com/eea/volto-addon-template", + "keywords": [ + "volto-addon", + "volto", + "plone", + "react" + ], + "repository": { + "type": "git", + "url": "git@github.com:eea/volto-addon-template.git" + }, + "dependencies": { + }, + "scripts": { + "release": "release-it", + "bootstrap": "node bootstrap", + "stylelint": "../../../node_modules/stylelint/bin/stylelint.js --allow-empty-input 'src/**/*.{css,less}'", + "stylelint:overrides": "../../../node_modules/.bin/stylelint --syntax less --allow-empty-input 'theme/**/*.overrides' 'src/**/*.overrides'", + "stylelint:fix": "yarn stylelint --fix && yarn stylelint:overrides --fix", + "prettier": "../../../node_modules/.bin/prettier --single-quote --check 'src/**/*.{js,jsx,json,css,less,md}'", + "prettier:fix": "../../../node_modules/.bin/prettier --single-quote --write 'src/**/*.{js,jsx,json,css,less,md}'", + "lint": "../../../node_modules/eslint/bin/eslint.js --max-warnings=0 'src/**/*.{js,jsx}'", + "lint:fix": "../../../node_modules/eslint/bin/eslint.js --fix 'src/**/*.{js,jsx}'" + } +} diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..cb042f0 --- /dev/null +++ b/src/index.js @@ -0,0 +1,5 @@ +const applyConfig = (config) => { + return config; +}; + +export default applyConfig;