@repokit/core 0.0.8 → 0.1.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.
- package/dist/cjs/CommandParser.js +2 -1
- package/dist/cjs/RepoKitCommand.js +0 -4
- package/dist/cjs/templates/command_template.js +26 -0
- package/dist/cjs/templates/configuration_template.js +25 -0
- package/dist/mjs/CommandParser.js +2 -1
- package/dist/mjs/RepoKitCommand.js +0 -4
- package/dist/mjs/templates/command_template.js +23 -0
- package/dist/mjs/templates/configuration_template.js +22 -0
- package/dist/types/RepoKitCommand.d.ts +0 -6
- package/dist/types/templates/command_template.d.ts +4 -0
- package/dist/types/templates/configuration_template.d.ts +5 -0
- package/package.json +4 -3
- package/src/CommandParser.ts +2 -1
- package/src/RepoKitCommand.ts +0 -5
- package/workspaces/configuration/configuration.rs +4 -11
- package/workspaces/external_commands/external_commands.rs +1 -1
- package/workspaces/internal_commands/register_command.rs +4 -10
- package/workspaces/internal_commands/typescript_command.rs +7 -26
- package/workspaces/internal_filesystem/internal_filesystem.rs +54 -0
- package/workspaces/internal_filesystem/mod.rs +1 -0
- package/workspaces/main.rs +1 -0
- /package/{workspaces/internal_commands → src/templates}/command_template.ts +0 -0
- /package/{workspaces/configuration → src/templates}/configuration_template.ts +0 -0
|
@@ -16,6 +16,7 @@ const promises_1 = require("node:fs/promises");
|
|
|
16
16
|
const node_fs_1 = require("node:fs");
|
|
17
17
|
const TaskPooler_1 = require("./TaskPooler");
|
|
18
18
|
const RepoKitCommand_1 = require("./RepoKitCommand");
|
|
19
|
+
/* oxlint-disable typescript-eslint(no-misused-spread) */
|
|
19
20
|
class CommandParser {
|
|
20
21
|
static parse() {
|
|
21
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -35,7 +36,7 @@ class CommandParser {
|
|
|
35
36
|
const declaredExports = yield Promise.resolve(`${path}`).then(s => require(s));
|
|
36
37
|
for (const key in declaredExports) {
|
|
37
38
|
if (declaredExports[key] instanceof RepoKitCommand_1.RepoKitCommand) {
|
|
38
|
-
commands.push(Object.assign(Object.assign({}, declaredExports[key]
|
|
39
|
+
commands.push(Object.assign(Object.assign({}, declaredExports[key]), { location: path }));
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
return commands;
|
|
@@ -8,9 +8,5 @@ class RepoKitCommand {
|
|
|
8
8
|
this.commands = commands;
|
|
9
9
|
this.description = description;
|
|
10
10
|
}
|
|
11
|
-
toJSON() {
|
|
12
|
-
const { name, owner, commands, description } = this;
|
|
13
|
-
return { name, owner, commands, description };
|
|
14
|
-
}
|
|
15
11
|
}
|
|
16
12
|
exports.RepoKitCommand = RepoKitCommand;
|
|
@@ -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
|
+
});
|
|
@@ -4,6 +4,7 @@ import { stat } from "node:fs/promises";
|
|
|
4
4
|
import { existsSync } from "node:fs";
|
|
5
5
|
import { TaskPooler } from "./TaskPooler.js";
|
|
6
6
|
import { RepoKitCommand } from "./RepoKitCommand.js";
|
|
7
|
+
/* oxlint-disable typescript-eslint(no-misused-spread) */
|
|
7
8
|
export class CommandParser {
|
|
8
9
|
static async parse() {
|
|
9
10
|
const { paths, root } = this.parsePaths();
|
|
@@ -20,7 +21,7 @@ export class CommandParser {
|
|
|
20
21
|
const declaredExports = await import(path);
|
|
21
22
|
for (const key in declaredExports) {
|
|
22
23
|
if (declaredExports[key] instanceof RepoKitCommand) {
|
|
23
|
-
commands.push({ ...declaredExports[key]
|
|
24
|
+
commands.push({ ...declaredExports[key], location: path });
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
return commands;
|
|
@@ -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
|
+
});
|
|
@@ -5,10 +5,4 @@ export declare class RepoKitCommand {
|
|
|
5
5
|
description: string;
|
|
6
6
|
commands: Record<string, ICommand>;
|
|
7
7
|
constructor({ name, description, owner, commands, }: IRepoKitCommand);
|
|
8
|
-
toJSON(): {
|
|
9
|
-
name: string;
|
|
10
|
-
owner: string;
|
|
11
|
-
commands: Record<string, ICommand>;
|
|
12
|
-
description: string;
|
|
13
|
-
};
|
|
14
8
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@repokit/core",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
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",
|
|
@@ -23,11 +23,12 @@
|
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
|
-
"build:all": "yarn build:ts && yarn lint:
|
|
26
|
+
"build:all": "yarn build:ts && yarn lint:ts && yarn lint:rust && yarn install:repokit",
|
|
27
27
|
"build:rust": "cargo build --release",
|
|
28
28
|
"build:ts": "yarn ts-packager -e src",
|
|
29
29
|
"install:repokit": "yarn build:rust && cargo install --path .",
|
|
30
|
-
"lint:
|
|
30
|
+
"lint:rust": "cargo clippy --fix --allow-dirty",
|
|
31
|
+
"lint:ts": "yarn oxlint --type-aware --type-check --report-unused-disable-directives --fix && yarn oxfmt",
|
|
31
32
|
"postinstall": "chmod +x ./install.sh && ./install.sh",
|
|
32
33
|
"repokit": "yarn build:ts && yarn install:repokit && repokit",
|
|
33
34
|
"run:dev": "cargo run --package repokit --bin repokit"
|
package/src/CommandParser.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { existsSync } from "node:fs";
|
|
|
6
6
|
import type { ILocatedCommand } from "./types";
|
|
7
7
|
import { TaskPooler } from "./TaskPooler";
|
|
8
8
|
import { RepoKitCommand } from "./RepoKitCommand";
|
|
9
|
+
/* oxlint-disable typescript-eslint(no-misused-spread) */
|
|
9
10
|
|
|
10
11
|
export class CommandParser {
|
|
11
12
|
public static async parse() {
|
|
@@ -28,7 +29,7 @@ export class CommandParser {
|
|
|
28
29
|
const declaredExports = await import(path);
|
|
29
30
|
for (const key in declaredExports) {
|
|
30
31
|
if (declaredExports[key] instanceof RepoKitCommand) {
|
|
31
|
-
commands.push({ ...declaredExports[key]
|
|
32
|
+
commands.push({ ...declaredExports[key], location: path });
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
return commands;
|
package/src/RepoKitCommand.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
use std::{
|
|
2
2
|
fs::File,
|
|
3
3
|
io,
|
|
4
|
-
path::
|
|
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
|
|
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 = ["
|
|
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
|
|
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::
|
|
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 =
|
|
24
|
-
|
|
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 =
|
|
36
|
+
let executable = InternalFileSystem::resolve_command("parse_commands.ts");
|
|
38
37
|
let stdout =
|
|
39
|
-
self.
|
|
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
|
|
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,54 @@
|
|
|
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::source_internal("commands")
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
pub fn templates_directory() -> PathBuf {
|
|
18
|
+
InternalFileSystem::source_internal("templates")
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
pub fn resolve_command(file_name: &str) -> String {
|
|
22
|
+
InternalFileSystem::path_buf_to_str(
|
|
23
|
+
InternalFileSystem::commands_directory().join(file_name),
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
pub fn resolve_template(file_name: &str) -> String {
|
|
28
|
+
InternalFileSystem::path_buf_to_str(
|
|
29
|
+
InternalFileSystem::templates_directory().join(file_name),
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
fn source_internal(path: &str) -> PathBuf {
|
|
34
|
+
let src = InternalFileSystem::absolute(format!("./src/{path}").as_str());
|
|
35
|
+
if InternalFileSystem::is_in_node_modules(&src) {
|
|
36
|
+
return InternalFileSystem::absolute(format!("./dist/{path}").as_str());
|
|
37
|
+
}
|
|
38
|
+
src
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
fn path_buf_to_str(buffer: PathBuf) -> String {
|
|
42
|
+
buffer
|
|
43
|
+
.into_os_string()
|
|
44
|
+
.into_string()
|
|
45
|
+
.expect("Cannot construct path")
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
fn is_in_node_modules(path: &PathBuf) -> bool {
|
|
49
|
+
path.as_os_str()
|
|
50
|
+
.to_str()
|
|
51
|
+
.expect("blah")
|
|
52
|
+
.contains("node_modules")
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pub mod internal_filesystem;
|
package/workspaces/main.rs
CHANGED
|
File without changes
|
|
File without changes
|