@repokit/core 3.0.6 → 4.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.
- package/Cargo.lock +96 -11
- package/Cargo.toml +2 -2
- package/installation/install.sh +39 -28
- package/internals/caches/crawl_cache.rs +124 -0
- package/internals/caches/file_cache.rs +104 -0
- package/internals/caches/mod.rs +5 -0
- package/internals/caches/repokit_version_resolver.rs +50 -0
- package/internals/caches/settings_cache.rs +73 -0
- package/internals/caches/version_cache.rs +128 -0
- package/internals/context/cache_scope.rs +76 -0
- package/internals/context/file_system.rs +66 -0
- package/internals/context/git_scope.rs +55 -0
- package/internals/context/mod.rs +5 -0
- package/internals/context/node_scope.rs +133 -0
- package/internals/context/typescript_bridge.rs +68 -0
- package/internals/executables/internal_executable.rs +8 -2
- package/internals/executables/internal_executable_definition.rs +0 -8
- package/internals/executor/executor.rs +13 -0
- package/internals/file_walker/file_walker.rs +59 -0
- package/internals/file_walker/mod.rs +1 -0
- package/internals/internal_commands/help.rs +4 -3
- package/internals/internal_commands/internal_registry.rs +14 -20
- package/internals/internal_commands/list_commands.rs +7 -16
- package/internals/internal_commands/list_owners.rs +3 -16
- package/internals/internal_commands/list_themes.rs +11 -10
- package/internals/internal_commands/list_version.rs +17 -18
- package/internals/internal_commands/locate_command.rs +11 -17
- package/internals/internal_commands/onboarder.rs +5 -16
- package/internals/internal_commands/register_command.rs +12 -20
- package/internals/internal_commands/search_commands.rs +29 -20
- package/internals/internal_commands/upgrade_repokit.rs +19 -30
- package/internals/internal_filesystem/file_builder.rs +4 -9
- package/internals/internal_filesystem/mod.rs +0 -1
- package/internals/logger/logger.rs +19 -6
- package/internals/main.rs +8 -11
- package/internals/repokit/mod.rs +1 -1
- package/internals/repokit/repokit.rs +49 -57
- package/internals/repokit/repokit_command.rs +69 -38
- package/internals/repokit/repokit_config.rs +42 -18
- package/internals/repokit/repokit_construct_validator.rs +1 -4
- package/internals/repokit/repokit_runtime.rs +43 -0
- package/internals/themes/theme_registry.rs +5 -7
- package/internals/validations/command_validations.rs +39 -62
- package/package.json +3 -3
- package/internals/configuration/configuration.rs +0 -45
- package/internals/configuration/mod.rs +0 -3
- package/internals/configuration/recovery.rs +0 -42
- package/internals/configuration/typescript_command.rs +0 -65
- package/internals/internal_filesystem/internal_filesystem.rs +0 -308
- package/internals/repokit/runtime_compiler.rs +0 -62
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
use std::sync::{LazyLock, Mutex, MutexGuard};
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
use crate::{
|
|
5
|
+
context::{
|
|
6
|
+
cache_scope::CacheScope, file_system::FileSystem, git_scope::GitScope,
|
|
7
|
+
node_scope::NodeScope, typescript_bridge::TypeScriptBridge,
|
|
8
|
+
},
|
|
9
|
+
repokit::repokit_config::RepoKitConfig,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
pub struct RepoKitRuntime {
|
|
13
|
+
pub git: GitScope,
|
|
14
|
+
pub node: NodeScope,
|
|
15
|
+
pub files: FileSystem,
|
|
16
|
+
pub caches: CacheScope,
|
|
17
|
+
pub configuration: RepoKitConfig,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static REPOKIT_RUNTIME: LazyLock<Mutex<RepoKitRuntime>> =
|
|
21
|
+
LazyLock::new(|| Mutex::new(RepoKitRuntime::new()));
|
|
22
|
+
|
|
23
|
+
impl RepoKitRuntime {
|
|
24
|
+
pub fn new() -> RepoKitRuntime {
|
|
25
|
+
let git = GitScope::new();
|
|
26
|
+
let files = FileSystem::new(&git.root);
|
|
27
|
+
let caches = CacheScope::new(&git, &files);
|
|
28
|
+
let mut node = NodeScope::new(&git.root);
|
|
29
|
+
let configuration = TypeScriptBridge::parse_configuration(&files, &mut node);
|
|
30
|
+
RepoKitRuntime {
|
|
31
|
+
git,
|
|
32
|
+
node,
|
|
33
|
+
files,
|
|
34
|
+
caches,
|
|
35
|
+
configuration,
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
pub fn with_runtime<R>(mut func: impl FnMut(MutexGuard<'_, RepoKitRuntime>) -> R) -> R {
|
|
40
|
+
let registry = REPOKIT_RUNTIME.lock().unwrap();
|
|
41
|
+
func(registry)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
use std::collections::HashMap;
|
|
2
2
|
|
|
3
|
-
use crate::{
|
|
4
|
-
internal_filesystem::internal_filesystem::InternalFileSystem,
|
|
5
|
-
themes::{
|
|
3
|
+
use crate::themes::{
|
|
6
4
|
built_in_themes::{money::MONEY, seeing_red::SEEING_RED, the_blues::THE_BLUES},
|
|
7
5
|
theme::Theme,
|
|
8
6
|
theme_colors::ThemeColors,
|
|
9
7
|
theme_inputs::{RepoKitTheme, ThemeInputColors},
|
|
10
|
-
}
|
|
11
|
-
};
|
|
8
|
+
};
|
|
12
9
|
|
|
13
10
|
pub struct ThemeRegistry {
|
|
14
11
|
pub theme: String,
|
|
@@ -26,11 +23,12 @@ impl ThemeRegistry {
|
|
|
26
23
|
}
|
|
27
24
|
}
|
|
28
25
|
|
|
29
|
-
pub fn set_theme(&mut self,
|
|
26
|
+
pub fn set_theme(&mut self, theme: &str) -> bool {
|
|
30
27
|
if self.themes.contains_key(theme) && self.theme != theme {
|
|
31
28
|
self.theme = theme.to_string();
|
|
32
|
-
|
|
29
|
+
return true;
|
|
33
30
|
}
|
|
31
|
+
false
|
|
34
32
|
}
|
|
35
33
|
|
|
36
34
|
pub fn current_theme(&self) -> &Theme {
|
|
@@ -1,54 +1,31 @@
|
|
|
1
|
-
use std::
|
|
2
|
-
collections::HashMap,
|
|
3
|
-
sync::{Arc, Mutex},
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
use ignore::WalkBuilder;
|
|
1
|
+
use std::collections::HashMap;
|
|
7
2
|
|
|
8
3
|
use crate::{
|
|
9
|
-
|
|
10
|
-
executables::
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
file_walker::walker::TSFileVisitorBuilder,
|
|
14
|
-
internal_commands::internal_registry::InternalRegistry,
|
|
4
|
+
context::typescript_bridge::TypeScriptBridge,
|
|
5
|
+
executables::internal_executable::InternalExecutable,
|
|
6
|
+
file_walker::file_walker::FileWalker,
|
|
7
|
+
internal_commands::internal_registry::InternalCommandRegistry,
|
|
15
8
|
logger::logger::Logger,
|
|
16
|
-
repokit::{
|
|
9
|
+
repokit::{repokit_command::RepoKitCommand, repokit_runtime::RepoKitRuntime},
|
|
17
10
|
};
|
|
18
11
|
|
|
19
|
-
pub struct CommandValidations
|
|
20
|
-
scope: RepoKitScope,
|
|
21
|
-
}
|
|
12
|
+
pub struct CommandValidations;
|
|
22
13
|
|
|
23
14
|
impl CommandValidations {
|
|
24
|
-
pub fn
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
pub fn from(kit: &RepoKit) -> CommandValidations {
|
|
31
|
-
CommandValidations {
|
|
32
|
-
scope: kit.scope.clone(),
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
pub fn collect_and_validate_internals(&self) -> HashMap<String, Box<dyn InternalExecutable>> {
|
|
37
|
-
let internals = InternalRegistry::new(&self.scope).get_all();
|
|
38
|
-
self.detect_collisions_between_internals_and_root_commands(&internals);
|
|
15
|
+
pub fn collect_and_validate_internals() -> HashMap<String, Box<dyn InternalExecutable>> {
|
|
16
|
+
let internals = InternalCommandRegistry::new().get_all();
|
|
17
|
+
CommandValidations::detect_collisions_between_internals_and_root_commands(&internals);
|
|
39
18
|
internals
|
|
40
19
|
}
|
|
41
20
|
|
|
42
|
-
pub fn collect_and_validate_externals(
|
|
43
|
-
let
|
|
44
|
-
let
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
let all = [&externals[..], &self.scope.configuration.thirdParty[..]].concat();
|
|
51
|
-
self.detect_collisions_between_root_commands_and_externals(&all)
|
|
21
|
+
pub fn collect_and_validate_externals() -> HashMap<String, RepoKitCommand> {
|
|
22
|
+
let walker = FileWalker::new();
|
|
23
|
+
let result = walker.get();
|
|
24
|
+
let externals = TypeScriptBridge::parse_commands(&result);
|
|
25
|
+
let all = RepoKitRuntime::with_runtime(|runtime| {
|
|
26
|
+
[&externals[..], &runtime.configuration.thirdParty[..]].concat()
|
|
27
|
+
});
|
|
28
|
+
CommandValidations::detect_collisions_between_root_commands_and_externals(&all)
|
|
52
29
|
}
|
|
53
30
|
|
|
54
31
|
pub fn detect_collisions_between_internals_and_externals(
|
|
@@ -72,11 +49,12 @@ impl CommandValidations {
|
|
|
72
49
|
}
|
|
73
50
|
|
|
74
51
|
fn detect_collisions_between_internals_and_root_commands(
|
|
75
|
-
&self,
|
|
76
52
|
internals: &HashMap<String, Box<dyn InternalExecutable>>,
|
|
77
53
|
) {
|
|
78
54
|
for name in internals.keys() {
|
|
79
|
-
if
|
|
55
|
+
if RepoKitRuntime::with_runtime(|runtime| {
|
|
56
|
+
runtime.configuration.commands.contains_key(name)
|
|
57
|
+
}) {
|
|
80
58
|
Logger::info(
|
|
81
59
|
format!(
|
|
82
60
|
"I encountered a command named {} in your {} file that conflicts with one of my internals",
|
|
@@ -91,29 +69,28 @@ impl CommandValidations {
|
|
|
91
69
|
}
|
|
92
70
|
|
|
93
71
|
fn detect_collisions_between_root_commands_and_externals(
|
|
94
|
-
&self,
|
|
95
72
|
externals: &Vec<RepoKitCommand>,
|
|
96
73
|
) -> HashMap<String, RepoKitCommand> {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
74
|
+
RepoKitRuntime::with_runtime(|runtime| {
|
|
75
|
+
let mut map: HashMap<String, RepoKitCommand> = HashMap::new();
|
|
76
|
+
for command in externals {
|
|
77
|
+
if map.contains_key(&command.name) {
|
|
78
|
+
let original = map.get(&command.name).expect("Unknown command");
|
|
79
|
+
CommandValidations::on_external_duplicate_collision(
|
|
80
|
+
command,
|
|
81
|
+
&original.location,
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
map.insert(command.name.clone(), command.clone());
|
|
85
|
+
if runtime.configuration.commands.contains_key(&command.name) {
|
|
86
|
+
CommandValidations::on_external_root_collision(command);
|
|
87
|
+
}
|
|
102
88
|
}
|
|
103
|
-
map
|
|
104
|
-
|
|
105
|
-
.scope
|
|
106
|
-
.configuration
|
|
107
|
-
.commands
|
|
108
|
-
.contains_key(&command.name)
|
|
109
|
-
{
|
|
110
|
-
self.on_external_root_collision(command);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
map
|
|
89
|
+
map
|
|
90
|
+
})
|
|
114
91
|
}
|
|
115
92
|
|
|
116
|
-
fn on_external_root_collision(
|
|
93
|
+
fn on_external_root_collision(command: &RepoKitCommand) {
|
|
117
94
|
Logger::info(format!(
|
|
118
95
|
"I encountered a package command named {} that conflicts with a command in your {} file",
|
|
119
96
|
Logger::with_theme(|theme|theme.highlight(&command.name)),
|
|
@@ -126,7 +103,7 @@ impl CommandValidations {
|
|
|
126
103
|
Logger::exit_with_info("Please rename one of these");
|
|
127
104
|
}
|
|
128
105
|
|
|
129
|
-
fn on_external_duplicate_collision(
|
|
106
|
+
fn on_external_duplicate_collision(command: &RepoKitCommand, collision_path: &str) {
|
|
130
107
|
Logger::info(
|
|
131
108
|
format!(
|
|
132
109
|
"I encountered two packages with the name {}",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@repokit/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "A knowledgebase for your repository - wrapped in a CLI",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -63,9 +63,9 @@
|
|
|
63
63
|
"eslint-plugin-import": "^2.32.0",
|
|
64
64
|
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
65
65
|
"eslint-plugin-unused-imports": "^4.4.1",
|
|
66
|
-
"oxfmt": "^0.
|
|
66
|
+
"oxfmt": "^0.43.0",
|
|
67
67
|
"oxlint": "^1.42.0",
|
|
68
|
-
"oxlint-tsgolint": "^0.
|
|
68
|
+
"oxlint-tsgolint": "^0.19.0",
|
|
69
69
|
"tsdown": "^0.21.0",
|
|
70
70
|
"tsx": "^4.21.0",
|
|
71
71
|
"typescript": "^6.0.2"
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
use std::path::Path;
|
|
2
|
-
|
|
3
|
-
use crate::{
|
|
4
|
-
internal_filesystem::{file_builder::FileBuilder, internal_filesystem::InternalFileSystem},
|
|
5
|
-
logger::logger::Logger,
|
|
6
|
-
post_processing::post_processor::PostProcessor,
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
pub struct Configuration;
|
|
10
|
-
|
|
11
|
-
impl Configuration {
|
|
12
|
-
pub fn create(root: &str) {
|
|
13
|
-
let file_path = format!("{root}/repokit.ts");
|
|
14
|
-
let path = Path::new(&file_path);
|
|
15
|
-
if path.exists() {
|
|
16
|
-
Logger::info(
|
|
17
|
-
format!(
|
|
18
|
-
"I found a Repokit configuration without an exported {} instance",
|
|
19
|
-
Logger::with_theme(|theme| theme.highlight("RepokitConfig"))
|
|
20
|
-
)
|
|
21
|
-
.as_str(),
|
|
22
|
-
);
|
|
23
|
-
return Logger::exit_with_info("Please create an instance and export it");
|
|
24
|
-
}
|
|
25
|
-
Configuration::welcome();
|
|
26
|
-
let mut source =
|
|
27
|
-
InternalFileSystem::new(root).resolve_template("configuration_template.txt");
|
|
28
|
-
let mut target = FileBuilder::create(path, |_| Logger::file_create_error());
|
|
29
|
-
FileBuilder::copy_to(&mut source, &mut target, |_| Logger::file_write_error());
|
|
30
|
-
Logger::info(
|
|
31
|
-
format!(
|
|
32
|
-
"Please fill out this file with your desired settings. Then run {}",
|
|
33
|
-
Logger::with_theme(|theme| theme.highlight("repokit onboard"))
|
|
34
|
-
)
|
|
35
|
-
.as_str(),
|
|
36
|
-
);
|
|
37
|
-
Logger::log_file_path(file_path.as_str());
|
|
38
|
-
PostProcessor::get().flush();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
fn welcome() {
|
|
42
|
-
Logger::info("Welcome to Repokit! Let's get you setup");
|
|
43
|
-
Logger::info("Creating your configuration file:");
|
|
44
|
-
}
|
|
45
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
use crate::{
|
|
2
|
-
executor::executor::Executor, internal_filesystem::internal_filesystem::InternalFileSystem,
|
|
3
|
-
logger::logger::Logger,
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
pub struct Recovery {
|
|
7
|
-
root: String,
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
impl Recovery {
|
|
11
|
-
pub fn new(root: &str) -> Recovery {
|
|
12
|
-
Recovery {
|
|
13
|
-
root: root.to_owned(),
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
pub fn run(&mut self, file_path: &str) {
|
|
18
|
-
let command = self.get_typecheck_command(file_path);
|
|
19
|
-
Executor::with_stdio(command, |cmd| cmd);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
pub fn get_typecheck_command(&self, file_path: &str) -> String {
|
|
23
|
-
let executor = InternalFileSystem::get_node_executor(&self.root);
|
|
24
|
-
let typescript_version = InternalFileSystem::get_typescript_version(executor);
|
|
25
|
-
let ignore_config = if typescript_version >= 6 {
|
|
26
|
-
" --ignoreConfig".to_string()
|
|
27
|
-
} else {
|
|
28
|
-
"".to_string()
|
|
29
|
-
};
|
|
30
|
-
let tsc_command = format!("{} tsc {} --noEmit{}", executor, file_path, ignore_config);
|
|
31
|
-
tsc_command
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
pub fn prompt_to_fix_errors(&self, config_path: &str) {
|
|
35
|
-
Logger::info(
|
|
36
|
-
"Please fix the above type-errors and rerun your command"
|
|
37
|
-
.to_string()
|
|
38
|
-
.as_str(),
|
|
39
|
-
);
|
|
40
|
-
Logger::log_file_path(config_path);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
use std::{path::Path, process::exit, sync::MutexGuard};
|
|
2
|
-
|
|
3
|
-
use serde_json::{Value, from_str};
|
|
4
|
-
|
|
5
|
-
use crate::{
|
|
6
|
-
configuration::configuration::Configuration,
|
|
7
|
-
executor::executor::Executor,
|
|
8
|
-
internal_filesystem::internal_filesystem::InternalFileSystem,
|
|
9
|
-
post_processing::post_processor::PostProcessor,
|
|
10
|
-
repokit::{
|
|
11
|
-
repokit_command::RepoKitCommand, repokit_config::RepoKitConfig,
|
|
12
|
-
repokit_construct_validator::RepoKitConstructValidator,
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
pub struct TypescriptCommand {
|
|
17
|
-
root: String,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
impl TypescriptCommand {
|
|
21
|
-
pub fn new(root: &str) -> TypescriptCommand {
|
|
22
|
-
TypescriptCommand {
|
|
23
|
-
root: root.to_owned(),
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
pub fn parse_configuration(&self) -> RepoKitConfig {
|
|
28
|
-
let executable = InternalFileSystem::new(&self.root).resolve_command("parse_configuration");
|
|
29
|
-
let stdout = self.execute(format!("{executable} --root {}", &self.root).as_str());
|
|
30
|
-
if stdout.is_empty() {
|
|
31
|
-
Configuration::create(&self.root);
|
|
32
|
-
}
|
|
33
|
-
let result: Result<Value, serde_json::Error> = from_str(stdout.as_str());
|
|
34
|
-
match result {
|
|
35
|
-
Ok(config) => RepoKitConfig::from_input(&self.root, config),
|
|
36
|
-
Err(_) => {
|
|
37
|
-
RepoKitConfig::on_parsing_error(&self.root, Value::Null);
|
|
38
|
-
PostProcessor::get().flush();
|
|
39
|
-
exit(0)
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
pub fn parse_commands(&self, path_list: &MutexGuard<Vec<String>>) -> Vec<RepoKitCommand> {
|
|
45
|
-
let paths = path_list.join(",");
|
|
46
|
-
let executable = InternalFileSystem::new(&self.root).resolve_command("parse_commands");
|
|
47
|
-
let stdout =
|
|
48
|
-
self.execute(format!("{executable} --paths {paths} --root {}", self.root).as_str());
|
|
49
|
-
let result: Result<Vec<Value>, serde_json::Error> = serde_json::from_str(&stdout);
|
|
50
|
-
match result {
|
|
51
|
-
Ok(commands) => RepoKitCommand::from_input(&self.root, commands),
|
|
52
|
-
Err(_) => {
|
|
53
|
-
RepoKitCommand::on_parsing_error(&self.root, Value::Null);
|
|
54
|
-
PostProcessor::get().flush();
|
|
55
|
-
exit(0);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
fn execute(&self, args: &str) -> String {
|
|
61
|
-
Executor::exec(format!("node {args}"), |cmd| {
|
|
62
|
-
cmd.current_dir(Path::new(&self.root))
|
|
63
|
-
})
|
|
64
|
-
}
|
|
65
|
-
}
|