diff --git a/.env-secret.jinja b/.env-secret.jinja new file mode 100644 index 0000000..8b82c3d --- /dev/null +++ b/.env-secret.jinja @@ -0,0 +1 @@ +ODOO_VERSION={{odoo_version}} diff --git a/README.md b/README.md index 02cc8a0..44cce50 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,65 @@ -# Waft Odoo installation method +# Waft project template -Waft is a wrapper for installing [Odoo](https://github.com/odoo/odoo). +This repository is the template project for Waft. -For documentation, please see the accompanying [waftlib](https://github.com/sunflowerit/waftlib) +## Installing copier + +You can start a new Waft/Odoo project based on this template by using [copier](https://copier.readthedocs.io). + +Copier and a plugin first need to be installed as a tool on your system. + +``` +pipx install copier +pipx inject copier copier-template-extensions +``` + +or + +``` +uv tool install copier --with copier-template-extensions +``` + +## Creating a new project + +You can now use copier to clone this template Waft project into your own: + + copier copy https://github.com/sunflowerit/waft --trust --vcs-ref use-copier myproject + +This will ask you for the Odoo and waftlib versions to use, then set up the project. + +Select an Odoo version that you want to use, for example 18.0. + +When you are happy, push the project somewhere you like: + +``` +git init +git remote add git@org:repo.git +git add . +git commit -m "[ADD] initial project set up" +git push +``` + +## Updating to a newer project template version + +If you want to update a project to the newest version of the template, you can use: + +``` +cd myproject +copier update [--vcs-ref use-copier] --trust +``` + +Copier will then check back in with `github.com/sunflowerit/waft` and update any files to its newest template, and run migration scripts if they exist. + +If any project files have be edited locally, copier will not replace the files but show a conflict that you can solve. + +Once happy you can push the updates to your project repository: + +``` +git add . +git commit -m "[UPD] waft to newer version" +git push +``` + +## Using waft features + +Please see the [main waftlib README](https://github.com/sunflowerit/waftlib). diff --git a/README.md.jinja b/README.md.jinja new file mode 100644 index 0000000..90da8b6 --- /dev/null +++ b/README.md.jinja @@ -0,0 +1,5 @@ +# Your project + +Information about your project + +## more info diff --git a/_copier/context.py b/_copier/context.py new file mode 100644 index 0000000..e5683a7 --- /dev/null +++ b/_copier/context.py @@ -0,0 +1,42 @@ +import re + +from copier_template_extensions import ContextHook + + +class ContextUpdater(ContextHook): + + detection_run = False + waftlib_version = None + odoo_version = None + + def _detect_waftlib_version(self): + with open("bootstrap", "r") as file: + for line in file: + if line.startswith("export LIBRARIES_VERSION_BRANCH"): + pattern = r':-(.+?)}' + _match = re.search(pattern, line) + if _match: + return _match.group(1) + + def _detect_odoo_version(self): + with open(".env-shared", "r") as file: + for line in file: + if line.startswith("ODOO_VERSION="): + pattern = r'=\"(.+?)\"' + _match = re.search(pattern, line) + if _match: + return _match.group(1) + + def hook(self, context): + context_updates = {} + + if context.get("_copier_phase") == "prompt": + if not self.detection_run: + print("Trying to detect waftlib version from bootstrap file...") + self.waftlib_version = self._detect_waftlib_version() + print("Trying to detect Odoo version from .env-shared file...") + self.odoo_version = self._detect_odoo_version() + context_updates["default_waftlib_version"] = self.waftlib_version + context_updates["default_odoo_version"] = self.odoo_version + self.detection_run = True + return context_updates diff --git a/bootstrap b/bootstrap.jinja similarity index 89% rename from bootstrap rename to bootstrap.jinja index d66e9b1..c9c1f72 100755 --- a/bootstrap +++ b/bootstrap.jinja @@ -3,7 +3,7 @@ set -e export LIBRARIES_REPOSITORIES='https://github.com/sunflowerit/waftlib.git' -export LIBRARIES_VERSION_BRANCH=${LIBRARIES_VERSION_BRANCH:-v.22.05.30} #versions: v.21.05.10, v.21.09.22, v.22.05.30 +export LIBRARIES_VERSION_BRANCH=${LIBRARIES_VERSION_BRANCH:-{{waftlib_version}}} ################################################################ ###### ###### diff --git a/copier.yml b/copier.yml new file mode 100644 index 0000000..670070c --- /dev/null +++ b/copier.yml @@ -0,0 +1,65 @@ +# min version: 9.6, for supporting context phases +_min_copier_version: '9.6' + +_skip_if_exists: + - README.md # people need to fill this for themselves + +# use contextupdater plugin (requires --trust) +_jinja_extensions: + - copier_templates_extensions.TemplateExtensionLoader + - _copier/context.py:ContextUpdater + +# migrations (requires --trust) +#_migrations: +# - version: "v1.0.0" +# when: "{{ _stage == 'before' }}" +# command: ["{{ _copier_python }}", _copier/detect-versions.py] + +#_tasks: +# - when: "{{ _copier_operation == 'copy' }}" +# command: ["{{ _copier_python }}", _copier/detect-versions.py] + +# questions +odoo_version: + type: str + help: What Odoo version should this project have? + default: '{{ default_odoo_version }}' + choices: + - '19.0' + - '18.0' + - '17.0' + - '16.0' + - '15.0' + - '14.0' + - '13.0' + - '12.0' + - '11.0' + - '10.0' + - '9.0' + - '8.0' + +waftlib_version: + type: str + help: Which version of Waftlib should this project use? + default: '{{ default_waftlib_version }}' + choices: + - 'v.22.05.30' + - 'v.21.09.22' + - 'v.21.05.10' + - 'master' + +_message_after_copy: | + + Your Waft project with Odoo {{ odoo_version }} has been created successfully! + + Next steps: + + 1. Change directory to the project root: + + $ cd {{ _copier_conf.dst_path }} + + 2. Run bootstrap: + + $ ./bootstrap + + 3. Read the documentation on how to build Odoo diff --git a/{{_copier_conf.answers_file}}.jinja b/{{_copier_conf.answers_file}}.jinja new file mode 100644 index 0000000..a96840d --- /dev/null +++ b/{{_copier_conf.answers_file}}.jinja @@ -0,0 +1,2 @@ +# Changes here will be overwritten by Copier +{{ _copier_answers|to_nice_yaml -}}