@repokit/core 4.0.5 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/README.md +17 -4
  2. package/dist/types.d.mts +1 -1
  3. package/externals/TSCompiler.ts +1 -2
  4. package/externals/types.ts +1 -1
  5. package/package.json +29 -20
  6. package/Cargo.lock +0 -1609
  7. package/Cargo.toml +0 -23
  8. package/installation/install.sh +0 -99
  9. package/internals/argv/argv.rs +0 -132
  10. package/internals/argv/mod.rs +0 -1
  11. package/internals/caches/crawl_cache.rs +0 -126
  12. package/internals/caches/file_cache.rs +0 -104
  13. package/internals/caches/mod.rs +0 -6
  14. package/internals/caches/old_cache.rs +0 -35
  15. package/internals/caches/repokit_version_resolver.rs +0 -50
  16. package/internals/caches/settings_cache.rs +0 -73
  17. package/internals/caches/version_cache.rs +0 -142
  18. package/internals/context/cache_scope.rs +0 -71
  19. package/internals/context/file_system.rs +0 -66
  20. package/internals/context/git_scope.rs +0 -55
  21. package/internals/context/mod.rs +0 -5
  22. package/internals/context/node_scope.rs +0 -133
  23. package/internals/context/typescript_bridge.rs +0 -84
  24. package/internals/executables/internal_executable.rs +0 -15
  25. package/internals/executables/internal_executable_definition.rs +0 -40
  26. package/internals/executables/mod.rs +0 -2
  27. package/internals/executor/executor.rs +0 -88
  28. package/internals/executor/mod.rs +0 -1
  29. package/internals/file_walker/file_walker.rs +0 -69
  30. package/internals/file_walker/mod.rs +0 -2
  31. package/internals/file_walker/walker.rs +0 -114
  32. package/internals/internal_commands/help.rs +0 -174
  33. package/internals/internal_commands/internal_registry.rs +0 -34
  34. package/internals/internal_commands/list_commands.rs +0 -97
  35. package/internals/internal_commands/list_owners.rs +0 -61
  36. package/internals/internal_commands/list_themes.rs +0 -114
  37. package/internals/internal_commands/list_version.rs +0 -59
  38. package/internals/internal_commands/locate_command.rs +0 -77
  39. package/internals/internal_commands/mod.rs +0 -11
  40. package/internals/internal_commands/onboarder.rs +0 -60
  41. package/internals/internal_commands/register_command.rs +0 -99
  42. package/internals/internal_commands/search_commands.rs +0 -201
  43. package/internals/internal_commands/upgrade_repokit.rs +0 -71
  44. package/internals/internal_filesystem/file_builder.rs +0 -56
  45. package/internals/internal_filesystem/mod.rs +0 -1
  46. package/internals/logger/logger.rs +0 -163
  47. package/internals/logger/mod.rs +0 -1
  48. package/internals/main.rs +0 -23
  49. package/internals/post_processing/mod.rs +0 -1
  50. package/internals/post_processing/post_processor.rs +0 -37
  51. package/internals/repokit/command_definition.rs +0 -11
  52. package/internals/repokit/mod.rs +0 -6
  53. package/internals/repokit/repokit.rs +0 -146
  54. package/internals/repokit/repokit_command.rs +0 -101
  55. package/internals/repokit/repokit_config.rs +0 -101
  56. package/internals/repokit/repokit_construct_validator.rs +0 -11
  57. package/internals/repokit/repokit_runtime.rs +0 -43
  58. package/internals/themes/built_in_themes/mod.rs +0 -3
  59. package/internals/themes/built_in_themes/money.rs +0 -41
  60. package/internals/themes/built_in_themes/seeing_red.rs +0 -41
  61. package/internals/themes/built_in_themes/the_blues.rs +0 -41
  62. package/internals/themes/mod.rs +0 -5
  63. package/internals/themes/theme.rs +0 -108
  64. package/internals/themes/theme_colors.rs +0 -32
  65. package/internals/themes/theme_inputs.rs +0 -35
  66. package/internals/themes/theme_registry.rs +0 -123
  67. package/internals/validations/command_validations.rs +0 -127
  68. package/internals/validations/mod.rs +0 -1
