@repokit/core 0.0.8 → 0.0.9

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.
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Commands = void 0;
4
+ const core_1 = require("@repokit/core");
5
+ /**
6
+ * Please fill out this command file with your desired settings
7
+ */
8
+ exports.Commands = new core_1.RepoKitCommand({
9
+ name: "<Your Package Name>",
10
+ owner: "<Optional Team or Individual>",
11
+ description: "<Your Package Description>",
12
+ commands: {
13
+ "<your-first-command>": {
14
+ command: "<insert shell command here>",
15
+ description: "A description for using your command",
16
+ },
17
+ "<your-second-command>": {
18
+ command: "<insert shell command here>",
19
+ description: "A description for using your command",
20
+ },
21
+ "<your-third-command>": {
22
+ command: "<insert shell command here>",
23
+ description: "A description for using your command",
24
+ },
25
+ },
26
+ });
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RepoKit = void 0;
4
+ const core_1 = require("@repokit/core");
5
+ /**
6
+ * Please fill out this config file with your desired
7
+ * repokit settings
8
+ */
9
+ exports.RepoKit = new core_1.RepoKitConfig({
10
+ project: "Your Project Name",
11
+ commands: {
12
+ "<your-first-command>": {
13
+ command: "<insert shell command here>",
14
+ description: "A description for using your command",
15
+ },
16
+ "<your-second-command>": {
17
+ command: "<insert shell command here>",
18
+ description: "A description for using your command",
19
+ },
20
+ "<your-third-command>": {
21
+ command: "<insert shell command here>",
22
+ description: "A description for using your command",
23
+ },
24
+ },
25
+ });
@@ -0,0 +1,23 @@
1
+ import { RepoKitCommand } from "@repokit/core";
2
+ /**
3
+ * Please fill out this command file with your desired settings
4
+ */
5
+ export const Commands = new RepoKitCommand({
6
+ name: "<Your Package Name>",
7
+ owner: "<Optional Team or Individual>",
8
+ description: "<Your Package Description>",
9
+ commands: {
10
+ "<your-first-command>": {
11
+ command: "<insert shell command here>",
12
+ description: "A description for using your command",
13
+ },
14
+ "<your-second-command>": {
15
+ command: "<insert shell command here>",
16
+ description: "A description for using your command",
17
+ },
18
+ "<your-third-command>": {
19
+ command: "<insert shell command here>",
20
+ description: "A description for using your command",
21
+ },
22
+ },
23
+ });
@@ -0,0 +1,22 @@
1
+ import { RepoKitConfig } from "@repokit/core";
2
+ /**
3
+ * Please fill out this config file with your desired
4
+ * repokit settings
5
+ */
6
+ export const RepoKit = new RepoKitConfig({
7
+ project: "Your Project Name",
8
+ commands: {
9
+ "<your-first-command>": {
10
+ command: "<insert shell command here>",
11
+ description: "A description for using your command",
12
+ },
13
+ "<your-second-command>": {
14
+ command: "<insert shell command here>",
15
+ description: "A description for using your command",
16
+ },
17
+ "<your-third-command>": {
18
+ command: "<insert shell command here>",
19
+ description: "A description for using your command",
20
+ },
21
+ },
22
+ });
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Please fill out this command file with your desired settings
3
+ */
4
+ export declare const Commands: any;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Please fill out this config file with your desired
3
+ * repokit settings
4
+ */
5
+ export declare const RepoKit: any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@repokit/core",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
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,11 +1,11 @@
1
1
  use std::{
2
2
  fs::File,
3
3
  io,
4
- path::{Path, PathBuf},
4
+ path::Path,
5
5
  process::exit,
6
6
  };
7
7
 
8
- use crate::logger::logger::Logger;
8
+ use crate::{internal_filesystem::internal_filesystem::InternalFileSystem, logger::logger::Logger};
9
9
 
10
10
  pub struct Configuration;
11
11
 
