@repokit/core 1.1.0 → 1.2.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.
@@ -6,7 +6,7 @@ REPO_ROOT=$(git rev-parse --show-toplevel)
6
6
  cd $REPO_ROOT
7
7
 
8
8
  command_exists() {
9
- command -v "$1"
9
+ command -v "$1" > /dev/null 2>&1
10
10
  }
11
11
 
12
12
  if command_exists rustc && command_exists cargo; then
@@ -12,7 +12,8 @@ impl Configuration {
12
12
  return;
13
13
  }
14
14
  Configuration::welcome();
15
- let template_path = InternalFileSystem::resolve_template("configuration_template.ts");
15
+ let template_path =
16
+ InternalFileSystem::new(root).resolve_template("configuration_template.ts");
16
17
  let mut source = File::open(template_path).expect("Template");
17
18
  let mut target = File::create(path_buf).expect("creating");
18
19
  io::copy(&mut source, &mut target).expect("writing");
@@ -64,7 +64,7 @@ impl ExternalCommands {
64
64
  }
65
65
  }
66
66
  pool.pool.shutdown_background();
67
- TypescriptCommand::new(self.root.clone()).parse_commands(paths)
67
+ TypescriptCommand::new(&self.root).parse_commands(paths)
68
68
  }
69
69
 
