@repokit/core 1.3.6 → 1.3.7
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/internals/configuration/configuration.rs +10 -9
- package/internals/file_walker/walker.rs +3 -1
- package/internals/internal_commands/help.rs +8 -1
- package/internals/internal_commands/register_command.rs +5 -9
- package/internals/internal_commands/typescript_command.rs +14 -3
- package/internals/internal_filesystem/file_builder.rs +57 -0
- package/internals/internal_filesystem/internal_filesystem.rs +15 -4
- package/internals/internal_filesystem/mod.rs +1 -0
- package/internals/logger/logger.rs +31 -3
- package/internals/repokit/repokit.rs +7 -5
- package/internals/validations/command_validations.rs +1 -1
- package/package.json +2 -2
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
use std::{
|
|
1
|
+
use std::{path::Path, process::exit};
|
|
2
2
|
|
|
3
|
-
use crate::{
|
|
3
|
+
use crate::{
|
|
4
|
+
internal_filesystem::{file_builder::FileBuilder, internal_filesystem::InternalFileSystem},
|
|
5
|
+
logger::logger::Logger,
|
|
6
|
+
};
|
|
4
7
|
|
|
5
8
|
pub struct Configuration;
|
|
6
9
|
|
|
7
10
|
impl Configuration {
|
|
8
11
|
pub fn create(root: &str) {
|
|
9
12
|
let file_path = format!("{root}/repokit.ts");
|
|
10
|
-
let
|
|
11
|
-
if
|
|
13
|
+
let path = Path::new(&file_path);
|
|
14
|
+
if path.exists() {
|
|
12
15
|
return;
|
|
13
16
|
}
|
|
14
17
|
Configuration::welcome();
|
|
15
|
-
let
|
|
18
|
+
let mut source =
|
|
16
19
|
InternalFileSystem::new(root).resolve_template("configuration_template.ts");
|
|
17
|
-
let mut
|
|
18
|
-
|
|
19
|
-
io::copy(&mut source, &mut target).expect("writing");
|
|
20
|
-
target.sync_all().expect("Flushing");
|
|
20
|
+
let mut target = FileBuilder::create(path, |_| Logger::file_create_error());
|
|
21
|
+
FileBuilder::copy_to(&mut source, &mut target, |_| Logger::file_write_error());
|
|
21
22
|
Logger::info(
|
|
22
23
|
format!(
|
|
23
24
|
"Please fill out this file with your desired settings. Then run {}",
|
|
@@ -7,6 +7,8 @@ use std::{
|
|
|
7
7
|
use ignore::{DirEntry, Error, ParallelVisitor, ParallelVisitorBuilder, WalkState};
|
|
8
8
|
use regex::Regex;
|
|
9
9
|
|
|
10
|
+
use crate::{internal_filesystem::file_builder::FileBuilder, logger::logger::Logger};
|
|
11
|
+
|
|
10
12
|
pub struct TSFileVisitor {
|
|
11
13
|
root: String,
|
|
12
14
|
paths: Arc<Mutex<Vec<String>>>,
|
|
@@ -26,7 +28,7 @@ impl ParallelVisitor for TSFileVisitor {
|
|
|
26
28
|
&& !template_matcher.is_match(path_string)
|
|
27
29
|
{
|
|
28
30
|
let mut open_comment = false;
|
|
29
|
-
let file: File =
|
|
31
|
+
let file: File = FileBuilder::open(path_string, |_| Logger::open_file_error());
|
|
30
32
|
let reader: BufReader<File> = BufReader::new(file);
|
|
31
33
|
for line_result in reader.lines() {
|
|
32
34
|
let unwrapped = line_result.unwrap();
|
|
@@ -145,7 +145,14 @@ impl Help {
|
|
|
145
145
|
sort_str_slice(&mut vector);
|
|
146
146
|
vector
|
|
147
147
|
.iter()
|
|
148
|
-
.map(|&name|
|
|
148
|
+
.map(|&name| {
|
|
149
|
+
RootCommand::from(
|
|
150
|
+
name,
|
|
151
|
+
commands
|
|
152
|
+
.get(name)
|
|
153
|
+
.expect("iteration is over known keys only"),
|
|
154
|
+
)
|
|
155
|
+
})
|
|
149
156
|
.collect()
|
|
150
157
|
}
|
|
151
158
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
use normalize_path::NormalizePath;
|
|
2
2
|
use std::{
|
|
3
3
|
collections::HashMap,
|
|
4
|
-
fs::{File, create_dir_all},
|
|
5
|
-
io,
|
|
6
4
|
path::{Path, PathBuf},
|
|
7
5
|
process,
|
|
8
6
|
};
|
|
@@ -15,7 +13,7 @@ use crate::{
|
|
|
15
13
|
},
|
|
16
14
|
},
|
|
17
15
|
internal_commands::help::Help,
|
|
18
|
-
internal_filesystem::internal_filesystem::InternalFileSystem,
|
|
16
|
+
internal_filesystem::{file_builder::FileBuilder, internal_filesystem::InternalFileSystem},
|
|
19
17
|
logger::logger::Logger,
|
|
20
18
|
};
|
|
21
19
|
|
|
@@ -56,7 +54,7 @@ impl RegisterCommand {
|
|
|
56
54
|
)
|
|
57
55
|
.as_str(),
|
|
58
56
|
);
|
|
59
|
-
create_dir_all(&path
|
|
57
|
+
FileBuilder::create_dir_all(&path, |_| Logger::file_directory_error());
|
|
60
58
|
}
|
|
61
59
|
if !path.is_dir() {
|
|
62
60
|
RegisterCommand::exit_on_missing_path();
|
|
@@ -90,12 +88,10 @@ impl InternalExecutable for RegisterCommand {
|
|
|
90
88
|
fn run(&self, args: Vec<String>, _: &HashMap<String, Box<dyn InternalExecutable>>) {
|
|
91
89
|
Logger::info("Registering a new command");
|
|
92
90
|
let command_path = self.validate_path(args);
|
|
93
|
-
let
|
|
91
|
+
let mut source =
|
|
94
92
|
InternalFileSystem::new(&self.scope.root).resolve_template("command_template.ts");
|
|
95
|
-
let mut
|
|
96
|
-
|
|
97
|
-
io::copy(&mut source, &mut target).expect("writing");
|
|
98
|
-
target.sync_all().expect("Flushing");
|
|
93
|
+
let mut target = FileBuilder::create(&command_path, |_| Logger::file_create_error());
|
|
94
|
+
FileBuilder::copy_to(&mut source, &mut target, |_| Logger::file_write_error());
|
|
99
95
|
Logger::info("Creating command file");
|
|
100
96
|
Logger::info("Please fill out your command file located at:");
|
|
101
97
|
Logger::log_file_path(command_path.to_str().expect("path"));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
use std::{path::Path, sync::MutexGuard};
|
|
1
|
+
use std::{path::Path, process::exit, sync::MutexGuard};
|
|
2
2
|
|
|
3
3
|
use serde_json::from_str;
|
|
4
4
|
|
|
@@ -6,6 +6,7 @@ use crate::{
|
|
|
6
6
|
configuration::configuration::Configuration,
|
|
7
7
|
executor::executor::Executor,
|
|
8
8
|
internal_filesystem::internal_filesystem::InternalFileSystem,
|
|
9
|
+
logger::logger::Logger,
|
|
9
10
|
repokit::interfaces::{RepoKitCommand, RepoKitConfig},
|
|
10
11
|
};
|
|
11
12
|
|
|
@@ -36,8 +37,18 @@ impl TypescriptCommand {
|
|
|
36
37
|
let executable = InternalFileSystem::new(&self.root).resolve_command("parse_commands.ts");
|
|
37
38
|
let stdout =
|
|
38
39
|
self.execute(format!("{executable} --paths {paths} --root {}", self.root).as_str());
|
|
39
|
-
let
|
|
40
|
-
|
|
40
|
+
let result: Result<Vec<RepoKitCommand>, serde_json::Error> = serde_json::from_str(&stdout);
|
|
41
|
+
match result {
|
|
42
|
+
Ok(commands) => commands,
|
|
43
|
+
Err(_) => {
|
|
44
|
+
Logger::info("There was an error parsing one of your commands");
|
|
45
|
+
Logger::info(
|
|
46
|
+
"You can validate a command file's syntactical correctness by running",
|
|
47
|
+
);
|
|
48
|
+
Logger::log_file_path("tsc --noEmit");
|
|
49
|
+
exit(0);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
41
52
|
}
|
|
42
53
|
|
|
43
54
|
fn execute(&self, args: &str) -> String {
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
use std::{
|
|
2
|
+
fs::{File, create_dir_all},
|
|
3
|
+
io::{Error, copy},
|
|
4
|
+
path::Path,
|
|
5
|
+
process::exit,
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
pub struct FileBuilder;
|
|
9
|
+
|
|
10
|
+
impl FileBuilder {
|
|
11
|
+
pub fn open(source: &str, on_error: impl Fn(Error)) -> File {
|
|
12
|
+
let source = File::open(source);
|
|
13
|
+
match source {
|
|
14
|
+
Ok(file) => file,
|
|
15
|
+
Err(error) => {
|
|
16
|
+
on_error(error);
|
|
17
|
+
exit(0);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
pub fn create(destination: &Path, on_error: impl Fn(Error)) -> File {
|
|
23
|
+
let source = File::create(destination);
|
|
24
|
+
match source {
|
|
25
|
+
Ok(file) => file,
|
|
26
|
+
Err(error) => {
|
|
27
|
+
on_error(error);
|
|
28
|
+
exit(0);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
pub fn copy_to(source: &mut File, target: &mut File, on_error: impl Fn(Error)) {
|
|
34
|
+
let result = copy(source, target);
|
|
35
|
+
match result {
|
|
36
|
+
Ok(_) => {
|
|
37
|
+
let sync = target.sync_all();
|
|
38
|
+
match sync {
|
|
39
|
+
Ok(_) => {}
|
|
40
|
+
Err(err) => on_error(err),
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
Err(err) => on_error(err),
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
pub fn create_dir_all(path: &Path, on_error: impl Fn(Error)) {
|
|
48
|
+
let source = create_dir_all(path);
|
|
49
|
+
match source {
|
|
50
|
+
Ok(result) => result,
|
|
51
|
+
Err(error) => {
|
|
52
|
+
on_error(error);
|
|
53
|
+
exit(0);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
use normalize_path::NormalizePath;
|
|
2
|
-
use std::
|
|
2
|
+
use std::{
|
|
3
|
+
fs::File,
|
|
4
|
+
path::{Path, PathBuf},
|
|
5
|
+
};
|
|
3
6
|
|
|
4
|
-
use crate::{
|
|
7
|
+
use crate::{
|
|
8
|
+
executor::executor::Executor, internal_filesystem::file_builder::FileBuilder,
|
|
9
|
+
logger::logger::Logger,
|
|
10
|
+
};
|
|
5
11
|
|
|
6
12
|
pub struct InternalFileSystem {
|
|
7
13
|
root: String,
|
|
@@ -23,8 +29,13 @@ impl InternalFileSystem {
|
|
|
23
29
|
self.path_buf_to_str(self.commands_directory().join(file_name))
|
|
24
30
|
}
|
|
25
31
|
|
|
26
|
-
pub fn resolve_template(&self, file_name: &str) ->
|
|
27
|
-
self.path_buf_to_str(self.templates_directory().join(file_name))
|
|
32
|
+
pub fn resolve_template(&self, file_name: &str) -> File {
|
|
33
|
+
let path = self.path_buf_to_str(self.templates_directory().join(file_name));
|
|
34
|
+
FileBuilder::open(&path, |_| {
|
|
35
|
+
Logger::error(format!("Unable to locate internal {file_name}").as_str());
|
|
36
|
+
Logger::error("Please file a bug here");
|
|
37
|
+
Logger::log_issue_link();
|
|
38
|
+
})
|
|
28
39
|
}
|
|
29
40
|
|
|
30
41
|
pub fn find_root() -> String {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
use std::process::exit;
|
|
2
|
+
use std::sync::LazyLock;
|
|
1
3
|
use std::sync::Mutex;
|
|
2
|
-
use std::{process, sync::LazyLock};
|
|
3
4
|
|
|
4
5
|
use colored::{ColoredString, Colorize, CustomColor};
|
|
5
6
|
|
|
@@ -23,12 +24,12 @@ impl Logger {
|
|
|
23
24
|
|
|
24
25
|
pub fn exit_with_info(message: &str) {
|
|
25
26
|
Logger::info(message);
|
|
26
|
-
|
|
27
|
+
exit(0);
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
pub fn exit_with_error(message: &str) {
|
|
30
31
|
Logger::error(message);
|
|
31
|
-
|
|
32
|
+
exit(0);
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
pub fn space_around(message: &str) {
|
|
@@ -92,6 +93,33 @@ impl Logger {
|
|
|
92
93
|
})
|
|
93
94
|
}
|
|
94
95
|
|
|
96
|
+
pub fn file_create_error() {
|
|
97
|
+
Logger::file_error("create a file");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
pub fn file_directory_error() {
|
|
101
|
+
Logger::file_error("create a directory");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
pub fn open_file_error() {
|
|
105
|
+
Logger::file_error("read a file");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
pub fn file_write_error() {
|
|
109
|
+
Logger::file_error("write to a file");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
pub fn log_issue_link() {
|
|
113
|
+
Logger::log_file_path("https://github.com/alexfigliolia/repokit/issues");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
fn file_error(operation: &str) {
|
|
117
|
+
Logger::info(format!("I was unable to {operation} in your repository").as_str());
|
|
118
|
+
Logger::error("Please verify the permissions on your working directory or file a bug here");
|
|
119
|
+
Logger::log_issue_link();
|
|
120
|
+
exit(0);
|
|
121
|
+
}
|
|
122
|
+
|
|
95
123
|
fn info_prefix() -> ColoredString {
|
|
96
124
|
format!("{}: ", *REGISTERED_NAME.lock().unwrap())
|
|
97
125
|
.bright_magenta()
|
|
@@ -36,7 +36,7 @@ impl RepoKit {
|
|
|
36
36
|
let validator = CommandValidations::from(self);
|
|
37
37
|
let internals = validator.collect_and_validate_internals();
|
|
38
38
|
if internals.contains_key(&command) {
|
|
39
|
-
let interface = internals.get(&command).expect("
|
|
39
|
+
let interface = internals.get(&command).expect("Unknown command");
|
|
40
40
|
return interface.run(args, &internals);
|
|
41
41
|
}
|
|
42
42
|
if self.scope.configuration.commands.contains_key(&command) {
|
|
@@ -45,7 +45,7 @@ impl RepoKit {
|
|
|
45
45
|
.configuration
|
|
46
46
|
.commands
|
|
47
47
|
.get(&command)
|
|
48
|
-
.expect("
|
|
48
|
+
.expect("Unknown command");
|
|
49
49
|
return Executor::with_stdio(
|
|
50
50
|
format!("{} {}", root_script.command, &args.join(" ")),
|
|
51
51
|
|cmd| cmd.current_dir(Path::new(&self.scope.root)),
|
|
@@ -56,14 +56,16 @@ impl RepoKit {
|
|
|
56
56
|
&internals, &externals,
|
|
57
57
|
);
|
|
58
58
|
if externals.contains_key(&command) {
|
|
59
|
-
let interface = externals.get(&command).expect("
|
|
59
|
+
let interface = externals.get(&command).expect("Unknown command");
|
|
60
60
|
if args.is_empty() {
|
|
61
61
|
return self.log_external_command(interface);
|
|
62
62
|
}
|
|
63
63
|
let sub_command = &args[0];
|
|
64
64
|
if interface.commands.contains_key(sub_command) {
|
|
65
|
-
let script = interface.commands.get(sub_command).expect("
|
|
66
|
-
let working_dir = Path::new(&interface.location)
|
|
65
|
+
let script = interface.commands.get(sub_command).expect("Unknown script");
|
|
66
|
+
let working_dir = Path::new(&interface.location)
|
|
67
|
+
.parent()
|
|
68
|
+
.expect("Working directory not found");
|
|
67
69
|
return Executor::with_stdio(
|
|
68
70
|
format!("{} {}", &script.command, &args[1..].join(" ")),
|
|
69
71
|
|cmd| cmd.current_dir(working_dir),
|
|
@@ -98,7 +98,7 @@ impl CommandValidations {
|
|
|
98
98
|
let mut map: HashMap<String, RepoKitCommand> = HashMap::new();
|
|
99
99
|
for command in externals {
|
|
100
100
|
if map.contains_key(&command.name) {
|
|
101
|
-
let original = map.get(&command.name).expect("
|
|
101
|
+
let original = map.get(&command.name).expect("Unknown command");
|
|
102
102
|
self.on_external_duplicate_collision(command, &original.location);
|
|
103
103
|
}
|
|
104
104
|
map.insert(command.name.clone(), command.clone());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@repokit/core",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.7",
|
|
4
4
|
"description": "A knowledgebase for your repository - wrapped in a CLI",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@types/node": "^25.2.1",
|
|
40
40
|
"oxfmt": "^0.33.0",
|
|
41
41
|
"oxlint": "^1.42.0",
|
|
42
|
-
"oxlint-tsgolint": "^0.
|
|
42
|
+
"oxlint-tsgolint": "^0.14.0",
|
|
43
43
|
"typescript": "^5.9.3"
|
|
44
44
|
}
|
|
45
45
|
}
|