@@ -17,7 +17,8 @@ impl Configuration {
17
17
  return;
18
18
  }
19
19
  Configuration::welcome();
20
- let mut source = File::open(Configuration::template_path()).expect("Template");
20
+ let template_path = InternalFileSystem::resolve_template("configuration_template.ts");
21
+ let mut source = File::open(template_path).expect("Template");
21
22
  let mut target = File::create(path_buf).expect("creating");
22
23
  io::copy(&mut source, &mut target).expect("writing");
23
24
  target.sync_all().expect("Flushing");
@@ -36,12 +37,4 @@ impl Configuration {
36
37
  Logger::info("Welcome to Repokit! Let's get you setup");
37
38
  Logger::info("Creating your configuration file:");
38
39
  }
39
-
40
- fn template_path() -> PathBuf {
41
- let file_path = file!();
42
- let dir = Path::new(file_path)
43
- .parent()
44
- .expect("Failed to get parent directory");
45
- dir.join("configuration_template.ts")
46
- }
47
40
  }
@@ -73,7 +73,7 @@ impl ExternalCommands {
73
73
 
74
74
  fn allowed(&self, path: &str) -> bool {
75
75
  let restricted_paths = ["node_modules", "target", "dist"];
76
- let restricted_extensions = ["internal_commands/command_template.ts"];
76
+ let restricted_extensions = ["templates/command_template.ts"];
77
77
  let relative_path = path.replace(format!("{}/", &self.root).as_str(), "");
78
78
  if ExternalCommands::restrict(
79
79
  &relative_path,
@@ -8,13 +8,14 @@ use std::{
8
8
  };
9
9
 
10
10
  use crate::{
11
- repokit::interfaces::RepoKitConfig,
12
11
  executables::{
13
12
  intenal_executable::InternalExecutable,
14
13
  internal_executable_definition::InternalExecutableDefinition,
15
14
  },
16
15
  internal_commands::help::Help,
16
+ internal_filesystem::internal_filesystem::InternalFileSystem,
17
17
  logger::logger::Logger,
18
+ repokit::interfaces::RepoKitConfig,
18
19
  };
19
20
 
20
21
  pub struct RegisterCommand {
@@ -84,21 +85,14 @@ impl RegisterCommand {
84
85
  "Please specify a path to a directory relative to the root of your repository",
85
86
  );
86
87
  }
87
-
88
- pub fn template_path() -> PathBuf {
89
- let file_path = file!();
90
- let dir = Path::new(file_path)
91
- .parent()
92
- .expect("Failed to get parent directory");
93
- dir.join("command_template.ts")
94
- }
95
88
  }
96
89
 
97
90
  impl InternalExecutable for RegisterCommand {
98
91
  fn run(&self, args: Vec<String>, _: &HashMap<String, Box<dyn InternalExecutable>>) {
99
92
  Logger::info("Registering a new command");
100
93
  let command_path = self.validate_path(args);
101
- let mut source = File::open(RegisterCommand::template_path()).expect("Template");
94
+ let template_path = InternalFileSystem::resolve_template("command_template.ts");
95
+ let mut source = File::open(template_path).expect("Template");
102
96
  let mut target = File::create(&command_path).expect("creating");
103
97
  io::copy(&mut source, &mut target).expect("writing");
104
98
  target.sync_all().expect("Flushing");
@@ -1,11 +1,11 @@
1
- use std::path::{Path, PathBuf};
1
+ use std::path::Path;
2
2
 
3
- use normalize_path::NormalizePath;
4
3
  use serde_json::from_str;
5
4
 
6
5
  use crate::{
7
6
  configuration::configuration::Configuration,
8
7
  executor::executor::Executor,
8
+ internal_filesystem::internal_filesystem::InternalFileSystem,
9
9
  logger::logger::Logger,
10
10
  repokit::interfaces::{RepoKitCommand, RepoKitConfig},
11
11
  };
@@ -20,9 +20,8 @@ impl TypescriptCommand {
20
20
  }
21
21
 
22
22
  pub fn parse_configuration(&self) -> RepoKitConfig {
23
- let executable = self.path_to_command("parse_configuration.ts");
24
- Logger::info(&executable);
25
- let stdout = self.execute(format!("{executable} --root {}", &self.root).as_str());
23
+ let executable = InternalFileSystem::resolve_command("parse_configuration.ts");
24
+ let stdout = self.with_tsx(format!("{executable} --root {}", &self.root).as_str());
26
25
  Logger::info(&stdout);
27
26
  if stdout.is_empty() {
28
27
  Configuration::create(&self.root);
@@ -34,32 +33,14 @@ impl TypescriptCommand {
34
33
 
35
34
  pub fn parse_commands(&self, path_list: Vec<String>) -> Vec<RepoKitCommand> {
36
35
  let paths = path_list.join(",");
37
- let executable = self.path_to_command("parse_commands.ts");
36
+ let executable = InternalFileSystem::resolve_command("parse_commands.ts");
38
37
  let stdout =
39
- self.execute(format!("{executable} --paths {paths} --root {}", self.root).as_str());
38
+ self.with_tsx(format!("{executable} --paths {paths} --root {}", self.root).as_str());
40
39
  let commands: Vec<RepoKitCommand> = serde_json::from_str(&stdout).expect("parse");
41
40
  commands
42
41
  }
43
42
 
44
- fn commands_dir(&self) -> PathBuf {
45
- let file_path = file!();
46
- let origin = env!("CARGO_MANIFEST_DIR");
47
- let dir = Path::new(file_path)
48
- .parent()
49
- .expect("Failed to get parent directory");
50
- let resolved = Path::new(origin).join(dir);
51
- resolved.join("../../src/commands").normalize()
52
- }
53
-
54
- fn path_to_command(&self, command_file: &str) -> String {
55
- self.commands_dir()
56
- .join(command_file)
57
- .into_os_string()
58
- .into_string()
59
- .expect("Cannot construct path")
60
- }
61
-
62
- fn execute(&self, args: &str) -> String {
43
+ fn with_tsx(&self, args: &str) -> String {
63
44
  Executor::exec(format!("npx tsx {}", args), |cmd| {
64
45
  cmd.current_dir(Path::new(&self.root))
65
46
  })
@@ -0,0 +1,36 @@
1
+ use normalize_path::NormalizePath;
2
+ use std::path::{Path, PathBuf};
3
+
4
+ pub struct InternalFileSystem;
5
+
6
+ impl InternalFileSystem {
7
+ pub fn absolute(segment: &str) -> PathBuf {
8
+ let origin = env!("CARGO_MANIFEST_DIR");
9
+ let path = Path::new(origin);
10
+ path.join(segment).normalize()
11
+ }
12
+
13
+ pub fn commands_directory() -> PathBuf {
14
+ InternalFileSystem::absolute("./src/commands")
15
+ }
16
+
17
+ pub fn templates_directory() -> PathBuf {
18
+ InternalFileSystem::absolute("./src/templates")
19
+ }
20
+
21
+ pub fn resolve_command(file_name: &str) -> String {
22
+ InternalFileSystem::commands_directory()
23
+ .join(file_name)
24
+ .into_os_string()
25
+ .into_string()
26
+ .expect("Cannot construct path")
27
+ }
28
+
29
+ pub fn resolve_template(file_name: &str) -> String {
30
+ InternalFileSystem::templates_directory()
31
+ .join(file_name)
32
+ .into_os_string()
33
+ .into_string()
34
+ .expect("Cannot construct path")
35
+ }
36
+ }
@@ -0,0 +1 @@
1
+ pub mod internal_filesystem;
@@ -9,6 +9,7 @@ mod executables;
9
9
  mod executor;
10
10
  mod external_commands;
11
11
  mod internal_commands;
12
+ mod internal_filesystem;
12
13
  mod logger;
13
14
  mod repokit;
14
15
  mod validations;