70
70
  fn read(path: &Path) -> bool {
@@ -93,7 +93,8 @@ impl InternalExecutable for RegisterCommand {
93
93
  fn run(&self, args: Vec<String>, _: &HashMap<String, Box<dyn InternalExecutable>>) {
94
94
  Logger::info("Registering a new command");
95
95
  let command_path = self.validate_path(args);
96
- let template_path = InternalFileSystem::resolve_template("command_template.ts");
96
+ let template_path =
97
+ InternalFileSystem::new(&self.root).resolve_template("command_template.ts");
97
98
  let mut source = File::open(template_path).expect("Template");
98
99
  let mut target = File::create(&command_path).expect("creating");
99
100
  io::copy(&mut source, &mut target).expect("writing");
@@ -14,12 +14,15 @@ pub struct TypescriptCommand {
14
14
  }
15
15
 
16
16
  impl TypescriptCommand {
17
- pub fn new(root: String) -> TypescriptCommand {
18
- TypescriptCommand { root }
17
+ pub fn new(root: &str) -> TypescriptCommand {
18
+ TypescriptCommand {
19
+ root: root.to_string(),
20
+ }
19
21
  }
20
22
 
21
23
  pub fn parse_configuration(&self) -> RepoKitConfig {
22
- let executable = InternalFileSystem::resolve_command("parse_configuration.ts");
24
+ let executable =
25
+ InternalFileSystem::new(&self.root).resolve_command("parse_configuration.ts");
23
26
  let stdout = self.execute(format!("{executable} --root {}", &self.root).as_str());
24
27
  if stdout.is_empty() {
25
28
  Configuration::create(&self.root);
@@ -31,7 +34,7 @@ impl TypescriptCommand {
31
34
 
32
35
  pub fn parse_commands(&self, path_list: Vec<String>) -> Vec<RepoKitCommand> {
33
36
  let paths = path_list.join(",");
34
- let executable = InternalFileSystem::resolve_command("parse_commands.ts");
37
+ let executable = InternalFileSystem::new(&self.root).resolve_command("parse_commands.ts");
35
38
  let stdout =
36
39
  self.execute(format!("{executable} --paths {paths} --root {}", self.root).as_str());
37
40
  let commands: Vec<RepoKitCommand> = serde_json::from_str(&stdout).expect("parse");
@@ -1,36 +1,47 @@
1
1
  use normalize_path::NormalizePath;
2
2
  use std::path::{Path, PathBuf};
3
3
 
4
- pub struct InternalFileSystem;
4
+ pub struct InternalFileSystem {
5
+ root: String,
6
+ }
5
7
 
6
8
  impl InternalFileSystem {
7
- pub fn absolute(segment: &str) -> PathBuf {
8
- let origin = env!("CARGO_MANIFEST_DIR");
9
- let path = Path::new(origin);
9
+ pub fn new(root: &str) -> InternalFileSystem {
10
+ InternalFileSystem {
11
+ root: root.to_string(),
12
+ }
13
+ }
14
+
15
+ pub fn absolute(&self, segment: &str) -> PathBuf {
16
+ let path = Path::new(&self.root);
10
17
  path.join(segment).normalize()
11
18
  }
12
19
 
13
- pub fn resolve_command(file_name: &str) -> String {
14
- InternalFileSystem::path_buf_to_str(
15
- InternalFileSystem::commands_directory().join(file_name),
16
- )
20
+ pub fn resolve_command(&self, file_name: &str) -> String {
21
+ self.path_buf_to_str(self.commands_directory().join(file_name))
22
+ }
23
+
24
+ pub fn resolve_template(&self, file_name: &str) -> String {
25
+ self.path_buf_to_str(self.templates_directory().join(file_name))
26
+ }
27
+
28
+ fn commands_directory(&self) -> PathBuf {
29
+ self.absolute(format!("{}/commands", self.package_directory()).as_str())
17
30
  }
18
31
 
19
- pub fn resolve_template(file_name: &str) -> String {
20
- InternalFileSystem::path_buf_to_str(
21
- InternalFileSystem::templates_directory().join(file_name),
22
- )
32
+ fn templates_directory(&self) -> PathBuf {
33
+ self.absolute(format!("{}/templates", self.package_directory()).as_str())
23
34
  }
24
35
 
25
- fn commands_directory() -> PathBuf {
26
- InternalFileSystem::absolute("./externals/commands")
36
+ fn package_directory(&self) -> String {
37
+ format!("./node_modules/{}/externals", self.package_name())
27
38
  }
28
39
 
29
- fn templates_directory() -> PathBuf {
30
- InternalFileSystem::absolute("./externals/templates")
40
+ fn package_name(&self) -> String {
41
+ "@repokit/core".to_string()
31
42
  }
32
43
 
33
- fn path_buf_to_str(buffer: PathBuf) -> String {
44
+ fn path_buf_to_str(&self, buffer: PathBuf) -> String {
34
45
  buffer
35
46
  .into_os_string()
36
47
  .into_string()
package/internals/main.rs CHANGED
@@ -15,7 +15,7 @@ mod validations;
15
15
 
16
16
  fn main() {
17
17
  let root = Executor::exec("git rev-parse --show-toplevel", |cmd| cmd);
18
- let config = TypescriptCommand::new(root.clone()).parse_configuration();
18
+ let config = TypescriptCommand::new(&root).parse_configuration();
19
19
  let kit = RepoKit::new(root, config);
20
20
  kit.invoke();
21
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@repokit/core",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "A knowledgebase for your repository - wrapped in a CLI",
5
5
  "keywords": [
6
6
  "cli",
@@ -22,12 +22,14 @@
22
22
  "scripts": {
23
23
  "build:all": "yarn lint:ts && yarn lint:rust && yarn install:rust",
24
24
  "build:rust": "cargo build --release",
25
+ "grant:exec": "chmod -R +x ./installation",
25
26
  "install:rust": "yarn build:rust && cargo install --path .",
26
27
  "lint:rust": "cargo clippy --fix --allow-dirty",
27
28
  "lint:ts": "yarn oxlint --type-aware --type-check --report-unused-disable-directives --fix && yarn oxfmt",
28
- "postinstall": "chmod +x ./install.sh && ./install.sh",
29
+ "postinstall": "yarn grant:exec && ./installation/install.sh",
29
30
  "repokit": "yarn install:repokit && repokit",
30
- "run:dev": "cargo run --package repokit --bin repokit"
31
+ "run:dev": "yarn symlink && cargo run --package repokit --bin repokit",
32
+ "symlink": "yarn grant:exec && ./installation/symlink.sh"
31
33
  },
32
34
  "dependencies": {
33
35
  "@figliolia/event-emitter": "^1.1.6",