@@ -1,56 +0,0 @@
1
- use std::{
2
- fs::{File, create_dir_all},
3
- io::{Error, copy},
4
- path::Path,
5
- };
6
-
7
- pub struct FileBuilder;
8
-
9
- impl FileBuilder {
10
- pub fn open<P: AsRef<Path>>(source: P, on_error: impl Fn(Error)) -> File {
11
- let source = File::open(source);
12
- match source {
13
- Ok(file) => file,
14
- Err(error) => {
15
- on_error(error);
16
- panic!();
17
- }
18
- }
19
- }
20
-
21
- pub fn create(destination: &Path, on_error: impl Fn(Error)) -> File {
22
- let source = File::create(destination);
23
- match source {
24
- Ok(file) => file,
25
- Err(error) => {
26
- on_error(error);
27
- panic!();
28
- }
29
- }
30
- }
31
-
32
- pub fn copy_to(source: &mut File, target: &mut File, on_error: impl Fn(Error)) {
33
- let result = copy(source, target);
34
- match result {
35
- Ok(_) => {
36
- let sync = target.sync_all();
37
- match sync {
38
- Ok(_) => {}
39
- Err(err) => on_error(err),
40
- }
41
- }
42
- Err(err) => on_error(err),
43
- }
44
- }
45
-
46
- pub fn create_dir_all(path: &Path, on_error: impl Fn(Error)) {
47
- let source = create_dir_all(path);
48
- match source {
49
- Ok(result) => result,
50
- Err(error) => {
51
- on_error(error);
52
- panic!();
53
- }
54
- }
55
- }
56
- }
@@ -1 +0,0 @@
1
- pub mod file_builder;
@@ -1,163 +0,0 @@
1
- use core::panic;
2
- use std::sync::LazyLock;
3
- use std::sync::Mutex;
4
- use std::sync::MutexGuard;
5
-
6
- use colored::{ColoredString, Colorize};
7
-
8
- use crate::repokit::repokit_runtime::RepoKitRuntime;
9
- use crate::themes::theme::Theme;
10
- use crate::themes::theme_registry::ThemeRegistry;
11
-
12
- static REGISTERED_NAME: LazyLock<Mutex<String>> =
13
- LazyLock::new(|| Mutex::new("Repokit".to_string()));
14
-
15
- static THEMES: LazyLock<Mutex<ThemeRegistry>> = LazyLock::new(|| Mutex::new(ThemeRegistry::new()));
16
-
17
- pub struct Logger;
18
-
19
- impl Logger {
20
- pub fn initialize() {
21
- RepoKitRuntime::with_runtime(|runtime| {
22
- Logger::set_name(&runtime.configuration.project);
23
- for theme in &runtime.configuration.themes {
24
- Logger::with_registry(|mut registry| registry.register_user_theme(theme))
25
- }
26
- Logger::with_registry(|mut registry| {
27
- registry.set_theme(&runtime.caches.settings_cache.theme_preference)
28
- });
29
- });
30
- }
31
-
32
- pub fn info(message: &str) {
33
- println!("{}{}", Logger::info_prefix(), message);
34
- }
35
-
36
- pub fn error(message: &str) {
37
- eprintln!("{}{}", Logger::error_prefix(), message);
38
- }
39
-
40
- pub fn exit_with_info(message: &str) {
41
- Logger::info(message);
42
- panic!();
43
- }
44
-
45
- pub fn exit_with_error(message: &str) {
46
- Logger::error(message);
47
- panic!();
48
- }
49
-
50
- pub fn list(items: &[&str], indentation: Option<i32>) {
51
- Logger::with_surrounding_space(|| {
52
- for (index, item) in items.iter().enumerate() {
53
- println!("{}{}. {}", Logger::indent(indentation), index + 1, item);
54
- }
55
- })
56
- }
57
-
58
- pub fn parse_error(file_type: &str, stdout: &str) {
59
- Logger::info(format!("There was an error parsing your {}", file_type).as_str());
60
- Logger::info(
61
- "This can occur when RepoKit attempts to parse a TypeScript file that can terminate the process upon evaluation",
62
- );
63
- Logger::info("Please file a bug to with any related error or stack trace found below");
64
- Logger::log_issue_link();
65
- println!();
66
- if !stdout.is_empty() {
67
- println!("{stdout}");
68
- }
69
- panic!();
70
- }
71
-
72
- pub fn space_around(message: &str) {
73
- println!("\n{}{}\n", Logger::info_prefix(), message);
74
- }
75
-
76
- pub fn with_surrounding_space<F>(mut func: impl FnMut() -> F) -> F {
77
- println!();
78
- let result = func();
79
- println!();
80
- result
81
- }
82
-
83
- pub fn log_file_path(path: &str) {
84
- Logger::with_surrounding_space(|| {
85
- println!(
86
- "{}{}",
87
- Logger::indent(None),
88
- Logger::with_theme(|theme| theme.highlight(path))
89
- );
90
- })
91
- }
92
-
93
- pub fn list_file_paths(paths: &Vec<String>) {
94
- Logger::with_surrounding_space(|| {
95
- for path in paths {
96
- println!(
97
- "{}{}",
98
- Logger::indent(None),
99
- Logger::with_theme(|theme| theme.highlight(path))
100
- );
101
- }
102
- })
103
- }
104
-
105
- pub fn indent(times: Option<i32>) -> String {
106
- let indentation: i32 = times.unwrap_or(5);
107
- " ".repeat(indentation.try_into().unwrap())
108
- }
109
-
110
- pub fn cyan(message: &str) -> ColoredString {
111
- message.cyan()
112
- }
113
-
114
- pub fn file_create_error() {
115
- Logger::file_error("create a file");
116
- }
117
-
118
- pub fn file_directory_error() {
119
- Logger::file_error("create a directory");
120
- }
121
-
122
- pub fn open_file_error() {
123
- Logger::file_error("read a file");
124
- }
125
-
126
- pub fn file_write_error() {
127
- Logger::file_error("write to a file");
128
- }
129
-
130
- pub fn log_issue_link() {
131
- Logger::log_file_path("https://github.com/alexfigliolia/repokit/issues");
132
- }
133
-
134
- pub fn with_theme<R>(func: impl Fn(&Theme) -> R) -> R {
135
- Logger::with_registry(|registry| func(registry.current_theme()))
136
- }
137
-
138
- pub fn with_registry<R>(func: impl Fn(MutexGuard<'_, ThemeRegistry>) -> R) -> R {
139
- let registry = THEMES.lock().unwrap();
140
- func(registry)
141
- }
142
-
143
- fn file_error(operation: &str) {
144
- Logger::info(format!("I was unable to {operation} in your repository").as_str());
145
- Logger::error("Please verify the permissions on your working directory or file a bug here");
146
- Logger::log_issue_link();
147
- panic!();
148
- }
149
-
150
- fn info_prefix() -> String {
151
- Logger::with_theme(|theme| format!("{}: ", theme.prefix(&REGISTERED_NAME.lock().unwrap())))
152
- }
153
-
154
- fn error_prefix() -> String {
155
- Logger::with_theme(|theme| {
156
- format!("{}: ", theme.error_prefix(&REGISTERED_NAME.lock().unwrap()))
157
- })
158
- }
159
-
160
- fn set_name(value: &str) {
161
- *REGISTERED_NAME.lock().unwrap() = value.to_string();
162
- }
163
- }
@@ -1 +0,0 @@
1
- pub mod logger;
package/internals/main.rs DELETED
@@ -1,23 +0,0 @@
1
- use std::panic;
2
-
3
- use crate::{post_processing::post_processor::PostProcessor, repokit::repokit::RepoKit};
4
-
5
- mod argv;
6
- mod caches;
7
- mod context;
8
- mod executables;
9
- mod executor;
10
- mod file_walker;
11
- mod internal_commands;
12
- mod internal_filesystem;
13
- mod logger;
14
- mod post_processing;
15
- mod repokit;
16
- mod themes;
17
- mod validations;
18
-
19
- fn main() {
20
- panic::set_hook(Box::new(|_| PostProcessor::get().flush()));
21
- RepoKit::new().invoke();
22
- PostProcessor::get().flush();
23
- }
@@ -1 +0,0 @@
1
- pub mod post_processor;
@@ -1,37 +0,0 @@
1
- use std::{
2
- process::exit,
3
- sync::{LazyLock, Mutex, MutexGuard},
4
- };
5
-
6
- pub struct PostProcessor {
7
- tasks: Vec<Box<dyn Fn() + Send + 'static>>,
8
- }
9
-
10
- impl PostProcessor {
11
- pub fn new() -> Self {
12
- PostProcessor { tasks: Vec::new() }
13
- }
14
-
15
- pub fn get() -> MutexGuard<'static, PostProcessor> {
16
- REPOKIT_POST_PROCESSOR.lock().unwrap()
17
- }
18
-
19
- pub fn register_task<F>(&mut self, task: F)
20
- where
21
- F: Fn() + Send + 'static,
22
- {
23
- self.tasks.push(Box::new(task));
24
- }
25
-
26
- pub fn flush(&mut self) {
27
- for task in self.tasks.iter() {
28
- task();
29
- }
30
- self.tasks.clear();
31
- self.tasks.shrink_to_fit();
32
- exit(0);
33
- }
34
- }
35
-
36
- static REPOKIT_POST_PROCESSOR: LazyLock<Mutex<PostProcessor>> =
37
- LazyLock::new(|| Mutex::new(PostProcessor::new()));
@@ -1,11 +0,0 @@
1
- use std::collections::HashMap;
2
-
3
- use schemars::JsonSchema;
4
- use serde::Deserialize;
5
-
6
- #[derive(Debug, Deserialize, Clone, JsonSchema)]
7
- pub struct CommandDefinition {
8
- pub command: String,
9
- pub description: String,
10
- pub args: Option<HashMap<String, String>>,
11
- }
@@ -1,6 +0,0 @@
1
- pub mod command_definition;
2
- pub mod repokit;
3
- pub mod repokit_command;
4
- pub mod repokit_config;
5
- pub mod repokit_construct_validator;
6
- pub mod repokit_runtime;
@@ -1,146 +0,0 @@
1
- use std::{collections::HashMap, env::args, path::Path};
2
-
3
- use crate::{
4
- executables::internal_executable::InternalExecutable,
5
- executor::executor::Executor,
6
- internal_commands::help::Help,
7
- logger::logger::Logger,
8
- repokit::{repokit_command::RepoKitCommand, repokit_runtime::RepoKitRuntime},
9
- validations::command_validations::CommandValidations,
10
- };
11
-
12
- pub struct RepoKit {}
13
-
14
- impl RepoKit {
15
- pub fn new() -> RepoKit {
16
- Logger::initialize();
17
- RepoKit {}
18
- }
19
-
20
- pub fn invoke(&self) {
21
- let (command, args) = self.parse();
22
- let internals = CommandValidations::collect_and_validate_internals();
23
- if let Some(internal_command) = internals.get(&command) {
24
- return internal_command.run(args, &internals);
25
- }
26
- RepoKitRuntime::with_runtime(|runtime| {
27
- if let Some(root_script) = runtime.configuration.commands.get(&command) {
28
- Executor::with_stdio(
29
- format!("{} {}", root_script.command, &args.join(" ")),
30
- |cmd| cmd.current_dir(&runtime.files.git_root_path),
31
- );
32
- panic!();
33
- }
34
- });
35
- let externals = CommandValidations::collect_and_validate_externals();
36
- CommandValidations::detect_collisions_between_internals_and_externals(
37
- &internals, &externals,
38
- );
39
- if let Some(interface) = externals.get(&command) {
40
- if args.is_empty() {
41
- return self.log_external_command(interface);
42
- }
43
- let sub_command = &args[0];
44
- if let Some(script) = interface.commands.get(sub_command) {
45
- let executable = format!("{} {}", &script.command, &args[1..].join(" "));
46
- if let Some(working_dir) = Path::new(&interface.location).parent() {
47
- return Executor::with_stdio(executable, |cmd| cmd.current_dir(working_dir));
48
- }
49
- return self.working_directory_not_found(interface, &executable);
50
- }
51
- return self.subcommand_not_found(interface, sub_command);
52
- }
53
- self.command_not_found(&command, &internals, &externals)
54
- }
55
-
56
- fn parse(&self) -> (String, Vec<String>) {
57
- let argv: Vec<String> = args().collect();
58
- if argv.len() < 2 {
59
- let (internals, externals) = self.collect_and_validate();
60
- Help::list_all(&internals, &externals);
61
- panic!();
62
- }
63
- let command = &argv[1];
64
- let args = &(&argv)[2..];
65
- (command.clone(), args.to_vec())
66
- }
67
-
68
- fn collect_and_validate(
69
- &self,
70
- ) -> (
71
- HashMap<String, Box<dyn InternalExecutable>>,
72
- HashMap<String, RepoKitCommand>,
73
- ) {
74
- let internals = CommandValidations::collect_and_validate_internals();
75
- let externals = CommandValidations::collect_and_validate_externals();
76
- CommandValidations::detect_collisions_between_internals_and_externals(
77
- &internals, &externals,
78
- );
79
- (internals, externals)
80
- }
81
-
82
- fn command_not_found(
83
- &self,
84
- command: &str,
85
- internals: &HashMap<String, Box<dyn InternalExecutable>>,
86
- externals: &HashMap<String, RepoKitCommand>,
87
- ) {
88
- Help::list_all(internals, externals);
89
- Logger::info(
90
- format!(
91
- "I'm not aware of a command named {}",
92
- Logger::with_theme(|theme| theme.highlight(command))
93
- )
94
- .as_str(),
95
- );
96
- }
97
-
98
- fn subcommand_not_found(&self, command: &RepoKitCommand, sub_command: &str) {
99
- Logger::info(
100
- format!(
101
- "The command {} was not found on {}",
102
- Logger::with_theme(|theme| theme.highlight(sub_command)),
103
- Logger::with_theme(|theme| theme.highlight(&command.name))
104
- )
105
- .as_str(),
106
- );
107
- Logger::info(
108
- format!(
109
- "Here are the commands that belong to {}",
110
- Logger::with_theme(|theme| theme.highlight(&command.name))
111
- )
112
- .as_str(),
113
- );
114
- Help::log_external_subcommands(&command.commands, 3);
115
- }
116
-
117
- fn log_external_command(&self, command: &RepoKitCommand) {
118
- Logger::info(
119
- format!(
120
- "Listing available commands for {}\n",
121
- Logger::with_theme(|theme| theme.command(&command.name))
122
- )
123
- .as_str(),
124
- );
125
- Help::log_external_subcommands(&command.commands, 3);
126
- println!();
127
- }
128
-
129
- fn working_directory_not_found(&self, interface: &RepoKitCommand, executable: &str) {
130
- Logger::info("I was unable to determine the working directory for this command");
131
- Logger::info(
132
- format!(
133
- "This typically indicates a bug within {}",
134
- Logger::with_theme(|theme| theme.highlight("Repokit"))
135
- )
136
- .as_str(),
137
- );
138
- Logger::info("Please file an issue at");
139
- Logger::log_issue_link();
140
- Logger::info("To run this command from your terminal, you can run:");
141
- Logger::log_file_path(executable);
142
- Logger::info("From the parent directory of");
143
- Logger::log_file_path(&interface.location);
144
- panic!();
145
- }
146
- }
@@ -1,101 +0,0 @@
1
- use std::{collections::HashMap, sync::LazyLock};
2
-
3
- use jsonschema::Validator;
4
- use schemars::JsonSchema;
5
- use serde::Deserialize;
6
- use serde_json::{Value, from_value, to_value};
7
-
8
- use crate::{
9
- logger::logger::Logger,
10
- post_processing::post_processor::PostProcessor,
11
- repokit::{
12
- command_definition::CommandDefinition,
13
- repokit_construct_validator::RepoKitConstructValidator, repokit_runtime::RepoKitRuntime,
14
- },
15
- };
16
-
17
- #[derive(Debug, Deserialize, Clone, JsonSchema)]
18
- pub struct RepoKitCommand {
19
- pub name: String,
20
- pub owner: String,
21
- pub location: String,
22
- pub description: String,
23
- pub commands: HashMap<String, CommandDefinition>,
24
- }
25
-
26
- static REPOKIT_COMMAND_VALIDATOR: LazyLock<Validator> = LazyLock::new(|| {
27
- Validator::new(&to_value(schemars::schema_for!(RepoKitCommand)).unwrap()).unwrap()
28
- });
29
-
30
- impl RepoKitConstructValidator for RepoKitCommand {}
31
-
32
- impl RepoKitCommand {
33
- pub fn from_input(input: Vec<Value>) -> Vec<RepoKitCommand> {
34
- let mut result: Vec<RepoKitCommand> = Vec::new();
35
- let mut failures = 0;
36
- let mut failed_paths: Vec<String> = Vec::new();
37
- let git_root = RepoKitRuntime::with_runtime(|runtime| runtime.git.root.clone());
38
- for command in input {
39
- let repokit_command: Result<RepoKitCommand, serde_json::Error> =
40
- from_value(command.clone());
41
- if !RepoKitCommand::is_valid(&REPOKIT_COMMAND_VALIDATOR, &command)
42
- || repokit_command.is_err()
43
- {
44
- failures += 1;
45
- if let Some(path) = RepoKitCommand::on_parsing_error(command) {
46
- failed_paths.push(path);
47
- }
48
- } else {
49
- let mut valid_command = repokit_command.expect("parse success");
50
- valid_command.location = format!("{}/{}", git_root, valid_command.location);
51
- result.push(valid_command);
52
- }
53
- }
54
- if failures != 0 {
55
- RepoKitCommand::register_encountered_errors(failed_paths);
56
- }
57
- result
58
- }
59
-
60
- pub fn on_parsing_error(command: Value) -> Option<String> {
61
- let location = command.get("location");
62
- println!();
63
- if location.is_some_and(|v| v.is_string()) {
64
- let path = RepoKitRuntime::with_runtime(|runtime| {
65
- format!(
66
- "{}/{}",
67
- runtime.git.root,
68
- location.unwrap().as_str().unwrap()
69
- )
70
- });
71
- return Some(path);
72
- }
73
- None
74
- }
75
-
76
- fn register_encountered_errors(failed_paths: Vec<String>) {
77
- PostProcessor::get().register_task(move || {
78
- println!();
79
- if !failed_paths.is_empty() {
80
- let appendage = if failed_paths.len() != 1 { "s" } else { "" };
81
- Logger::error(
82
- format!(
83
- "I encountered an error in the following command{}",
84
- appendage
85
- )
86
- .as_str(),
87
- );
88
- Logger::list_file_paths(&failed_paths);
89
- } else {
90
- Logger::info("There was an error parsing one or more of your commands");
91
- }
92
- Logger::info("You can validate a command file's syntactical correctness by running");
93
- let type_check_command = RepoKitRuntime::with_runtime(|mut runtime| {
94
- runtime
95
- .node
96
- .get_typecheck_command("<optional-path-to-file>")
97
- });
98
- Logger::log_file_path(&type_check_command);
99
- });
100
- }
101
- }
@@ -1,101 +0,0 @@
1
- use core::panic;
2
- use jsonschema::Validator;
3
- use schemars::JsonSchema;
4
- use serde::Deserialize;
5
- use serde_json::{Value, from_value, to_value};
6
- use std::{collections::HashMap, path::Path, sync::LazyLock};
7
-
8
- use crate::{
9
- context::{file_system::FileSystem, node_scope::NodeScope},
10
- internal_filesystem::file_builder::FileBuilder,
11
- logger::logger::Logger,
12
- repokit::{
13
- command_definition::CommandDefinition, repokit_command::RepoKitCommand,
14
- repokit_construct_validator::RepoKitConstructValidator,
15
- },
16
- themes::theme_inputs::RepoKitTheme,
17
- };
18
-
19
- #[derive(Debug, Deserialize, Clone, JsonSchema)]
20
- pub struct RootCommand {
21
- pub name: String,
22
- pub command: String,
23
- pub description: String,
24
- pub args: Option<HashMap<String, String>>,
25
- }
26
-
27
- impl RootCommand {
28
- pub fn from(name: &str, command: &CommandDefinition) -> RootCommand {
29
- RootCommand {
30
- name: name.to_string(),
31
- args: command.args.clone(),
32
- command: command.command.to_string(),
33
- description: command.description.to_string(),
34
- }
35
- }
36
- }
37
-
38
- #[derive(Debug, Deserialize, Clone, JsonSchema)]
39
- pub struct RepoKitConfig {
40
- pub project: String,
41
- pub thirdParty: Vec<RepoKitCommand>,
42
- pub commands: HashMap<String, CommandDefinition>,
43
- pub themes: Vec<RepoKitTheme>,
44
- }
45
-
46
- static REPOKIT_CONFIG_VALIDATOR: LazyLock<Validator> = LazyLock::new(|| {
47
- Validator::new(&to_value(schemars::schema_for!(RepoKitConfig)).unwrap()).unwrap()
48
- });
49
-
50
- impl RepoKitConstructValidator for RepoKitConfig {}
51
-
52
- impl RepoKitConfig {
53
- pub fn from_input(root: &str, node: &mut NodeScope, input: Value) -> RepoKitConfig {
54
- let repokit_config: Result<RepoKitConfig, serde_json::Error> = from_value(input.clone());
55
- if !RepoKitConfig::is_valid(&REPOKIT_CONFIG_VALIDATOR, &input) || repokit_config.is_err() {
56
- RepoKitConfig::on_parsing_error(root, node, Value::Null);
57
- }
58
- repokit_config.expect("assertions succeeded")
59
- }
60
-
61
- pub fn on_parsing_error(root: &str, node: &mut NodeScope, _: Value) -> Option<String> {
62
- let path_buf = Path::new(&root).join("repokit.ts");
63
- let path = path_buf.to_str().expect("exists");
64
- node.type_check_file(path);
65
- println!();
66
- Logger::info("There was an error parsing your configuration");
67
- NodeScope::prompt_to_fix_errors(path);
68
- panic!();
69
- }
70
-
71
- pub fn create(files: &FileSystem) {
72
- let file_path = format!("{}/repokit.ts", &files.git_root);
73
- let path = Path::new(&file_path);
74
- if path.exists() {
75
- Logger::info(
76
- format!(
77
- "I found a Repokit configuration but could not resolve the exported {} instance",
78
- Logger::with_theme(|theme| theme.highlight("RepokitConfig"))
79
- )
80
- .as_str(),
81
- );
82
- Logger::exit_with_info(
83
- "Please double check that your config file is free of any sideffects that can cause the parser to crash",
84
- );
85
- }
86
- Logger::info("Welcome to Repokit! Let's get you setup");
87
- Logger::info("Creating your configuration file:");
88
- let mut source = files.resolve_template("configuration_template.txt");
89
- let mut target = FileBuilder::create(path, |_| Logger::file_create_error());
90
- FileBuilder::copy_to(&mut source, &mut target, |_| Logger::file_write_error());
91
- Logger::info(
92
- format!(
93
- "Please fill out this file with your desired settings. Then run {}",
94
- Logger::with_theme(|theme| theme.highlight("repokit onboard"))
95
- )
96
- .as_str(),
97
- );
98
- Logger::log_file_path(file_path.as_str());
99
- panic!();
100
- }
101
- }
@@ -1,11 +0,0 @@
1
- use jsonschema::Validator;
2
- use serde_json::Value;
3
-
4
- pub trait RepoKitConstructValidator {
5
- fn is_valid(validator: &Validator, input: &Value) -> bool {
6
- if validator.validate(input).is_err() {
7
- return false;
8
- }
9
- true
10
- }
11
- }