@repokit/core 0.0.1
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/.vscode/settings.json +11 -0
- package/Cargo.lock +517 -0
- package/Cargo.toml +26 -0
- package/README.md +204 -0
- package/dist/cjs/CommandParser.js +68 -0
- package/dist/cjs/ConfigurationParser.js +46 -0
- package/dist/cjs/RepoKitCommand.js +16 -0
- package/dist/cjs/RepoKitConfig.js +10 -0
- package/dist/cjs/TaskPooler.js +42 -0
- package/dist/cjs/commands/parse_commands.js +15 -0
- package/dist/cjs/commands/parse_configuration.js +15 -0
- package/dist/cjs/index.js +19 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/types.js +2 -0
- package/dist/mjs/CommandParser.js +51 -0
- package/dist/mjs/ConfigurationParser.js +31 -0
- package/dist/mjs/RepoKitCommand.js +16 -0
- package/dist/mjs/RepoKitConfig.js +8 -0
- package/dist/mjs/TaskPooler.js +28 -0
- package/dist/mjs/commands/parse_commands.js +4 -0
- package/dist/mjs/commands/parse_configuration.js +4 -0
- package/dist/mjs/index.js +3 -0
- package/dist/mjs/package.json +4 -0
- package/dist/mjs/types.js +1 -0
- package/dist/types/CommandParser.d.ts +5 -0
- package/dist/types/ConfigurationParser.d.ts +4 -0
- package/dist/types/RepoKitCommand.d.ts +14 -0
- package/dist/types/RepoKitConfig.d.ts +6 -0
- package/dist/types/TaskPooler.d.ts +10 -0
- package/dist/types/commands/parse_commands.d.ts +1 -0
- package/dist/types/commands/parse_configuration.d.ts +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/types.d.ts +18 -0
- package/install.sh +43 -0
- package/package.json +40 -0
- package/repokit.ts +36 -0
- package/src/CommandParser.ts +59 -0
- package/src/ConfigurationParser.ts +34 -0
- package/src/RepoKitCommand.ts +24 -0
- package/src/RepoKitConfig.ts +10 -0
- package/src/TaskPooler.ts +31 -0
- package/src/commands/parse_commands.ts +5 -0
- package/src/commands/parse_configuration.ts +5 -0
- package/src/index.ts +3 -0
- package/src/types.ts +22 -0
- package/tsconfig.json +24 -0
- package/workspaces/concurrency/mod.rs +1 -0
- package/workspaces/concurrency/thread_pool.rs +32 -0
- package/workspaces/configuration/configuration.rs +47 -0
- package/workspaces/configuration/configuration_template.ts +23 -0
- package/workspaces/configuration/mod.rs +1 -0
- package/workspaces/executables/external_executable.rs +4 -0
- package/workspaces/executables/intenal_executable.rs +9 -0
- package/workspaces/executables/internal_executable_definition.rs +8 -0
- package/workspaces/executables/mod.rs +3 -0
- package/workspaces/executor/executor.rs +62 -0
- package/workspaces/executor/mod.rs +1 -0
- package/workspaces/external_commands/external_commands.rs +125 -0
- package/workspaces/external_commands/mod.rs +1 -0
- package/workspaces/internal_commands/command_template.ts +24 -0
- package/workspaces/internal_commands/help.rs +146 -0
- package/workspaces/internal_commands/internal_registry.rs +59 -0
- package/workspaces/internal_commands/list_commands.rs +106 -0
- package/workspaces/internal_commands/list_owners.rs +74 -0
- package/workspaces/internal_commands/locate_command.rs +78 -0
- package/workspaces/internal_commands/mod.rs +10 -0
- package/workspaces/internal_commands/onboarder.rs +66 -0
- package/workspaces/internal_commands/register_command.rs +117 -0
- package/workspaces/internal_commands/search_commands.rs +189 -0
- package/workspaces/internal_commands/typescript_command.rs +63 -0
- package/workspaces/internal_commands/upgrade_repokit.rs +76 -0
- package/workspaces/logger/logger.rs +98 -0
- package/workspaces/logger/mod.rs +1 -0
- package/workspaces/main.rs +21 -0
- package/workspaces/repokit/interfaces.rs +41 -0
- package/workspaces/repokit/mod.rs +2 -0
- package/workspaces/repokit/repokit.rs +141 -0
- package/workspaces/validations/command_validations.rs +140 -0
- package/workspaces/validations/mod.rs +1 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
use std::{
|
|
2
|
+
collections::HashMap,
|
|
3
|
+
env::args,
|
|
4
|
+
path::Path,
|
|
5
|
+
process::{self},
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
use crate::{
|
|
9
|
+
executables::intenal_executable::InternalExecutable,
|
|
10
|
+
executor::executor::Executor,
|
|
11
|
+
internal_commands::help::Help,
|
|
12
|
+
logger::logger::Logger,
|
|
13
|
+
repokit::interfaces::{RepoKitCommand, RepoKitConfig},
|
|
14
|
+
validations::command_validations::CommandValidations,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
pub struct RepoKit {
|
|
18
|
+
pub root: String,
|
|
19
|
+
pub configuration: RepoKitConfig,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
impl RepoKit {
|
|
23
|
+
pub fn new(root: String, configuration: RepoKitConfig) -> RepoKit {
|
|
24
|
+
Logger::set_name(&configuration.project);
|
|
25
|
+
RepoKit {
|
|
26
|
+
root,
|
|
27
|
+
configuration,
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
pub fn invoke(&self) {
|
|
32
|
+
let (command, args) = self.parse();
|
|
33
|
+
let validator = CommandValidations::from(self);
|
|
34
|
+
let internals = validator.collect_and_validate_internals();
|
|
35
|
+
if internals.contains_key(&command) {
|
|
36
|
+
let interface = internals.get(&command).expect("exists");
|
|
37
|
+
return interface.run(args, &internals);
|
|
38
|
+
}
|
|
39
|
+
if self.configuration.commands.contains_key(&command) {
|
|
40
|
+
let root_script = self.configuration.commands.get(&command).expect("exists");
|
|
41
|
+
return Executor::with_stdio(
|
|
42
|
+
format!("{} {}", root_script.command, &args.join(" ")),
|
|
43
|
+
|cmd| cmd.current_dir(Path::new(&self.root)),
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
let externals = validator.collect_and_validate_externals();
|
|
47
|
+
CommandValidations::detect_collisions_between_internals_and_externals(
|
|
48
|
+
&internals, &externals,
|
|
49
|
+
);
|
|
50
|
+
if externals.contains_key(&command) {
|
|
51
|
+
let interface = externals.get(&command).expect("exists");
|
|
52
|
+
if args.is_empty() {
|
|
53
|
+
return self.log_external_command(interface);
|
|
54
|
+
}
|
|
55
|
+
let sub_command = &args[0];
|
|
56
|
+
if interface.commands.contains_key(sub_command) {
|
|
57
|
+
let script = interface.commands.get(sub_command).expect("exists");
|
|
58
|
+
let working_dir = Path::new(&interface.location).parent().expect("exists");
|
|
59
|
+
return Executor::with_stdio(
|
|
60
|
+
format!("{}{}", &script.command, &args[1..].join(" ")),
|
|
61
|
+
|cmd| cmd.current_dir(working_dir),
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
return self.subcommand_not_found(interface, sub_command);
|
|
65
|
+
}
|
|
66
|
+
self.command_not_found(&command, &internals, &externals)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
fn parse(&self) -> (String, Vec<String>) {
|
|
70
|
+
let argv: Vec<String> = args().collect();
|
|
71
|
+
if argv.len() < 2 {
|
|
72
|
+
let (internals, externals) = self.collect_and_validate();
|
|
73
|
+
Help::list_all(&self.configuration.commands, &internals, &externals);
|
|
74
|
+
process::exit(0);
|
|
75
|
+
}
|
|
76
|
+
let command = &argv[1];
|
|
77
|
+
let args = &(&argv)[2..];
|
|
78
|
+
(command.clone(), args.to_vec())
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
fn collect_and_validate(
|
|
82
|
+
&self,
|
|
83
|
+
) -> (
|
|
84
|
+
HashMap<String, Box<dyn InternalExecutable>>,
|
|
85
|
+
HashMap<String, RepoKitCommand>,
|
|
86
|
+
) {
|
|
87
|
+
let validator = CommandValidations::from(self);
|
|
88
|
+
let internals = validator.collect_and_validate_internals();
|
|
89
|
+
let externals = validator.collect_and_validate_externals();
|
|
90
|
+
CommandValidations::detect_collisions_between_internals_and_externals(
|
|
91
|
+
&internals, &externals,
|
|
92
|
+
);
|
|
93
|
+
(internals, externals)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
fn command_not_found(
|
|
97
|
+
&self,
|
|
98
|
+
command: &str,
|
|
99
|
+
internals: &HashMap<String, Box<dyn InternalExecutable>>,
|
|
100
|
+
externals: &HashMap<String, RepoKitCommand>,
|
|
101
|
+
) {
|
|
102
|
+
Help::list_all(&self.configuration.commands, internals, externals);
|
|
103
|
+
Logger::info(
|
|
104
|
+
format!(
|
|
105
|
+
"I'm not aware of a command named {}",
|
|
106
|
+
Logger::blue_bright(command)
|
|
107
|
+
)
|
|
108
|
+
.as_str(),
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
fn subcommand_not_found(&self, command: &RepoKitCommand, sub_command: &str) {
|
|
113
|
+
Logger::info(
|
|
114
|
+
format!(
|
|
115
|
+
"The command {} was not found on {}",
|
|
116
|
+
Logger::blue_bright(sub_command),
|
|
117
|
+
Logger::blue_bright(&command.name)
|
|
118
|
+
)
|
|
119
|
+
.as_str(),
|
|
120
|
+
);
|
|
121
|
+
Logger::info(
|
|
122
|
+
format!(
|
|
123
|
+
"Here are the commands that belong to {}",
|
|
124
|
+
Logger::blue_bright(&command.name)
|
|
125
|
+
)
|
|
126
|
+
.as_str(),
|
|
127
|
+
);
|
|
128
|
+
Help::print_commands(&command.commands, Some(3));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
fn log_external_command(&self, command: &RepoKitCommand) {
|
|
132
|
+
Logger::info(
|
|
133
|
+
format!(
|
|
134
|
+
"Listing available commands for {}",
|
|
135
|
+
Logger::blue_bright(&command.name)
|
|
136
|
+
)
|
|
137
|
+
.as_str(),
|
|
138
|
+
);
|
|
139
|
+
Help::print_commands(&command.commands, Some(3))
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
use std::collections::HashMap;
|
|
2
|
+
|
|
3
|
+
use futures::executor;
|
|
4
|
+
|
|
5
|
+
use crate::{
|
|
6
|
+
repokit::{
|
|
7
|
+
repokit::RepoKit,
|
|
8
|
+
interfaces::{RepoKitCommand, RepoKitConfig},
|
|
9
|
+
},
|
|
10
|
+
executables::intenal_executable::InternalExecutable,
|
|
11
|
+
external_commands::external_commands::ExternalCommands,
|
|
12
|
+
internal_commands::internal_registry::InternalRegistry,
|
|
13
|
+
logger::logger::Logger,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
pub struct CommandValidations {
|
|
17
|
+
root: String,
|
|
18
|
+
configuration: RepoKitConfig,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
impl CommandValidations {
|
|
22
|
+
pub fn new(root: String, configuration: RepoKitConfig) -> CommandValidations {
|
|
23
|
+
CommandValidations {
|
|
24
|
+
root,
|
|
25
|
+
configuration,
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
pub fn from(kit: &RepoKit) -> CommandValidations {
|
|
30
|
+
CommandValidations {
|
|
31
|
+
root: kit.root.clone(),
|
|
32
|
+
configuration: kit.configuration.clone(),
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
pub fn collect_and_validate_internals(&self) -> HashMap<String, Box<dyn InternalExecutable>> {
|
|
37
|
+
let internals =
|
|
38
|
+
InternalRegistry::new(self.root.clone(), self.configuration.clone()).get_all();
|
|
39
|
+
self.detect_collisions_between_internals_and_root_commands(&internals);
|
|
40
|
+
internals
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
pub fn collect_and_validate_externals(&self) -> HashMap<String, RepoKitCommand> {
|
|
44
|
+
let finder = ExternalCommands::new(self.root.clone());
|
|
45
|
+
let externals = executor::block_on(finder.find_all());
|
|
46
|
+
self.detect_collisions_between_root_commands_and_externals(&externals)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
pub fn detect_collisions_between_internals_and_externals(
|
|
50
|
+
internals: &HashMap<String, Box<dyn InternalExecutable>>,
|
|
51
|
+
externals: &HashMap<String, RepoKitCommand>,
|
|
52
|
+
) {
|
|
53
|
+
for (name, command) in externals {
|
|
54
|
+
if internals.contains_key(name) {
|
|
55
|
+
Logger::info(
|
|
56
|
+
format!(
|
|
57
|
+
"I encountered a command named {} that conflicts with one of my internals",
|
|
58
|
+
Logger::blue_bright(name),
|
|
59
|
+
)
|
|
60
|
+
.as_str(),
|
|
61
|
+
);
|
|
62
|
+
Logger::info("Here's where it's located:");
|
|
63
|
+
Logger::log_file_path(&command.location);
|
|
64
|
+
Logger::exit_with_info("Please rename it");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
fn detect_collisions_between_internals_and_root_commands(
|
|
70
|
+
&self,
|
|
71
|
+
internals: &HashMap<String, Box<dyn InternalExecutable>>,
|
|
72
|
+
) {
|
|
73
|
+
for name in internals.keys() {
|
|
74
|
+
if self.configuration.commands.contains_key(name) {
|
|
75
|
+
Logger::info(
|
|
76
|
+
format!(
|
|
77
|
+
"I encountered a command named {} in your {} file that conflicts with one of my internals",
|
|
78
|
+
Logger::blue_bright(name),
|
|
79
|
+
Logger::blue_bright("repokit.ts"),
|
|
80
|
+
)
|
|
81
|
+
.as_str(),
|
|
82
|
+
);
|
|
83
|
+
Logger::exit_with_info("Please rename it");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
fn detect_collisions_between_root_commands_and_externals(
|
|
89
|
+
&self,
|
|
90
|
+
externals: &Vec<RepoKitCommand>,
|
|
91
|
+
) -> HashMap<String, RepoKitCommand> {
|
|
92
|
+
let mut map: HashMap<String, RepoKitCommand> = HashMap::new();
|
|
93
|
+
for command in externals {
|
|
94
|
+
if map.contains_key(&command.name) {
|
|
95
|
+
let original = map.get(&command.name).expect("existent key");
|
|
96
|
+
self.on_external_duplicate_collision(command, &original.location);
|
|
97
|
+
}
|
|
98
|
+
map.insert(command.name.clone(), command.clone());
|
|
99
|
+
if self.configuration.commands.contains_key(&command.name) {
|
|
100
|
+
self.on_external_root_collision(command);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
map
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
fn on_external_root_collision(&self, command: &RepoKitCommand) {
|
|
107
|
+
Logger::info(format!(
|
|
108
|
+
"I encountered a package command named {} that conflicts with a command in your {} file",
|
|
109
|
+
Logger::blue_bright(&command.name),
|
|
110
|
+
Logger::blue_bright("repokit.ts")
|
|
111
|
+
)
|
|
112
|
+
.as_str(),
|
|
113
|
+
);
|
|
114
|
+
Logger::info("Here's where it's located:");
|
|
115
|
+
Logger::log_file_path(&command.location);
|
|
116
|
+
Logger::exit_with_info("Please rename one of these");
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
fn on_external_duplicate_collision(&self, command: &RepoKitCommand, collision_path: &str) {
|
|
120
|
+
Logger::info(
|
|
121
|
+
format!(
|
|
122
|
+
"I encountered two packages with the name {}",
|
|
123
|
+
Logger::blue_bright(&command.name),
|
|
124
|
+
)
|
|
125
|
+
.as_str(),
|
|
126
|
+
);
|
|
127
|
+
Logger::info("Here's where they're located:\n");
|
|
128
|
+
println!(
|
|
129
|
+
"{}1. {}",
|
|
130
|
+
Logger::indent(None),
|
|
131
|
+
Logger::blue_bright(collision_path)
|
|
132
|
+
);
|
|
133
|
+
println!(
|
|
134
|
+
"{}2. {}\n",
|
|
135
|
+
Logger::indent(None),
|
|
136
|
+
Logger::blue_bright(&command.location)
|
|
137
|
+
);
|
|
138
|
+
Logger::exit_with_info("Please rename one of these");
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pub mod command_validations;
|