From 21d2b123e05575690927d9f1a6cf9d2b44070799 Mon Sep 17 00:00:00 2001 From: Kenneth Belitzky Date: Thu, 8 May 2025 19:30:35 +0000 Subject: [PATCH 1/2] Refactor configuration structure from 'structure' to 'files' in YAML and JSON files --- README.es.md | 8 ++--- README.md | 8 ++--- example/structure.yaml | 2 +- struct-schema.json | 32 ++++++++++++++++++- struct_module/commands/generate.py | 2 +- struct_module/commands/info.py | 6 ++-- struct_module/commands/validate.py | 2 +- struct_module/contribs/ansible-playbook.yaml | 2 +- struct_module/contribs/chef-cookbook.yaml | 2 +- struct_module/contribs/ci-cd-pipelines.yaml | 2 +- .../contribs/cloudformation-files.yaml | 2 +- .../contribs/configs/codeowners.yaml | 2 +- .../contribs/configs/devcontainer.yaml | 2 +- .../contribs/configs/editor-config.yaml | 2 +- struct_module/contribs/configs/eslint.yaml | 2 +- struct_module/contribs/configs/jshint.yaml | 2 +- struct_module/contribs/configs/prettier.yaml | 2 +- struct_module/contribs/docker-files.yaml | 2 +- .../contribs/documentation-template.yaml | 2 +- struct_module/contribs/git-hooks.yaml | 2 +- .../contribs/github/prompts/generic.yaml | 2 +- .../contribs/github/prompts/react-form.yaml | 2 +- .../contribs/github/prompts/security-api.yaml | 2 +- .../contribs/github/prompts/struct.yaml | 2 +- struct_module/contribs/github/templates.yaml | 2 +- .../github/workflows/execute-tf-workflow.yaml | 2 +- .../contribs/github/workflows/labeler.yaml | 2 +- .../contribs/github/workflows/pre-commit.yaml | 2 +- .../github/workflows/release-drafter.yaml | 2 +- .../contribs/github/workflows/run-struct.yaml | 4 +-- .../contribs/github/workflows/stale.yaml | 2 +- struct_module/contribs/helm-chart.yaml | 2 +- .../contribs/kubernetes-manifests.yaml | 2 +- struct_module/contribs/project/generic.yaml | 2 +- struct_module/contribs/project/go.yaml | 2 +- struct_module/contribs/project/java.yaml | 2 +- struct_module/contribs/project/nodejs.yaml | 2 +- struct_module/contribs/project/python.yaml | 2 +- struct_module/contribs/project/ruby.yaml | 2 +- struct_module/contribs/project/rust.yaml | 2 +- .../contribs/terraform/apps/generic.yaml | 2 +- .../terraform/apps/github-organization.yaml | 2 +- .../contribs/terraform/modules/generic.yaml | 2 +- struct_module/contribs/vagrant-files.yaml | 2 +- 44 files changed, 83 insertions(+), 53 deletions(-) diff --git a/README.es.md b/README.es.md index 2837bd3..251e8d8 100644 --- a/README.es.md +++ b/README.es.md @@ -138,7 +138,7 @@ struct generate \ Aquí tienes un ejemplo de un archivo de configuración YAML: ```yaml -structure: +files: - README.md: content: | # {{@ project_name @}} @@ -223,7 +223,7 @@ como puedes ver, cada variable debe tener una descripción, un tipo y un valor p Este filtro obtiene la versión más reciente de una release en un repositorio de GitHub. Toma el nombre del repositorio como argumento. ```yaml -structure: +files: - README.md: content: | # MyProject @@ -241,7 +241,7 @@ NOTA: puedes usar este filtro para obtener la última versión de un proveedor d Este filtro convierte una cadena en un slug. Toma un argumento opcional para especificar el carácter separador (el valor predeterminado es `-`). ```yaml -structure: +files: - README.md: content: | # {{@ project_name @}} @@ -254,7 +254,7 @@ structure: Este filtro obtiene el nombre de la rama predeterminada de un repositorio de GitHub. Toma el nombre del repositorio como argumento. ```yaml -structure: +files: - README.md: content: | # MyProject diff --git a/README.md b/README.md index b19ec25..3377a43 100644 --- a/README.md +++ b/README.md @@ -143,7 +143,7 @@ When defining your project structure in the YAML configuration file, you can use Example: ```yaml -structure: +files: - README.md: skip: true content: | @@ -232,7 +232,7 @@ as you can see, the `author_name` variable is defined on the `variables` section This filter fetches the latest release version of a GitHub repository. It takes the repository name as an argument. ```yaml -structure: +files: - README.md: content: | # MyProject @@ -250,7 +250,7 @@ NOTE: you can use this filter to get the latest release for a terraform provider This filter converts a string into a slug. It takes an optional argument to specify the separator character (default is `-`). ```yaml -structure: +files: - README.md: content: | # {{@ project_name @}} @@ -263,7 +263,7 @@ structure: This filter fetches the default branch name of a GitHub repository. It takes the repository name as an argument. ```yaml -structure: +files: - README.md: content: | # MyProject diff --git a/example/structure.yaml b/example/structure.yaml index d9cd8c4..0823056 100644 --- a/example/structure.yaml +++ b/example/structure.yaml @@ -1,4 +1,4 @@ -structure: +files: - README.md: skip: true content: | diff --git a/struct-schema.json b/struct-schema.json index a00c070..b6f4051 100644 --- a/struct-schema.json +++ b/struct-schema.json @@ -1,5 +1,5 @@ { - "$schema": "http://json-schema.org/draft-07/schema#", + "$schema": "https://json-schema.org/draft-07/schema", "type": "object", "properties": { "structure": { @@ -21,6 +21,36 @@ } } }, + "files": { + "type": "array", + "items": { + "type": "object", + "patternProperties": { + ".*": { + "type": "object", + "properties": { + "skip": { + "type": "boolean" + }, + "skip_if_exists": { + "type": "boolean" + }, + "content": { + "type": "string" + }, + "permissions": { + "type": "string" + }, + "file": { + "type": "string", + "format": "uri" + } + }, + "additionalProperties": false + } + } + } + }, "folders": { "type": "array", "items": { diff --git a/struct_module/commands/generate.py b/struct_module/commands/generate.py index 005083b..1cc7894 100644 --- a/struct_module/commands/generate.py +++ b/struct_module/commands/generate.py @@ -63,7 +63,7 @@ def _create_structure(self, args): config = yaml.safe_load(f) template_vars = dict(item.split('=') for item in args.vars.split(',')) if args.vars else None - config_structure = config.get('structure', []) + config_structure = config.get('structure', config.get('files', [])) config_folders = config.get('folders', []) config_variables = config.get('variables', []) diff --git a/struct_module/commands/info.py b/struct_module/commands/info.py index 6dbafc5..b060d10 100644 --- a/struct_module/commands/info.py +++ b/struct_module/commands/info.py @@ -38,9 +38,9 @@ def _get_info(self, args): print(f" 📌 Name: {args.structure_definition}\n") print(f" 📌 Description: {config.get('description', 'No description')}\n") - if config.get('structure'): - print(f" 📌 Structure:") - for item in config.get('structure', []): + if config.get('files'): + print(f" 📌 Files:") + for item in config.get('files', []): for name, content in item.items(): print(f" - {name} ") # indent all lines of content diff --git a/struct_module/commands/validate.py b/struct_module/commands/validate.py index 4c3ef5e..f4139fc 100644 --- a/struct_module/commands/validate.py +++ b/struct_module/commands/validate.py @@ -18,7 +18,7 @@ def execute(self, args): with open(args.yaml_file, 'r') as f: config = yaml.safe_load(f) - self._validate_structure_config(config.get('structure', [])) + self._validate_structure_config(config.get('structure', config.get('files', []))) self._validate_folders_config(config.get('folders', [])) self._validate_variables_config(config.get('variables', [])) diff --git a/struct_module/contribs/ansible-playbook.yaml b/struct_module/contribs/ansible-playbook.yaml index 916b77f..e81c944 100644 --- a/struct_module/contribs/ansible-playbook.yaml +++ b/struct_module/contribs/ansible-playbook.yaml @@ -1,4 +1,4 @@ -structure: +files: - main.yml: content: | - name: Example Playbook diff --git a/struct_module/contribs/chef-cookbook.yaml b/struct_module/contribs/chef-cookbook.yaml index 6d8ae8e..d22c368 100644 --- a/struct_module/contribs/chef-cookbook.yaml +++ b/struct_module/contribs/chef-cookbook.yaml @@ -1,4 +1,4 @@ -structure: +files: - recipes/default.rb: content: | package 'nginx' do diff --git a/struct_module/contribs/ci-cd-pipelines.yaml b/struct_module/contribs/ci-cd-pipelines.yaml index 631a50b..ee9f322 100644 --- a/struct_module/contribs/ci-cd-pipelines.yaml +++ b/struct_module/contribs/ci-cd-pipelines.yaml @@ -1,4 +1,4 @@ -structure: +files: - .gitlab-ci.yml: content: | stages: diff --git a/struct_module/contribs/cloudformation-files.yaml b/struct_module/contribs/cloudformation-files.yaml index b54a342..04e7436 100644 --- a/struct_module/contribs/cloudformation-files.yaml +++ b/struct_module/contribs/cloudformation-files.yaml @@ -1,4 +1,4 @@ -structure: +files: - template.yaml: content: | Resources: diff --git a/struct_module/contribs/configs/codeowners.yaml b/struct_module/contribs/configs/codeowners.yaml index 9c36ab2..1a36c98 100644 --- a/struct_module/contribs/configs/codeowners.yaml +++ b/struct_module/contribs/configs/codeowners.yaml @@ -1,3 +1,3 @@ -structure: +files: - CODEOWNERS: | * @github_username diff --git a/struct_module/contribs/configs/devcontainer.yaml b/struct_module/contribs/configs/devcontainer.yaml index c76dd6f..c5997d8 100644 --- a/struct_module/contribs/configs/devcontainer.yaml +++ b/struct_module/contribs/configs/devcontainer.yaml @@ -1,4 +1,4 @@ -structure: +files: - .devcontainer/devcontainer.json: content: | // For format details, see https://aka.ms/devcontainer.json. For config options, see the diff --git a/struct_module/contribs/configs/editor-config.yaml b/struct_module/contribs/configs/editor-config.yaml index 0537958..a120c3f 100644 --- a/struct_module/contribs/configs/editor-config.yaml +++ b/struct_module/contribs/configs/editor-config.yaml @@ -1,4 +1,4 @@ -structure: +files: - .editorconfig: content: | root = true diff --git a/struct_module/contribs/configs/eslint.yaml b/struct_module/contribs/configs/eslint.yaml index 18ca90e..867b3a7 100644 --- a/struct_module/contribs/configs/eslint.yaml +++ b/struct_module/contribs/configs/eslint.yaml @@ -1,4 +1,4 @@ -structure: +files: - .eslintrc.json: content: | { diff --git a/struct_module/contribs/configs/jshint.yaml b/struct_module/contribs/configs/jshint.yaml index 24eca84..5caa0be 100644 --- a/struct_module/contribs/configs/jshint.yaml +++ b/struct_module/contribs/configs/jshint.yaml @@ -1,4 +1,4 @@ -structure: +files: - .jshintrc: content: | { diff --git a/struct_module/contribs/configs/prettier.yaml b/struct_module/contribs/configs/prettier.yaml index ad6027c..f311fb0 100644 --- a/struct_module/contribs/configs/prettier.yaml +++ b/struct_module/contribs/configs/prettier.yaml @@ -1,4 +1,4 @@ -structure: +files: - .prettierrc: content: | { diff --git a/struct_module/contribs/docker-files.yaml b/struct_module/contribs/docker-files.yaml index d0ebee0..e8113aa 100644 --- a/struct_module/contribs/docker-files.yaml +++ b/struct_module/contribs/docker-files.yaml @@ -1,4 +1,4 @@ -structure: +files: - Dockerfile: content: | FROM nginx:latest diff --git a/struct_module/contribs/documentation-template.yaml b/struct_module/contribs/documentation-template.yaml index 7263410..6042779 100644 --- a/struct_module/contribs/documentation-template.yaml +++ b/struct_module/contribs/documentation-template.yaml @@ -1,4 +1,4 @@ -structure: +files: - README.md: content: | # {{@ project_name @}} diff --git a/struct_module/contribs/git-hooks.yaml b/struct_module/contribs/git-hooks.yaml index 7389cd5..4433ffe 100644 --- a/struct_module/contribs/git-hooks.yaml +++ b/struct_module/contribs/git-hooks.yaml @@ -1,4 +1,4 @@ -structure: +files: - .git/hooks/pre-commit: permissions: 755 content: | diff --git a/struct_module/contribs/github/prompts/generic.yaml b/struct_module/contribs/github/prompts/generic.yaml index 9dbc734..5bcf366 100644 --- a/struct_module/contribs/github/prompts/generic.yaml +++ b/struct_module/contribs/github/prompts/generic.yaml @@ -1,4 +1,4 @@ -structure: +files: - .github/prompts/generic.prompt.md: content: | Your prompt here diff --git a/struct_module/contribs/github/prompts/react-form.yaml b/struct_module/contribs/github/prompts/react-form.yaml index 2c6f0a6..eafc061 100644 --- a/struct_module/contribs/github/prompts/react-form.yaml +++ b/struct_module/contribs/github/prompts/react-form.yaml @@ -1,4 +1,4 @@ -structure: +files: - .github/prompts/react-form.prompt.md: content: | Your goal is to generate a new React form component. diff --git a/struct_module/contribs/github/prompts/security-api.yaml b/struct_module/contribs/github/prompts/security-api.yaml index 417b232..cb29120 100644 --- a/struct_module/contribs/github/prompts/security-api.yaml +++ b/struct_module/contribs/github/prompts/security-api.yaml @@ -1,4 +1,4 @@ -structure: +files: - .github/prompts/security-api.prompt.md: content: | Secure REST API review: diff --git a/struct_module/contribs/github/prompts/struct.yaml b/struct_module/contribs/github/prompts/struct.yaml index 99a3510..1a1f131 100644 --- a/struct_module/contribs/github/prompts/struct.yaml +++ b/struct_module/contribs/github/prompts/struct.yaml @@ -1,4 +1,4 @@ -structure: +files: - .github/prompts/struct.prompt.md: content: | # Struct Assistant diff --git a/struct_module/contribs/github/templates.yaml b/struct_module/contribs/github/templates.yaml index dec57da..31b927a 100644 --- a/struct_module/contribs/github/templates.yaml +++ b/struct_module/contribs/github/templates.yaml @@ -1,4 +1,4 @@ -structure: +files: - .github/PULL_REQUEST_TEMPLATE/bug_fix_template.md: content: | ## Bug Fix diff --git a/struct_module/contribs/github/workflows/execute-tf-workflow.yaml b/struct_module/contribs/github/workflows/execute-tf-workflow.yaml index f9b524c..34147da 100644 --- a/struct_module/contribs/github/workflows/execute-tf-workflow.yaml +++ b/struct_module/contribs/github/workflows/execute-tf-workflow.yaml @@ -1,4 +1,4 @@ -structure: +files: - .github/workflows/execute-tf-{{@ app_name | slugify @}}.yaml: content: | name: 'execute-tf-{{@ app_name | slugify @}}' diff --git a/struct_module/contribs/github/workflows/labeler.yaml b/struct_module/contribs/github/workflows/labeler.yaml index 7896ac4..95f3b24 100644 --- a/struct_module/contribs/github/workflows/labeler.yaml +++ b/struct_module/contribs/github/workflows/labeler.yaml @@ -1,4 +1,4 @@ -structure: +files: - .github/labeler.yml: content: | # Add 'root' label to any root file changes diff --git a/struct_module/contribs/github/workflows/pre-commit.yaml b/struct_module/contribs/github/workflows/pre-commit.yaml index 6856577..2c884a7 100644 --- a/struct_module/contribs/github/workflows/pre-commit.yaml +++ b/struct_module/contribs/github/workflows/pre-commit.yaml @@ -1,4 +1,4 @@ -structure: +files: - .github/workflows/z-pre-commit.yaml: content: | name: z-pre-commit diff --git a/struct_module/contribs/github/workflows/release-drafter.yaml b/struct_module/contribs/github/workflows/release-drafter.yaml index 2130cf2..2e0479c 100644 --- a/struct_module/contribs/github/workflows/release-drafter.yaml +++ b/struct_module/contribs/github/workflows/release-drafter.yaml @@ -1,4 +1,4 @@ -structure: +files: - .github/workflows/release-drafter.yaml: content: | name: release-drafter diff --git a/struct_module/contribs/github/workflows/run-struct.yaml b/struct_module/contribs/github/workflows/run-struct.yaml index e37f5bd..c0d36ae 100644 --- a/struct_module/contribs/github/workflows/run-struct.yaml +++ b/struct_module/contribs/github/workflows/run-struct.yaml @@ -1,4 +1,4 @@ -structure: +files: - .github/workflows/run-struct.yaml: skip_if_exists: true content: | @@ -18,7 +18,7 @@ structure: - .struct.yaml: skip_if_exists: true content: | - structure: + files: - README.md: content: | # Sample content diff --git a/struct_module/contribs/github/workflows/stale.yaml b/struct_module/contribs/github/workflows/stale.yaml index df87dff..2173d11 100644 --- a/struct_module/contribs/github/workflows/stale.yaml +++ b/struct_module/contribs/github/workflows/stale.yaml @@ -1,4 +1,4 @@ -structure: +files: - .github/workflows/stale.yaml: content: | name: 'stale' diff --git a/struct_module/contribs/helm-chart.yaml b/struct_module/contribs/helm-chart.yaml index 015f9ad..5d10370 100644 --- a/struct_module/contribs/helm-chart.yaml +++ b/struct_module/contribs/helm-chart.yaml @@ -1,4 +1,4 @@ -structure: +files: - Chart.yaml: content: | apiVersion: v2 diff --git a/struct_module/contribs/kubernetes-manifests.yaml b/struct_module/contribs/kubernetes-manifests.yaml index 01e6aa0..62d4e51 100644 --- a/struct_module/contribs/kubernetes-manifests.yaml +++ b/struct_module/contribs/kubernetes-manifests.yaml @@ -1,4 +1,4 @@ -structure: +files: - deployment.yaml: content: | apiVersion: apps/v1 diff --git a/struct_module/contribs/project/generic.yaml b/struct_module/contribs/project/generic.yaml index 909531c..b429beb 100644 --- a/struct_module/contribs/project/generic.yaml +++ b/struct_module/contribs/project/generic.yaml @@ -1,4 +1,4 @@ -structure: +files: - .config/REMOVE_ME.md: content: | # .config Folder diff --git a/struct_module/contribs/project/go.yaml b/struct_module/contribs/project/go.yaml index b0b8b77..d8ebb2e 100644 --- a/struct_module/contribs/project/go.yaml +++ b/struct_module/contribs/project/go.yaml @@ -1,4 +1,4 @@ -structure: +files: - .editorconfig: content: | # Editor configuration diff --git a/struct_module/contribs/project/java.yaml b/struct_module/contribs/project/java.yaml index 73160ba..3f5889f 100644 --- a/struct_module/contribs/project/java.yaml +++ b/struct_module/contribs/project/java.yaml @@ -1,4 +1,4 @@ -structure: +files: - .editorconfig: content: | # Editor configuration diff --git a/struct_module/contribs/project/nodejs.yaml b/struct_module/contribs/project/nodejs.yaml index c9964ad..5895d81 100644 --- a/struct_module/contribs/project/nodejs.yaml +++ b/struct_module/contribs/project/nodejs.yaml @@ -1,4 +1,4 @@ -structure: +files: - .editorconfig: content: | # Editor configuration diff --git a/struct_module/contribs/project/python.yaml b/struct_module/contribs/project/python.yaml index c866fe7..bed9323 100644 --- a/struct_module/contribs/project/python.yaml +++ b/struct_module/contribs/project/python.yaml @@ -1,4 +1,4 @@ -structure: +files: - .editorconfig: content: | # Editor configuration diff --git a/struct_module/contribs/project/ruby.yaml b/struct_module/contribs/project/ruby.yaml index 90e3153..16dc9e3 100644 --- a/struct_module/contribs/project/ruby.yaml +++ b/struct_module/contribs/project/ruby.yaml @@ -1,4 +1,4 @@ -structure: +files: - .editorconfig: content: | # Editor configuration diff --git a/struct_module/contribs/project/rust.yaml b/struct_module/contribs/project/rust.yaml index 1e19bad..2ba7eb3 100644 --- a/struct_module/contribs/project/rust.yaml +++ b/struct_module/contribs/project/rust.yaml @@ -1,4 +1,4 @@ -structure: +files: - .editorconfig: content: | # Editor configuration diff --git a/struct_module/contribs/terraform/apps/generic.yaml b/struct_module/contribs/terraform/apps/generic.yaml index 77b32c7..a4d712d 100644 --- a/struct_module/contribs/terraform/apps/generic.yaml +++ b/struct_module/contribs/terraform/apps/generic.yaml @@ -1,4 +1,4 @@ -structure: +files: - main.tf: content: | # This is the main Terraform app main file. diff --git a/struct_module/contribs/terraform/apps/github-organization.yaml b/struct_module/contribs/terraform/apps/github-organization.yaml index d7733e7..6d35233 100644 --- a/struct_module/contribs/terraform/apps/github-organization.yaml +++ b/struct_module/contribs/terraform/apps/github-organization.yaml @@ -1,4 +1,4 @@ -structure: +files: - providers.yaml: content: | provider "github" { diff --git a/struct_module/contribs/terraform/modules/generic.yaml b/struct_module/contribs/terraform/modules/generic.yaml index ceadc0e..3648eb1 100644 --- a/struct_module/contribs/terraform/modules/generic.yaml +++ b/struct_module/contribs/terraform/modules/generic.yaml @@ -1,4 +1,4 @@ -structure: +files: - main.tf: content: | resource "aws_instance" "example" { diff --git a/struct_module/contribs/vagrant-files.yaml b/struct_module/contribs/vagrant-files.yaml index f358060..a29f20e 100644 --- a/struct_module/contribs/vagrant-files.yaml +++ b/struct_module/contribs/vagrant-files.yaml @@ -1,4 +1,4 @@ -structure: +files: - Vagrantfile: content: | Vagrant.configure("2") do |config| From 7b9e7fb71c942182d005fd6caee57eeed83b7a81 Mon Sep 17 00:00:00 2001 From: Kenneth Belitzky Date: Thu, 8 May 2025 19:33:44 +0000 Subject: [PATCH 2/2] Refactor structure handling in configuration files to prioritize 'structure' key over 'files' key --- struct_module/commands/generate.py | 2 +- struct_module/commands/validate.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/struct_module/commands/generate.py b/struct_module/commands/generate.py index 1cc7894..a0f0c44 100644 --- a/struct_module/commands/generate.py +++ b/struct_module/commands/generate.py @@ -63,7 +63,7 @@ def _create_structure(self, args): config = yaml.safe_load(f) template_vars = dict(item.split('=') for item in args.vars.split(',')) if args.vars else None - config_structure = config.get('structure', config.get('files', [])) + config_structure = config.get('files', config.get('structure', [])) config_folders = config.get('folders', []) config_variables = config.get('variables', []) diff --git a/struct_module/commands/validate.py b/struct_module/commands/validate.py index f4139fc..0d7b59f 100644 --- a/struct_module/commands/validate.py +++ b/struct_module/commands/validate.py @@ -18,7 +18,9 @@ def execute(self, args): with open(args.yaml_file, 'r') as f: config = yaml.safe_load(f) - self._validate_structure_config(config.get('structure', config.get('files', []))) + if 'structure' in config and 'files' in config: + self.logger.warning("Both 'structure' and 'files' keys exist. Prioritizing 'structure'.") + self._validate_structure_config(config.get('structure') or config.get('files', [])) self._validate_folders_config(config.get('folders', [])) self._validate_variables_config(config.get('variables', []))