Skip to content

Commit

Permalink
Guillotina addon in core (#2699)
Browse files Browse the repository at this point in the history
* volto-guillotina, initial commit

* Integrate Cypress infrastructure with it

* Add support for customizations in testing addons

* Volto logo in Guillotina

* Backport ongoing actions override for sharing

* Changelog
  • Loading branch information
sneridagh committed Oct 10, 2021
1 parent a5c5312 commit 1d4adda
Show file tree
Hide file tree
Showing 15 changed files with 308 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,8 @@

### Feature

- Add `volto-guillotina` addon to core @sneridagh

### Bugfix

### Internal
Expand All @@ -17,6 +19,8 @@
- Footer: Point to plone.org instead of plone.com @ericof
- Fix "make start-frontend" @tisto

- Update all the tests infrastructure for the new `volto-guillotina` addon @sneridagh

## 14.0.0-alpha.14 (2021-10-01)

### Bugfix
Expand Down
27 changes: 27 additions & 0 deletions addon-registry.js
Expand Up @@ -361,6 +361,33 @@ class AddonConfigurationRegistry {
return aliases;
}

/**
* Allow testing packages addons to customize Volto and other addons.
*
* Same as the above one, but specific for Volto testing addons
*/
getTestingAddonCustomizationPaths() {
let aliases = {};
if (process.env.RAZZLE_TESTING_ADDONS) {
process.env.RAZZLE_TESTING_ADDONS.split(',').forEach((addon) => {
const normalizedAddonName = addon.split(':')[0];
const testingPackagePath = `${this.projectRootPath}/packages/${normalizedAddonName}/src`;
if (fs.existsSync(testingPackagePath)) {
const basePath = getPackageBasePath(testingPackagePath);
const packageJson = path.join(basePath, 'package.json');
aliases = {
...aliases,
...this.getCustomizationPaths(require(packageJson), basePath),
};
}
});

return aliases;
} else {
return [];
}
}

/**
* Returns an agregated, dependency-resolved list of addon loader strings
*/
Expand Down
6 changes: 0 additions & 6 deletions cypress/cypress.guillotina.json

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -60,7 +60,7 @@
"cypress:run:core-sandbox": "NODE_ENV=production CYPRESS_API=plone cypress run --config integrationFolder='cypress/tests/core-sandbox'",
"cypress:run:multilingual": "NODE_ENV=production CYPRESS_API=plone cypress run --config integrationFolder='cypress/tests/multilingual'",
"cypress:run:workingCopy": "NODE_ENV=production CYPRESS_API=plone cypress run --config integrationFolder='cypress/tests/workingCopy'",
"cypress:run:guillotina": "NODE_ENV=production CYPRESS_API=guillotina cypress run --config-file cypress/cypress.guillotina.json",
"cypress:run:guillotina": "NODE_ENV=production CYPRESS_API=guillotina cypress run --config integrationFolder='cypress/tests/guillotina'",
"cy:install": "cypress install",
"cy:test:fixture:setup": "node cypress/support/reset-fixture.js",
"cy:test:fixture:teardown": "node cypress/support/reset-fixture.js teardown",
Expand All @@ -73,7 +73,7 @@
"ci:start-frontend-multilingual": "RAZZLE_TESTING_ADDONS=core-sandbox:multilingualFixture RAZZLE_API_PATH=http://localhost:55001/plone yarn build && start-test start:prod http://localhost:3000 cypress:run:multilingual",
"ci:start-frontend-workingCopy": "RAZZLE_TESTING_ADDONS=core-sandbox:workingCopyFixture RAZZLE_API_PATH=http://localhost:55001/plone yarn build && start-test start:prod http://localhost:3000 cypress:run:workingCopy",
"ci:start-project-frontend": "cd my-volto-app && RAZZLE_API_PATH=http://localhost:55001/plone yarn build && start-test start:prod http://localhost:3000 'cd .. && yarn cypress:run'",
"ci:start-frontend-guillotina": "RAZZLE_API_PATH=http://localhost:8081/db/web yarn build && start-test start:prod http://localhost:3000 cypress:run:guillotina",
"ci:start-frontend-guillotina": "RAZZLE_TESTING_ADDONS=volto-guillotina RAZZLE_API_PATH=http://localhost:8081/db/web yarn build && start-test start:prod http://localhost:3000 cypress:run:guillotina",
"ci:cypress:run": "start-test ci:start-api-plone http-get://localhost:55001/plone ci:start-frontend",
"ci:cypress:project:run": "start-test ci:start-api-plone http-get://localhost:55001/plone ci:start-project-frontend",
"ci:cypress:run:core-sandbox": "start-test ci:start-api-plone http-get://localhost:55001/plone ci:start-frontend-core-sandbox",
Expand Down
16 changes: 16 additions & 0 deletions packages/volto-guillotina/.npmignore
@@ -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
46 changes: 46 additions & 0 deletions packages/volto-guillotina/.project.eslintrc.js
@@ -0,0 +1,46 @@
const fs = require('fs');
const path = require('path');

const projectRootPath = fs.realpathSync('./project'); // __dirname
const packageJson = require(path.join(projectRootPath, 'package.json'));
const jsConfig = require(path.join(projectRootPath, 'jsconfig.json')).compilerOptions;

const pathsConfig = jsConfig.paths;

let voltoPath = path.join(projectRootPath, 'node_modules/@plone/volto');

Object.keys(pathsConfig).forEach(pkg => {
if (pkg === '@plone/volto') {
voltoPath = `./${jsConfig.baseUrl}/${pathsConfig[pkg][0]}`;
}
});
const AddonConfigurationRegistry = require(`${voltoPath}/addon-registry.js`);
const reg = new AddonConfigurationRegistry(projectRootPath);

// Extends ESlint configuration for adding the aliases to `src` directories in Volto addons
const addonAliases = Object.keys(reg.packages).map(o => [
o,
reg.packages[o].modulePath,
]);


module.exports = {
extends: `${projectRootPath}/node_modules/@plone/volto/.eslintrc`,
settings: {
'import/resolver': {
alias: {
map: [
['@plone/volto', '@plone/volto/src'],
...addonAliases,
['@package', `${__dirname}/src`],
['~', `${__dirname}/src`],
],
extensions: ['.js', '.jsx', '.json'],
},
'babel-plugin-root-import': {
rootPathSuffix: 'src',
},
},
},
};

58 changes: 58 additions & 0 deletions packages/volto-guillotina/Makefile
@@ -0,0 +1,58 @@
# Yeoman Volto App development

### Defensive settings for make:
# https://tech.davis-hansson.com/p/make/
SHELL:=bash
.ONESHELL:
.SHELLFLAGS:=-xeu -o pipefail -O inherit_errexit -c
.SILENT:
.DELETE_ON_ERROR:
MAKEFLAGS+=--warn-undefined-variables
MAKEFLAGS+=--no-builtin-rules

# Project settings

DIR=$(shell basename $$(pwd))
ADDON ?= "@plone/volto-guillotina"

# Recipe snippets for reuse

# We like colors
# From: https://coderwall.com/p/izxssa/colored-makefile-for-golang-projects
RED=`tput setaf 1`
GREEN=`tput setaf 2`
RESET=`tput sgr0`
YELLOW=`tput setaf 3`


# Top-level targets

.PHONY: project
project:
npm install -g yo
npm install -g @plone/generator-volto
npm install -g mrs-developer
yo @plone/volto project --addon ${ADDON} --workspace "src/addons/${DIR}" --no-interactive
ln -sf $$(pwd) project/src/addons/
cp .project.eslintrc.js .eslintrc.js
cd project && yarn
@echo "-------------------"
@echo "$(GREEN)Volto project is ready!$(RESET)"
@echo "$(RED)Now run: cd project && yarn start$(RESET)"

.PHONY: all
all: project

.PHONY: start-test-backend
start-test-backend: ## Start Test Plone Backend
@echo "$(GREEN)==> Start Test Plone Backend$(RESET)"
docker run -i --rm -e ZSERVER_HOST=0.0.0.0 -e ZSERVER_PORT=55001 -p 55001:55001 -e SITE=plone -e APPLY_PROFILES=plone.app.contenttypes:plone-content,plone.restapi:default,kitconcept.volto:default-homepage -e CONFIGURE_PACKAGES=plone.app.contenttypes,plone.restapi,kitconcept.volto,kitconcept.volto.cors -e ADDONS='plone.app.robotframework plone.app.contenttypes plone.restapi kitconcept.volto' plone ./bin/robot-server plone.app.robotframework.testing.PLONE_ROBOT_TESTING

.PHONY: start-backend-docker
start-backend-docker: ## Starts a Docker-based backend
@echo "$(GREEN)==> Start Docker-based Plone Backend$(RESET)"
docker run -it --rm --name=plone -p 8080:8080 -e SITE=Plone -e ADDONS="kitconcept.volto" -e ZCML="kitconcept.volto.cors" plone

.PHONY: help
help: ## Show this help.
@echo -e "$$(grep -hE '^\S+:.*##' $(MAKEFILE_LIST) | sed -e 's/:.*##\s*/:/' -e 's/^\(.\+\):\(.*\)/\\x1b[36m\1\\x1b[m:\2/' | column -c2 -t -s :)"
17 changes: 17 additions & 0 deletions packages/volto-guillotina/babel.config.js
@@ -0,0 +1,17 @@
module.exports = function (api) {
api.cache(true);
const presets = ['razzle/babel'];
const plugins = [
[
'react-intl', // React Intl extractor, required for the whole i18n infrastructure to work
{
messagesDir: './build/messages/',
},
],
];

return {
plugins,
presets,
};
};
14 changes: 14 additions & 0 deletions packages/volto-guillotina/locales/volto.pot
@@ -0,0 +1,14 @@
msgid ""
msgstr ""
"Project-Id-Version: Plone\n"
"POT-Creation-Date: 2021-01-29T12:34:47.097Z\n"
"Last-Translator: Plone i18n <plone-i18n@lists.sourceforge.net>\n"
"Language-Team: Plone i18n <plone-i18n@lists.sourceforge.net>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"Language-Code: en\n"
"Language-Name: English\n"
"Preferred-Encodings: utf-8\n"
"Domain: volto\n"
19 changes: 19 additions & 0 deletions packages/volto-guillotina/package.json
@@ -0,0 +1,19 @@
{
"name": "@plone/volto-guillotina",
"version": "0.1.0",
"description": "volto-guillotina: Volto add-on",
"main": "src/index.js",
"license": "MIT",
"keywords": [
"volto-addon",
"volto",
"plone",
"react"
],
"scripts": {
"i18n": "rm -rf build/messages && NODE_ENV=production i18n --addon"
},
"dependencies": {
"@plone/scripts": "*"
}
}
@@ -0,0 +1,44 @@
/**
* Sharing actions.
* @module actions/sharing/sharing
*/

import {
UPDATE_SHARING,
GET_SHARING,
} from '@plone/volto/constants/ActionTypes';

/**
* Update sharing function.
* @function updateSharing
* @param {string} url Content url.
* @param {Object} sharing Sharing data.
* @returns {Object} Update sharing action.
*/
export function updateSharing(url, sharing) {
return {
type: UPDATE_SHARING,
request: {
op: 'post',
path: `${url}/@grant`,
data: sharing,
},
};
}

/**
* Get sharing function.
* @function getSharing
* @param {string} url Content url.
* @param {string} search Search value.
* @returns {Object} Get sharing action.
*/
export function getSharing(url, search = '') {
return {
type: GET_SHARING,
request: {
op: 'get',
path: `${url}/@grant${search !== '' ? `?search=${search}` : ''}`,
},
};
}
@@ -0,0 +1,41 @@
import { updateSharing, getSharing } from './sharing';
import {
UPDATE_SHARING,
GET_SHARING,
} from '@plone/volto/constants/ActionTypes';

describe('Sharing action', () => {
describe('updateSharing', () => {
it('should create an action to update sharing', () => {
const url = 'http://localhost';
const sharing = 'Hello World!';
const action = updateSharing(url, sharing);

expect(action.type).toEqual(UPDATE_SHARING);
expect(action.request.op).toEqual('post');
expect(action.request.path).toEqual(`${url}/@sharing`);
expect(action.request.data).toEqual(sharing);
});
});

describe('getSharing', () => {
it('should create an action to get sharing', () => {
const url = 'http://localhost';
const action = getSharing(url);

expect(action.type).toEqual(GET_SHARING);
expect(action.request.op).toEqual('get');
expect(action.request.path).toEqual(`${url}/@sharing`);
});

it('should create an action to get sharing with search param', () => {
const url = 'http://localhost';
const search = 'admin';
const action = getSharing(url, search);

expect(action.type).toEqual(GET_SHARING);
expect(action.request.op).toEqual('get');
expect(action.request.path).toEqual(`${url}/@sharing?search=${search}`);
});
});
});
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions packages/volto-guillotina/src/index.js
@@ -0,0 +1,5 @@
const applyConfig = (config) => {
return config;
};

export default applyConfig;
1 change: 1 addition & 0 deletions razzle.config.js
Expand Up @@ -197,6 +197,7 @@ const defaultModify = ({
];

config.resolve.alias = {
...registry.getTestingAddonCustomizationPaths(),
...registry.getAddonCustomizationPaths(),
...registry.getProjectCustomizationPaths(),
...config.resolve.alias,
Expand Down

0 comments on commit 1d4adda

Please sign in to comment.