feat: use embedded filesystem for default files
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Glenn Y. Rolland 2024-01-04 23:14:14 +01:00
parent 97a05896a3
commit d39d597128
5 changed files with 26 additions and 28 deletions

View file

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

View file

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

View file

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

View file

@ -6,6 +6,7 @@ require "crinja"
require "./config"
require "./filelist"
require "./file_storage"
# The CodePreloader module organizes classes and methods related to preloading code files.
module CodePreloader
@ -40,35 +41,14 @@ module CodePreloader
abort("Unexpected nil value for init_options!") if init_options.nil?
# 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
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
config_content = [
"---",
"# 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")
# Content of the default .code_preloader.yml file
config_content = FileStorage.get("default_config.yml").gets_to_end
# Writing the configuration content to the file
File.write(config_path, config_content)
@ -116,8 +96,12 @@ module CodePreloader
filelist.reject { |path| !!(path =~ Regex.new(ignore_pattern)) }
end
abort("No prompt file defined!") if prompt_template_path.nil?
prompt_template_content = File.read(prompt_template_path)
STDERR.puts "Loading template file from: #{prompt_template_path ? prompt_template_path : "<internal>" }".colorize(:yellow)
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?

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