@repokit/core 0.1.1 → 0.1.2

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/install.sh CHANGED
@@ -16,23 +16,6 @@ else
16
16
  curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
17
17
  fi
18
18
 
19
- if npm list --depth=0 tsx; then
20
- echo "Found tsx installation"
21
- else
22
- # Node Dependencies installation
23
- if [ -f "${REPO_ROOT}/yarn.lock" ]; then
24
- yarn add -D tsx
25
- elif [ -f "${REPO_ROOT}/pnpm-lock.yaml" ]; then
26
- pnpm add -D tsx
27
- elif [ -f "${REPO_ROOT}/package-lock.json" ]; then
28
- npm i -D tsx
29
- else
30
- echo "No node.js package manager detected"
31
- echo "Run npm init to create your node.js project"
32
- fi
33
- fi
34
-
35
-
36
19
  echo "Installing Repokit CLI"
37
20
 
38
21
  cd "$SCRIPT_ORIGIN"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@repokit/core",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "A knowledgebase for your repository - wrapped in a CLI",
5
5
  "homepage": "https://github.com/alexfigliolia/repokit#readme",
6
6
  "license": "MIT",
@@ -1,9 +1,4 @@
1
- use std::{
2
- fs::File,
3
- io,
4
- path::Path,
5
- process::exit,
6
- };
1
+ use std::{fs::File, io, path::Path, process::exit};
7
2
 
8
3
  use crate::{internal_filesystem::internal_filesystem::InternalFileSystem, logger::logger::Logger};
9
4
 
@@ -17,7 +12,7 @@ impl Configuration {
17
12
  return;
18
13
  }
19
14
  Configuration::welcome();
20
- let template_path = InternalFileSystem::resolve_template("configuration_template.ts");
15
+ let template_path = InternalFileSystem::resolve_template("configuration_template");
21
16
  let mut source = File::open(template_path).expect("Template");
22
17
  let mut target = File::create(path_buf).expect("creating");
23
18
  io::copy(&mut source, &mut target).expect("writing");
@@ -91,7 +91,7 @@ impl InternalExecutable for RegisterCommand {
91
91
  fn run(&self, args: Vec<String>, _: &HashMap<String, Box<dyn InternalExecutable>>) {
92
92
  Logger::info("Registering a new command");
93
93
  let command_path = self.validate_path(args);
94
- let template_path = InternalFileSystem::resolve_template("command_template.ts");
94
+ let template_path = InternalFileSystem::resolve_template("command_template");
95
95
  let mut source = File::open(template_path).expect("Template");
96
96
  let mut target = File::create(&command_path).expect("creating");
97
97
  io::copy(&mut source, &mut target).expect("writing");
@@ -20,8 +20,8 @@ impl TypescriptCommand {
20
20
  }
21
21
 
22
22
  pub fn parse_configuration(&self) -> RepoKitConfig {
23
- let executable = InternalFileSystem::resolve_command("parse_configuration.ts");
24
- let stdout = self.with_tsx(format!("{executable} --root {}", &self.root).as_str());
23
+ let executable = InternalFileSystem::resolve_command("parse_configuration");
24
+ let stdout = self.exec_with_node(&executable, format!("--root {}", &self.root).as_str());
25
25
  Logger::info(&stdout);
26
26
  if stdout.is_empty() {
27
27
  Configuration::create(&self.root);
@@ -33,15 +33,22 @@ impl TypescriptCommand {
33
33
 
34
34
  pub fn parse_commands(&self, path_list: Vec<String>) -> Vec<RepoKitCommand> {
35
35
  let paths = path_list.join(",");
36
- let executable = InternalFileSystem::resolve_command("parse_commands.ts");
37
- let stdout =
38
- self.with_tsx(format!("{executable} --paths {paths} --root {}", self.root).as_str());
36
+ let executable = InternalFileSystem::resolve_command("parse_commands");
37
+ let stdout = self.exec_with_node(
38
+ &executable,
39
+ format!("--paths {paths} --root {}", self.root).as_str(),
40
+ );
39
41
  let commands: Vec<RepoKitCommand> = serde_json::from_str(&stdout).expect("parse");
40
42
  commands
41
43
  }
42
44
 
43
- fn with_tsx(&self, args: &str) -> String {
44
- Executor::exec(format!("npx tsx {}", args), |cmd| {
45
+ fn exec_with_node(&self, executable: &str, args: &str) -> String {
46
+ let driver = if executable.ends_with(".ts") {
47
+ "npx tsx"
48
+ } else {
49
+ "node"
50
+ };
51
+ Executor::exec(format!("{driver} {executable} {}", args), |cmd| {
45
52
  cmd.current_dir(Path::new(&self.root))
46
53
  })
47
54
  }
@@ -10,32 +10,33 @@ impl InternalFileSystem {
10
10
  path.join(segment).normalize()
11
11
  }
12
12
 
13
- pub fn commands_directory() -> PathBuf {
14
- InternalFileSystem::source_internal("commands")
13
+ pub fn resolve_command(file_name: &str) -> String {
14
+ let (path, extension) = InternalFileSystem::commands_directory();
15
+ InternalFileSystem::path_buf_to_str(path.join(format!("{file_name}{extension}")))
15
16
  }
16
17
 
17
- pub fn templates_directory() -> PathBuf {
18
- InternalFileSystem::source_internal("templates")
18
+ pub fn resolve_template(file_name: &str) -> String {
19
+ let (path, extension) = InternalFileSystem::templates_directory();
20
+ InternalFileSystem::path_buf_to_str(path.join(format!("{file_name}{extension}")))
19
21
  }
20
22
 
21
- pub fn resolve_command(file_name: &str) -> String {
22
- InternalFileSystem::path_buf_to_str(
23
- InternalFileSystem::commands_directory().join(file_name),
24
- )
23
+ fn commands_directory() -> (PathBuf, String) {
24
+ InternalFileSystem::source_internal("commands")
25
25
  }
26
26
 
27
- pub fn resolve_template(file_name: &str) -> String {
28
- InternalFileSystem::path_buf_to_str(
29
- InternalFileSystem::templates_directory().join(file_name),
30
- )
27
+ fn templates_directory() -> (PathBuf, String) {
28
+ InternalFileSystem::source_internal("templates")
31
29
  }
32
30
 
33
- fn source_internal(path: &str) -> PathBuf {
31
+ fn source_internal(path: &str) -> (PathBuf, String) {
34
32
  let src = InternalFileSystem::absolute(format!("./src/{path}").as_str());
35
33
  if InternalFileSystem::is_in_node_modules(&src) {
36
- return InternalFileSystem::absolute(format!("./dist/mjs/{path}").as_str());
34
+ return (
35
+ InternalFileSystem::absolute(format!("./dist/mjs/{path}").as_str()),
36
+ ".js".to_string(),
37
+ );
37
38
  }
38
- src
39
+ (src, ".ts".to_string())
39
40
  }
40
41
 
41
42
  fn path_buf_to_str(buffer: PathBuf) -> String {