-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support creation of a project without an addon
- Loading branch information
Showing
16 changed files
with
409 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: Plone Frontend Project CI | ||
on: | ||
push: | ||
paths: | ||
- "sub/frontend_project/**" | ||
- ".github/workflows/sub_frontend_project.yml" | ||
workflow_dispatch: | ||
|
||
env: | ||
NODE_VERSION: 20.x | ||
PYTHON_VERSION: "3.10" | ||
|
||
jobs: | ||
|
||
generation: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python-version: | ||
- "3.10" | ||
- "3.11" | ||
- "3.12" | ||
|
||
steps: | ||
# git checkout | ||
- name: Checkout codebase | ||
uses: actions/checkout@v4 | ||
|
||
# python setup | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
cache: 'pip' | ||
|
||
# python install | ||
- name: Install dependencies | ||
run: | | ||
pip install -r requirements.txt | ||
# Test | ||
- name: Run tests | ||
run: | | ||
cd sub/frontend_project | ||
python -m pytest tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ def context() -> dict: | |
"email": "[email protected]", | ||
"github_organization": "collective", | ||
"npm_package_name": "@plone-collective/volto-addon", | ||
"volto_version": "18.0.0-alpha.31" | ||
"volto_version": "18.0.0-alpha.31", | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
SHELL := /bin/bash | ||
CURRENT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) | ||
|
||
|
||
# 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` | ||
|
||
.PHONY: all | ||
all: build | ||
|
||
|
||
# Add the following 'help' target to your Makefile | ||
# And add help text after each target name starting with '\#\#' | ||
.PHONY: help | ||
help: ## This help message | ||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | ||
|
||
.PHONY: clean | ||
clean: ## Clean | ||
rm -rf volto-addon | ||
|
||
../../bin/cookieplone: ## cookieplone installation | ||
$(MAKE) -C ".." bin/cookieplone | ||
|
||
.PHONY: format | ||
format: ../../bin/cookieplone ## Format code | ||
@echo "$(GREEN)==> Formatting codebase $(RESET)" | ||
../../bin/black hooks tests | ||
../../bin/isort hooks tests | ||
|
||
.PHONY: generate | ||
generate: ../../bin/cookieplone ## Create a sample package | ||
@echo "$(GREEN)==> Creating new test package$(RESET)" | ||
rm -rf volto-addon | ||
../../bin/cookiecutter . --no-input | ||
|
||
.PHONY: test | ||
test: ../../bin/cookieplone ## Create a sample package and tests it | ||
@echo "$(GREEN)==> Creating new test package$(RESET)" | ||
../../bin/python -m pytest tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
{ | ||
"title": "Frontend Project", | ||
"volto_version": "{{ 'Yes' | latest_volto }}", | ||
"author": "Plone Community", | ||
"email": "[email protected]", | ||
"__folder_name": "app", | ||
"__gha_enable": true, | ||
"__version_plone_volto": "{{ cookiecutter.volto_version }}", | ||
|
@@ -11,7 +13,9 @@ | |
"title": "Project name", | ||
"volto_version": "Volto version" | ||
}, | ||
"_copy_without_render": [], | ||
"_copy_without_render": [ | ||
"_project_files" | ||
], | ||
"_extensions": [ | ||
"cookieplone.filters.latest_volto" | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"""Pytest configuration.""" | ||
|
||
import re | ||
from copy import deepcopy | ||
from pathlib import Path | ||
from typing import List | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def variable_pattern(): | ||
return re.compile("{{( ?cookiecutter)[.](.*?)}}") | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def context() -> dict: | ||
"""Cookiecutter context.""" | ||
return { | ||
"title": "Frontend project", | ||
"author": "Plone Collective", | ||
"email": "[email protected]", | ||
"volto_version": "18.0.0-alpha.31", | ||
} | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def bad_context() -> dict: | ||
"""Cookiecutter context with invalid data.""" | ||
return { | ||
"title": "Frontend project", | ||
"author": "Plone Collective", | ||
"email": "[email protected]", | ||
"volto_version": "---", | ||
} | ||
|
||
|
||
@pytest.fixture | ||
def build_files_list(): | ||
def func(root_dir: Path) -> List[Path]: | ||
"""Build a list containing absolute paths to the generated files.""" | ||
return [path for path in Path(root_dir).glob("*") if path.is_file()] | ||
|
||
return func | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def cutter_result(cookies_session, context): | ||
"""Cookiecutter result.""" | ||
return cookies_session.bake(extra_context=context) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"""Test cookiecutter generation with all features enabled.""" | ||
|
||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
|
||
def test_creation(cookies, context: dict): | ||
"""Generated project should match provided value.""" | ||
result = cookies.bake(extra_context=context) | ||
assert result.exception is None | ||
assert result.exit_code == 0 | ||
assert result.project_path.name == "app" | ||
assert result.project_path.is_dir() | ||
|
||
|
||
def test_variable_substitution(build_files_list, variable_pattern, cutter_result): | ||
"""Check if no file was unprocessed.""" | ||
paths = build_files_list(cutter_result.project_path) | ||
for path in paths: | ||
for line in open(path): | ||
match = variable_pattern.search(line) | ||
msg = f"cookiecutter variable not replaced in {path}" | ||
assert match is None, msg | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"file_path,text,expected", | ||
[ | ||
[".eslintrc.js", "volto-addon", False], | ||
["Makefile", "volto-addon", False], | ||
["package.json", "volto-addon-dev", False], | ||
["package.json", "project-dev", True], | ||
["volto.config.js", "volto-addon", False], | ||
], | ||
) | ||
def test_root_files_do_not_mention_addon( | ||
cutter_result, file_path: Path, text: str, expected: bool | ||
): | ||
"""Check if root files were generated and have no reference to the addon.""" | ||
path = cutter_result.project_path / file_path | ||
assert path.exists() | ||
assert path.is_file() | ||
assert (text in path.read_text()) is expected |
30 changes: 30 additions & 0 deletions
30
sub/frontend_project/{{ cookiecutter.__folder_name }}/_project_files/.eslintrc.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const fs = require('fs'); | ||
const projectRootPath = __dirname; | ||
|
||
let coreLocation; | ||
if (fs.existsSync(`${projectRootPath}/core`)) | ||
coreLocation = `${projectRootPath}/core`; | ||
else if (fs.existsSync(`${projectRootPath}/../../core`)) | ||
coreLocation = `${projectRootPath}/../../core`; | ||
|
||
module.exports = { | ||
extends: `${coreLocation}/packages/volto/.eslintrc`, | ||
rules: { | ||
'import/no-unresolved': 1, | ||
}, | ||
settings: { | ||
'import/resolver': { | ||
alias: { | ||
map: [ | ||
['@plone/volto', `${coreLocation}/packages/volto/src`], | ||
[ | ||
'@plone/volto-slate', | ||
`${coreLocation}/core/packages/volto-slate/src`, | ||
], | ||
['@plone/registry', `${coreLocation}/packages/registry/src`], | ||
], | ||
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json'], | ||
}, | ||
}, | ||
}, | ||
}; |
Oops, something went wrong.