diff --git a/.code_preloader.yml b/.code_preloader.yml index 6849a86..cd65b58 100644 --- a/.code_preloader.yml +++ b/.code_preloader.yml @@ -17,5 +17,5 @@ output_path: null prompt: header_path: null footer_path: null - template_path: misc/templates/default.j2 + template_path: null # diff --git a/shard.lock b/shard.lock index 1ed4af1..a496054 100644 --- a/shard.lock +++ b/shard.lock @@ -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 diff --git a/shard.yml b/shard.yml index a74f463..7b79ff7 100644 --- a/shard.yml +++ b/shard.yml @@ -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 diff --git a/src/cli.cr b/src/cli.cr index d94450a..af8c431 100644 --- a/src/cli.cr +++ b/src/cli.cr @@ -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 : "" }".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? diff --git a/src/file_storage.cr b/src/file_storage.cr new file mode 100644 index 0000000..2cf3c1f --- /dev/null +++ b/src/file_storage.cr @@ -0,0 +1,7 @@ +require "baked_file_system" + +class FileStorage + extend BakedFileSystem + + bake_folder "../static" +end