Compare commits

..

2 commits

Author SHA1 Message Date
d39d597128 feat: use embedded filesystem for default files
Some checks failed
continuous-integration/drone/push Build is failing
2024-01-04 23:14:14 +01:00
97a05896a3 feat: add defaults (template & config) as files 2024-01-04 23:03:21 +01:00
7 changed files with 66 additions and 28 deletions

View file

@ -17,5 +17,5 @@ output_path: null
prompt: prompt:
header_path: null header_path: null
footer_path: null footer_path: null
template_path: misc/templates/default.j2 template_path: null
# #

View file

@ -1,5 +1,9 @@
version: 2.0 version: 2.0
shards: shards:
baked_file_system:
git: https://github.com/schovi/baked_file_system.git
version: 0.10.0
crinja: crinja:
git: https://github.com/straight-shoota/crinja.git git: https://github.com/straight-shoota/crinja.git
version: 0.8.1 version: 0.8.1

View file

@ -18,6 +18,9 @@ dependencies:
github: alexherbo2/walk.cr github: alexherbo2/walk.cr
version_from_shard: version_from_shard:
github: hugopl/version_from_shard github: hugopl/version_from_shard
baked_file_system:
github: schovi/baked_file_system
version: 0.10.0
# completion: # completion:
# github: f/completion # github: f/completion

View file

@ -6,6 +6,7 @@ require "crinja"
require "./config" require "./config"
require "./filelist" require "./filelist"
require "./file_storage"
# The CodePreloader module organizes classes and methods related to preloading code files. # The CodePreloader module organizes classes and methods related to preloading code files.
module CodePreloader module CodePreloader
@ -40,35 +41,14 @@ module CodePreloader
abort("Unexpected nil value for init_options!") if init_options.nil? abort("Unexpected nil value for init_options!") if init_options.nil?
# Default path for the .code_preloader.yml file # Default path for the .code_preloader.yml file
default_config_path = "example.code_preloader.yml" default_config_path = ".code_preloader.yml"
# Use the specified path if provided, otherwise use the default # Use the specified path if provided, otherwise use the default
config_path = init_options.config_path || default_config_path config_path = init_options.config_path || default_config_path
abort("ERROR: configuration file already exist: #{config_path}") if File.exists? config_path
# Content of the .code_preloader.yml file # Content of the default .code_preloader.yml file
config_content = [ config_content = FileStorage.get("default_config.yml").gets_to_end
"---",
"# Example configuration for Code-Preloader",
"",
"# List of repository paths to preload",
"# source_list:",
"# - \"path/to/repo1\"",
"# - \"path/to/repo2\"",
"",
"# List of patterns to ignore during preloading",
"ignore_list:",
" - ^\\.git/.*",
"",
"# Path to the output file (if null, output to STDOUT)",
"output_path: null",
"",
"# Optional: Path to a file containing the header prompt",
"header_path: null",
"",
"# Optional: Path to a file containing the footer prompt",
"footer_path: null",
""
].join("\n")
# Writing the configuration content to the file # Writing the configuration content to the file
File.write(config_path, config_content) File.write(config_path, config_content)
@ -116,8 +96,12 @@ module CodePreloader
filelist.reject { |path| !!(path =~ Regex.new(ignore_pattern)) } filelist.reject { |path| !!(path =~ Regex.new(ignore_pattern)) }
end end
abort("No prompt file defined!") if prompt_template_path.nil? STDERR.puts "Loading template file from: #{prompt_template_path ? prompt_template_path : "<internal>" }".colorize(:yellow)
prompt_template_content = File.read(prompt_template_path) if prompt_template_path
prompt_template_content = File.read(prompt_template_path)
else
prompt_template_content = FileStorage.get("default_template.j2").gets_to_end
end
if !prompt_header_path.nil? if !prompt_header_path.nil?

7
src/file_storage.cr Normal file
View file

@ -0,0 +1,7 @@
require "baked_file_system"
class FileStorage
extend BakedFileSystem
bake_folder "../static"
end

24
static/default_config.yml Normal file
View file

@ -0,0 +1,24 @@
---
# Example configuration for Code-Preloader
# List of repository paths to preload
# source_list:
# - "path/to/repo1"
# - "path/to/repo2"
# List of patterns to ignore during preloading
ignore_list:
- ^\.git/.*
# Path to the output file (if null, output to STDOUT)
output_path: null
prompt:
# Optional: Path to a file containing the prompt header
header_path: null
# Optional: Path to a file containing the prompt footer
footer_path: null
# Optional: Path to a file container a jinja template to structure the prompt
template_path: null

View file

@ -0,0 +1,16 @@
{%- if prompt_header -%}
@@ CONTEXT
{{ prompt_header }}
{%- endif -%}
{%- for file in prompt_files -%}
@@ FILE "{{ file.path }}" WITH MIME-TYPE "{{ file.mime_type }}"
{{- file.content -}}
{%- endfor -%}
{%- if prompt_footer -%}
@@ REQUEST
{{ prompt_footer }}
{%- endif -%}