@repokit/core 1.5.0 → 1.6.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.
Files changed (49) hide show
  1. package/dist/CommandParser.d.mts +9 -0
  2. package/dist/CommandParser.mjs +55 -0
  3. package/dist/ConcurrencyPool.d.mts +13 -0
  4. package/dist/ConcurrencyPool.mjs +24 -0
  5. package/dist/ConfigurationParser.d.mts +9 -0
  6. package/dist/ConfigurationParser.mjs +27 -0
  7. package/dist/RepoKitCommand.d.mts +17 -0
  8. package/dist/RepoKitCommand.mjs +16 -0
  9. package/dist/RepoKitConfig.d.mts +25 -0
  10. package/dist/RepoKitConfig.mjs +25 -0
  11. package/dist/TSCompiler.d.mts +9 -0
  12. package/dist/TSCompiler.mjs +20 -0
  13. package/dist/commands/parse_commands.d.mts +1 -0
  14. package/dist/commands/parse_commands.mjs +9 -0
  15. package/dist/commands/parse_configuration.d.mts +1 -0
  16. package/dist/commands/parse_configuration.mjs +9 -0
  17. package/dist/index.d.mts +4 -0
  18. package/dist/index.mjs +4 -0
  19. package/dist/templates/command_template.mjs +5 -0
  20. package/dist/templates/configuration_template.mjs +5 -0
  21. package/dist/types.d.mts +25 -0
  22. package/dist/types.mjs +1 -0
  23. package/externals/CommandParser.ts +12 -6
  24. package/externals/ConcurrencyPool.ts +24 -0
  25. package/externals/ConfigurationParser.ts +3 -2
  26. package/externals/TSCompiler.ts +22 -4
  27. package/externals/commands/parse_configuration.ts +3 -1
  28. package/internals/configuration/configuration.rs +8 -1
  29. package/internals/internal_commands/typescript_command.rs +2 -3
  30. package/internals/internal_filesystem/internal_filesystem.rs +5 -2
  31. package/package.json +6 -5
  32. package/dist/CommandParser.d.ts +0 -6
  33. package/dist/CommandParser.js +0 -55
  34. package/dist/ConfigurationParser.d.ts +0 -5
  35. package/dist/ConfigurationParser.js +0 -36
  36. package/dist/RepoKitCommand.d.ts +0 -8
  37. package/dist/RepoKitCommand.js +0 -16
  38. package/dist/RepoKitConfig.d.ts +0 -17
  39. package/dist/RepoKitConfig.js +0 -22
  40. package/dist/TSCompiler.d.ts +0 -2
  41. package/dist/TSCompiler.js +0 -11
  42. package/dist/commands/parse_commands.d.ts +0 -1
  43. package/dist/commands/parse_commands.js +0 -6
  44. package/dist/commands/parse_configuration.d.ts +0 -1
  45. package/dist/commands/parse_configuration.js +0 -4
  46. package/dist/index.d.ts +0 -3
  47. package/dist/index.js +0 -19
  48. package/dist/types.d.ts +0 -21
  49. package/dist/types.js +0 -2
@@ -0,0 +1,9 @@
1
+ //#region externals/CommandParser.d.ts
2
+ declare class CommandParser {
3
+ private static compiler?;
4
+ static parse(): Promise<void>;
5
+ private static parseCommand;
6
+ private static parsePaths;
7
+ }
8
+ //#endregion
9
+ export { CommandParser };
@@ -0,0 +1,55 @@
1
+ import { TSCompiler } from "./TSCompiler.mjs";
2
+ import { RepoKitCommand } from "./RepoKitCommand.mjs";
3
+ import { ConcurrencyPool } from "./ConcurrencyPool.mjs";
4
+ import { parseArgs } from "node:util";
5
+ import { stat } from "node:fs/promises";
6
+ import { existsSync } from "node:fs";
7
+
8
+ //#region externals/CommandParser.ts
9
+ var CommandParser = class {
10
+ static compiler;
11
+ static async parse() {
12
+ const { paths, root } = this.parsePaths();
13
+ if (!root || !existsSync(root) || !(await stat(root)).isDirectory()) return console.log(JSON.stringify([]));
14
+ this.compiler = new TSCompiler(root, "parse_commands");
15
+ const pool = new ConcurrencyPool();
16
+ const pathList = paths.split(",").filter(Boolean);
17
+ const commands = await Promise.all(pathList.map((path) => pool.enqueue(() => this.parseCommand(path))));
18
+ console.log(JSON.stringify(commands.flat()));
19
+ }
20
+ static async parseCommand(path) {
21
+ const commands = [];
22
+ const declaredExports = await this.compiler?.compile?.(path);
23
+ for (const key in declaredExports) if (declaredExports[key] instanceof RepoKitCommand) commands.push({
24
+ ...declaredExports[key],
25
+ location: path
26
+ });
27
+ return commands;
28
+ }
29
+ static parsePaths() {
30
+ try {
31
+ return parseArgs({ options: {
32
+ paths: {
33
+ default: "",
34
+ multiple: false,
35
+ short: "p",
36
+ type: "string"
37
+ },
38
+ root: {
39
+ default: "",
40
+ multiple: false,
41
+ short: "r",
42
+ type: "string"
43
+ }
44
+ } }).values;
45
+ } catch {
46
+ return {
47
+ paths: "",
48
+ root: ""
49
+ };
50
+ }
51
+ }
52
+ };
53
+
54
+ //#endregion
55
+ export { CommandParser };
@@ -0,0 +1,13 @@
1
+ import { AsyncTask } from "./types.mjs";
2
+
3
+ //#region externals/ConcurrencyPool.d.ts
4
+ declare class ConcurrencyPool<T> {
5
+ readonly maxConcurrency: number;
6
+ private readonly IDs;
7
+ private readonly activeTasks;
8
+ constructor(maxConcurrency?: number);
9
+ enqueue(task: AsyncTask<T>): Promise<T>;
10
+ private executeTask;
11
+ }
12
+ //#endregion
13
+ export { ConcurrencyPool };
@@ -0,0 +1,24 @@
1
+ import { AutoIncrementingID } from "@figliolia/event-emitter";
2
+
3
+ //#region externals/ConcurrencyPool.ts
4
+ var ConcurrencyPool = class {
5
+ IDs = new AutoIncrementingID();
6
+ activeTasks = /* @__PURE__ */ new Map();
7
+ constructor(maxConcurrency = 10) {
8
+ this.maxConcurrency = maxConcurrency;
9
+ }
10
+ async enqueue(task) {
11
+ if (this.activeTasks.size === this.maxConcurrency) await Promise.race(Array.from(this.activeTasks.values()));
12
+ return this.executeTask(task);
13
+ }
14
+ executeTask(task) {
15
+ const ID = this.IDs.get();
16
+ const promise = task();
17
+ this.activeTasks.set(ID, promise);
18
+ promise.finally(() => this.activeTasks.delete(ID));
19
+ return promise;
20
+ }
21
+ };
22
+
23
+ //#endregion
24
+ export { ConcurrencyPool };
@@ -0,0 +1,9 @@
1
+ import { TSCompiler } from "./TSCompiler.mjs";
2
+
3
+ //#region externals/ConfigurationParser.d.ts
4
+ declare class ConfigurationParser extends TSCompiler {
5
+ static parse(): Promise<void>;
6
+ private static parseRoot;
7
+ }
8
+ //#endregion
9
+ export { ConfigurationParser };
@@ -0,0 +1,27 @@
1
+ import { TSCompiler } from "./TSCompiler.mjs";
2
+ import { RepoKitConfig } from "./RepoKitConfig.mjs";
3
+ import { parseArgs } from "node:util";
4
+ import { existsSync } from "node:fs";
5
+ import { join } from "node:path";
6
+
7
+ //#region externals/ConfigurationParser.ts
8
+ var ConfigurationParser = class extends TSCompiler {
9
+ static async parse() {
10
+ const root = this.parseRoot();
11
+ const path = join(root, "repokit.ts");
12
+ if (!existsSync(path)) return;
13
+ const config = await new TSCompiler(root, "parse_configuration").compile(path);
14
+ for (const key in config) if (config[key] instanceof RepoKitConfig) return console.log(JSON.stringify(config[key].toScoped(path)));
15
+ }
16
+ static parseRoot() {
17
+ return parseArgs({ options: { root: {
18
+ default: "",
19
+ multiple: false,
20
+ short: "r",
21
+ type: "string"
22
+ } } }).values.root;
23
+ }
24
+ };
25
+
26
+ //#endregion
27
+ export { ConfigurationParser };
@@ -0,0 +1,17 @@
1
+ import { ICommand, IRepoKitCommand } from "./types.mjs";
2
+
3
+ //#region externals/RepoKitCommand.d.ts
4
+ declare class RepoKitCommand {
5
+ name: string;
6
+ owner: string;
7
+ description: string;
8
+ commands: Record<string, ICommand>;
9
+ constructor({
10
+ name,
11
+ description,
12
+ owner,
13
+ commands
14
+ }: IRepoKitCommand);
15
+ }
16
+ //#endregion
17
+ export { RepoKitCommand };
@@ -0,0 +1,16 @@
1
+ //#region externals/RepoKitCommand.ts
2
+ var RepoKitCommand = class {
3
+ name;
4
+ owner;
5
+ description;
6
+ commands;
7
+ constructor({ name, description, owner = "", commands = {} }) {
8
+ this.name = name;
9
+ this.owner = owner;
10
+ this.commands = commands;
11
+ this.description = description;
12
+ }
13
+ };
14
+
15
+ //#endregion
16
+ export { RepoKitCommand };
@@ -0,0 +1,25 @@
1
+ import { RepoKitCommand } from "./RepoKitCommand.mjs";
2
+ import { ICommand, IRepoKitConfig } from "./types.mjs";
3
+
4
+ //#region externals/RepoKitConfig.d.ts
5
+ declare class RepoKitConfig implements Required<IRepoKitConfig> {
6
+ project: string;
7
+ thirdParty: RepoKitCommand[];
8
+ commands: Record<string, ICommand>;
9
+ constructor({
10
+ project,
11
+ commands,
12
+ thirdParty
13
+ }: IRepoKitConfig);
14
+ toScoped(location: string): this & {
15
+ thirdParty: {
16
+ location: string;
17
+ name: string;
18
+ owner: string;
19
+ description: string;
20
+ commands: Record<string, ICommand>;
21
+ }[];
22
+ };
23
+ }
24
+ //#endregion
25
+ export { RepoKitConfig };
@@ -0,0 +1,25 @@
1
+ import { RepoKitCommand } from "./RepoKitCommand.mjs";
2
+
3
+ //#region externals/RepoKitConfig.ts
4
+ var RepoKitConfig = class {
5
+ project;
6
+ thirdParty;
7
+ commands;
8
+ constructor({ project, commands = {}, thirdParty = [] }) {
9
+ this.project = project;
10
+ this.commands = commands;
11
+ this.thirdParty = thirdParty.map((command) => new RepoKitCommand(command));
12
+ }
13
+ toScoped(location) {
14
+ return {
15
+ ...this,
16
+ thirdParty: this.thirdParty.map((command) => ({
17
+ ...command,
18
+ location
19
+ }))
20
+ };
21
+ }
22
+ };
23
+
24
+ //#endregion
25
+ export { RepoKitConfig };
@@ -0,0 +1,9 @@
1
+ //#region externals/TSCompiler.d.ts
2
+ declare class TSCompiler {
3
+ readonly root: string;
4
+ readonly command: string;
5
+ constructor(root: string, command: string);
6
+ compile(path: string): Promise<any>;
7
+ }
8
+ //#endregion
9
+ export { TSCompiler };
@@ -0,0 +1,20 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { transform } from "@swc/core";
3
+
4
+ //#region externals/TSCompiler.ts
5
+ var TSCompiler = class {
6
+ constructor(root, command) {
7
+ this.root = root;
8
+ this.command = command;
9
+ }
10
+ async compile(path) {
11
+ const source = (await readFile(path)).toString();
12
+ const result = await transform(source, { module: { type: "es6" } });
13
+ const config = eval(result.code);
14
+ console.log(config);
15
+ return config;
16
+ }
17
+ };
18
+
19
+ //#endregion
20
+ export { TSCompiler };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,9 @@
1
+ import { CommandParser } from "../CommandParser.mjs";
2
+
3
+ //#region externals/commands/parse_commands.ts
4
+ (async () => {
5
+ await CommandParser.parse();
6
+ })();
7
+
8
+ //#endregion
9
+ export { };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,9 @@
1
+ import { ConfigurationParser } from "../ConfigurationParser.mjs";
2
+
3
+ //#region externals/commands/parse_configuration.ts
4
+ (async () => {
5
+ await ConfigurationParser.parse();
6
+ })();
7
+
8
+ //#endregion
9
+ export { };
@@ -0,0 +1,4 @@
1
+ import { RepoKitCommand } from "./RepoKitCommand.mjs";
2
+ import { AsyncTask, ICommand, ILocatedCommand, IRepoKitCommand, IRepoKitConfig } from "./types.mjs";
3
+ import { RepoKitConfig } from "./RepoKitConfig.mjs";
4
+ export { AsyncTask, ICommand, ILocatedCommand, IRepoKitCommand, IRepoKitConfig, RepoKitCommand, RepoKitConfig };
package/dist/index.mjs ADDED
@@ -0,0 +1,4 @@
1
+ import { RepoKitCommand } from "./RepoKitCommand.mjs";
2
+ import { RepoKitConfig } from "./RepoKitConfig.mjs";
3
+
4
+ export { RepoKitCommand, RepoKitConfig };
@@ -0,0 +1,5 @@
1
+ //#region externals/templates/command_template.txt
2
+ var command_template_default = "import { RepoKitCommand } from \"@repokit/core\";\n\n/**\n * Please fill out this command file with your desired settings\n */\nexport const Commands = new RepoKitCommand({\n name: \"<Your Package Name>\",\n owner: \"<Optional Team or Individual>\",\n description: \"<Your Package Description>\",\n commands: {\n \"<your-first-command>\": {\n command: \"<insert shell command here>\",\n description: \"A description for using your command\",\n },\n \"<your-second-command>\": {\n command: \"<insert shell command here>\",\n description: \"A description for using your command\",\n },\n \"<your-third-command>\": {\n command: \"<insert shell command here>\",\n description: \"A description for using your command\",\n },\n },\n});\n";
3
+
4
+ //#endregion
5
+ export { command_template_default as default };
@@ -0,0 +1,5 @@
1
+ //#region externals/templates/configuration_template.txt
2
+ var configuration_template_default = "import { RepoKitConfig } from \"@repokit/core\";\n\n/**\n * Please fill out this config file with your desired\n * repokit settings\n */\nexport const RepoKit = new RepoKitConfig({\n project: \"Your Project Name\",\n commands: {\n \"<your-first-command>\": {\n command: \"<insert shell command here>\",\n description: \"A description for using your command\",\n },\n \"<your-second-command>\": {\n command: \"<insert shell command here>\",\n description: \"A description for using your command\",\n },\n \"<your-third-command>\": {\n command: \"<insert shell command here>\",\n description: \"A description for using your command\",\n },\n },\n});\n";
3
+
4
+ //#endregion
5
+ export { configuration_template_default as default };
@@ -0,0 +1,25 @@
1
+ import { RepoKitCommand } from "./RepoKitCommand.mjs";
2
+
3
+ //#region externals/types.d.ts
4
+ interface IRepoKitConfig {
5
+ project: string;
6
+ thirdParty?: RepoKitCommand[];
7
+ commands?: Record<string, ICommand>;
8
+ }
9
+ interface IRepoKitCommand {
10
+ name: string;
11
+ owner?: string;
12
+ description: string;
13
+ commands: Record<string, ICommand>;
14
+ }
15
+ interface ICommand {
16
+ command: string;
17
+ description: string;
18
+ args?: Record<string, string>;
19
+ }
20
+ interface ILocatedCommand extends IRepoKitCommand {
21
+ location: string;
22
+ }
23
+ type AsyncTask<T> = () => Promise<T>;
24
+ //#endregion
25
+ export { AsyncTask, ICommand, ILocatedCommand, IRepoKitCommand, IRepoKitConfig };
package/dist/types.mjs ADDED
@@ -0,0 +1 @@
1
+ export { };
@@ -1,27 +1,33 @@
1
1
  import { parseArgs } from "node:util";
2
- import { join } from "node:path";
3
2
  import { stat } from "node:fs/promises";
4
3
  import { existsSync } from "node:fs";
5
4
 
6
5
  import type { ILocatedCommand } from "./types";
7
6
  import { TSCompiler } from "./TSCompiler";
8
7
  import { RepoKitCommand } from "./RepoKitCommand";
8
+ import { ConcurrencyPool } from "./ConcurrencyPool";
9
9
  /* oxlint-disable typescript-eslint(no-misused-spread) */
10
10
 
11
- export class CommandParser extends TSCompiler {
11
+ export class CommandParser {
12
+ private static compiler?: TSCompiler;
13
+
12
14
  public static async parse() {
13
15
  const { paths, root } = this.parsePaths();
14
16
  if (!root || !existsSync(root) || !(await stat(root)).isDirectory()) {
15
17
  return console.log(JSON.stringify([]));
16
18
  }
19
+ this.compiler = new TSCompiler(root, "parse_commands");
20
+ const pool = new ConcurrencyPool<ILocatedCommand[]>();
17
21
  const pathList = paths.split(",").filter(Boolean);
18
- const results = pathList.map(path => this.parseCommand(join(root, path)));
19
- console.log(JSON.stringify(results.flat()));
22
+ const commands = await Promise.all(
23
+ pathList.map(path => pool.enqueue(() => this.parseCommand(path))),
24
+ );
25
+ console.log(JSON.stringify(commands.flat()));
20
26
  }
21
27
 
22
- private static parseCommand(path: string) {
28
+ private static async parseCommand(path: string) {
23
29
  const commands: ILocatedCommand[] = [];
24
- const declaredExports = require(path);
30
+ const declaredExports = await this.compiler?.compile?.(path);
25
31
  for (const key in declaredExports) {
26
32
  if (declaredExports[key] instanceof RepoKitCommand) {
27
33
  commands.push({ ...declaredExports[key], location: path });
@@ -0,0 +1,24 @@
1
+ import { AutoIncrementingID } from "@figliolia/event-emitter";
2
+
3
+ import type { AsyncTask } from "./types";
4
+
5
+ export class ConcurrencyPool<T> {
6
+ private readonly IDs = new AutoIncrementingID();
7
+ private readonly activeTasks = new Map<string, Promise<T>>();
8
+ constructor(public readonly maxConcurrency: number = 10) {}
9
+
10
+ public async enqueue(task: AsyncTask<T>) {
11
+ if (this.activeTasks.size === this.maxConcurrency) {
12
+ await Promise.race(Array.from(this.activeTasks.values()));
13
+ }
14
+ return this.executeTask(task);
15
+ }
16
+
17
+ private executeTask(task: AsyncTask<T>) {
18
+ const ID = this.IDs.get();
19
+ const promise = task();
20
+ this.activeTasks.set(ID, promise);
21
+ void promise.finally(() => this.activeTasks.delete(ID));
22
+ return promise;
23
+ }
24
+ }
@@ -6,13 +6,14 @@ import { TSCompiler } from "./TSCompiler";
6
6
  import { RepoKitConfig } from "./RepoKitConfig";
7
7
 
8
8
  export class ConfigurationParser extends TSCompiler {
9
- public static parse() {
9
+ public static async parse() {
10
10
  const root = this.parseRoot();
11
11
  const path = join(root, "repokit.ts");
12
12
  if (!existsSync(path)) {
13
13
  return;
14
14
  }
15
- const config = require(path);
15
+ const compiler = new TSCompiler(root, "parse_configuration");
16
+ const config = await compiler.compile(path);
16
17
  for (const key in config) {
17
18
  if (config[key] instanceof RepoKitConfig) {
18
19
  return console.log(JSON.stringify(config[key].toScoped(path)));
@@ -1,8 +1,26 @@
1
- import { register } from "ts-node";
1
+ import { basename, resolve } from "node:path";
2
+ import { readFile, rm, writeFile } from "node:fs/promises";
3
+
4
+ import { transform } from "@swc/core";
2
5
 
3
6
  export class TSCompiler {
4
- static {
5
- const service = register();
6
- service.enabled(true);
7
+ private static readonly TMP_FILE_NAME = ".repokit_tmp.js";
8
+ constructor(
9
+ public readonly root: string,
10
+ public readonly command: string,
11
+ ) {}
12
+
13
+ public async compile(path: string) {
14
+ const source = (await readFile(path)).toString();
15
+ const result = await transform(source, {
16
+ module: {
17
+ type: "es6",
18
+ },
19
+ });
20
+ const target = `${resolve(path, "../")}/${basename(path)}${TSCompiler.TMP_FILE_NAME}`;
21
+ await writeFile(target, result.code);
22
+ const config = await import(target);
23
+ await rm(target, { force: true });
24
+ return config;
7
25
  }
8
26
  }
@@ -1,3 +1,5 @@
1
1
  import { ConfigurationParser } from "../ConfigurationParser";
2
2
 
3
- ConfigurationParser.parse();
3
+ void (async () => {
4
+ await ConfigurationParser.parse();
5
+ })();
@@ -12,7 +12,14 @@ impl Configuration {
12
12
  let file_path = format!("{root}/repokit.ts");
13
13
  let path = Path::new(&file_path);
14
14
  if path.exists() {
15
- return;
15
+ Logger::info(
16
+ format!(
17
+ "I found a Repokit configuration without an exported {} instance",
18
+ Logger::blue("RepokitConfig")
19
+ )
20
+ .as_str(),
21
+ );
22
+ return Logger::exit_with_info("Please create an instance and export it");
16
23
  }
17
24
  Configuration::welcome();
18
25
  let mut source =
@@ -22,8 +22,7 @@ impl TypescriptCommand {
22
22
  }
23
23
 
24
24
  pub fn parse_configuration(&self) -> RepoKitConfig {
25
- let executable =
26
- InternalFileSystem::new(&self.root).resolve_command("parse_configuration.js");
25
+ let executable = InternalFileSystem::new(&self.root).resolve_command("parse_configuration");
27
26
  let stdout = self.execute(format!("{executable} --root {}", &self.root).as_str());
28
27
  if stdout.is_empty() {
29
28
  Configuration::create(&self.root);
@@ -34,7 +33,7 @@ impl TypescriptCommand {
34
33
 
35
34
  pub fn parse_commands(&self, path_list: &MutexGuard<Vec<String>>) -> Vec<RepoKitCommand> {
36
35
  let paths = path_list.join(",");
37
- let executable = InternalFileSystem::new(&self.root).resolve_command("parse_commands.js");
36
+ let executable = InternalFileSystem::new(&self.root).resolve_command("parse_commands");
38
37
  let stdout =
39
38
  self.execute(format!("{executable} --paths {paths} --root {}", self.root).as_str());
40
39
  let result: Result<Vec<RepoKitCommand>, serde_json::Error> = serde_json::from_str(&stdout);
@@ -25,8 +25,11 @@ impl InternalFileSystem {
25
25
  path.join(segment).normalize()
26
26
  }
27
27
 
28
- pub fn resolve_command(&self, file_name: &str) -> String {
29
- self.path_buf_to_str(self.commands_directory().join(file_name))
28
+ pub fn resolve_command(&self, command_name: &str) -> String {
29
+ self.path_buf_to_str(
30
+ self.commands_directory()
31
+ .join(format!("{command_name}.mjs")),
32
+ )
30
33
  }
31
34
 
32
35
  pub fn resolve_template(&self, file_name: &str) -> File {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@repokit/core",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "A knowledgebase for your repository - wrapped in a CLI",
5
5
  "keywords": [
6
6
  "cli",
@@ -24,9 +24,9 @@
24
24
  "Cargo.lock",
25
25
  "Cargo.toml"
26
26
  ],
27
- "main": "./dist/index.js",
28
- "module": "./dist/index.js",
29
- "types": "./dist/index.d.ts",
27
+ "main": "./dist/index.mjs",
28
+ "module": "./dist/index.mjs",
29
+ "types": "./dist/index.d.mjs",
30
30
  "publishConfig": {
31
31
  "access": "public"
32
32
  },
@@ -47,7 +47,7 @@
47
47
  },
48
48
  "dependencies": {
49
49
  "@figliolia/event-emitter": "^1.2.0",
50
- "ts-node": "^10.9.2"
50
+ "@swc/core": "^1.15.18"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@figliolia/child-process": "^1.0.4",
@@ -55,6 +55,7 @@
55
55
  "oxfmt": "^0.34.0",
56
56
  "oxlint": "^1.42.0",
57
57
  "oxlint-tsgolint": "^0.14.0",
58
+ "tsdown": "^0.20.3",
58
59
  "tsx": "^4.21.0",
59
60
  "typescript": "^5.9.3"
60
61
  }
@@ -1,6 +0,0 @@
1
- import { TSCompiler } from "./TSCompiler";
2
- export declare class CommandParser extends TSCompiler {
3
- static parse(): Promise<void>;
4
- private static parseCommand;
5
- private static parsePaths;
6
- }
@@ -1,55 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CommandParser = void 0;
4
- const node_util_1 = require("node:util");
5
- const node_path_1 = require("node:path");
6
- const promises_1 = require("node:fs/promises");
7
- const node_fs_1 = require("node:fs");
8
- const TSCompiler_1 = require("./TSCompiler");
9
- const RepoKitCommand_1 = require("./RepoKitCommand");
10
- /* oxlint-disable typescript-eslint(no-misused-spread) */
11
- class CommandParser extends TSCompiler_1.TSCompiler {
12
- static async parse() {
13
- const { paths, root } = this.parsePaths();
14
- if (!root || !(0, node_fs_1.existsSync)(root) || !(await (0, promises_1.stat)(root)).isDirectory()) {
15
- return console.log(JSON.stringify([]));
16
- }
17
- const pathList = paths.split(",").filter(Boolean);
18
- const results = pathList.map(path => this.parseCommand((0, node_path_1.join)(root, path)));
19
- console.log(JSON.stringify(results.flat()));
20
- }
21
- static parseCommand(path) {
22
- const commands = [];
23
- const declaredExports = require(path);
24
- for (const key in declaredExports) {
25
- if (declaredExports[key] instanceof RepoKitCommand_1.RepoKitCommand) {
26
- commands.push({ ...declaredExports[key], location: path });
27
- }
28
- }
29
- return commands;
30
- }
31
- static parsePaths() {
32
- try {
33
- return (0, node_util_1.parseArgs)({
34
- options: {
35
- paths: {
36
- default: "",
37
- multiple: false,
38
- short: "p",
39
- type: "string",
40
- },
41
- root: {
42
- default: "",
43
- multiple: false,
44
- short: "r",
45
- type: "string",
46
- },
47
- },
48
- }).values;
49
- }
50
- catch {
51
- return { paths: "", root: "" };
52
- }
53
- }
54
- }
55
- exports.CommandParser = CommandParser;
@@ -1,5 +0,0 @@
1
- import { TSCompiler } from "./TSCompiler";
2
- export declare class ConfigurationParser extends TSCompiler {
3
- static parse(): void;
4
- private static parseRoot;
5
- }
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConfigurationParser = void 0;
4
- const node_util_1 = require("node:util");
5
- const node_path_1 = require("node:path");
6
- const node_fs_1 = require("node:fs");
7
- const TSCompiler_1 = require("./TSCompiler");
8
- const RepoKitConfig_1 = require("./RepoKitConfig");
9
- class ConfigurationParser extends TSCompiler_1.TSCompiler {
10
- static parse() {
11
- const root = this.parseRoot();
12
- const path = (0, node_path_1.join)(root, "repokit.ts");
13
- if (!(0, node_fs_1.existsSync)(path)) {
14
- return;
15
- }
16
- const config = require(path);
17
- for (const key in config) {
18
- if (config[key] instanceof RepoKitConfig_1.RepoKitConfig) {
19
- return console.log(JSON.stringify(config[key].toScoped(path)));
20
- }
21
- }
22
- }
23
- static parseRoot() {
24
- return (0, node_util_1.parseArgs)({
25
- options: {
26
- root: {
27
- default: "",
28
- multiple: false,
29
- short: "r",
30
- type: "string",
31
- },
32
- },
33
- }).values.root;
34
- }
35
- }
36
- exports.ConfigurationParser = ConfigurationParser;
@@ -1,8 +0,0 @@
1
- import type { ICommand, IRepoKitCommand } from "./types";
2
- export declare class RepoKitCommand {
3
- name: string;
4
- owner: string;
5
- description: string;
6
- commands: Record<string, ICommand>;
7
- constructor({ name, description, owner, commands, }: IRepoKitCommand);
8
- }
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RepoKitCommand = void 0;
4
- class RepoKitCommand {
5
- name;
6
- owner;
7
- description;
8
- commands;
9
- constructor({ name, description, owner = "", commands = {}, }) {
10
- this.name = name;
11
- this.owner = owner;
12
- this.commands = commands;
13
- this.description = description;
14
- }
15
- }
16
- exports.RepoKitCommand = RepoKitCommand;
@@ -1,17 +0,0 @@
1
- import type { ICommand, IRepoKitConfig } from "./types";
2
- import { RepoKitCommand } from "./RepoKitCommand";
3
- export declare class RepoKitConfig implements Required<IRepoKitConfig> {
4
- project: string;
5
- thirdParty: RepoKitCommand[];
6
- commands: Record<string, ICommand>;
7
- constructor({ project, commands, thirdParty }: IRepoKitConfig);
8
- toScoped(location: string): this & {
9
- thirdParty: {
10
- location: string;
11
- name: string;
12
- owner: string;
13
- description: string;
14
- commands: Record<string, ICommand>;
15
- }[];
16
- };
17
- }
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RepoKitConfig = void 0;
4
- const RepoKitCommand_1 = require("./RepoKitCommand");
5
- /* eslint-disable typescript-eslint(no-misused-spread */
6
- class RepoKitConfig {
7
- project;
8
- thirdParty;
9
- commands;
10
- constructor({ project, commands = {}, thirdParty = [] }) {
11
- this.project = project;
12
- this.commands = commands;
13
- this.thirdParty = thirdParty.map(command => new RepoKitCommand_1.RepoKitCommand(command));
14
- }
15
- toScoped(location) {
16
- return {
17
- ...this,
18
- thirdParty: this.thirdParty.map(command => ({ ...command, location })),
19
- };
20
- }
21
- }
22
- exports.RepoKitConfig = RepoKitConfig;
@@ -1,2 +0,0 @@
1
- export declare class TSCompiler {
2
- }
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TSCompiler = void 0;
4
- const ts_node_1 = require("ts-node");
5
- class TSCompiler {
6
- static {
7
- const service = (0, ts_node_1.register)();
8
- service.enabled(true);
9
- }
10
- }
11
- exports.TSCompiler = TSCompiler;
@@ -1 +0,0 @@
1
- export {};
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const CommandParser_1 = require("../CommandParser");
4
- void (async () => {
5
- await CommandParser_1.CommandParser.parse();
6
- })();
@@ -1 +0,0 @@
1
- export {};
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const ConfigurationParser_1 = require("../ConfigurationParser");
4
- ConfigurationParser_1.ConfigurationParser.parse();
package/dist/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from "./RepoKitConfig";
2
- export * from "./RepoKitCommand";
3
- export * from "./types";
package/dist/index.js DELETED
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./RepoKitConfig"), exports);
18
- __exportStar(require("./RepoKitCommand"), exports);
19
- __exportStar(require("./types"), exports);
package/dist/types.d.ts DELETED
@@ -1,21 +0,0 @@
1
- import type { RepoKitCommand } from "./RepoKitCommand";
2
- export interface IRepoKitConfig {
3
- project: string;
4
- thirdParty?: RepoKitCommand[];
5
- commands?: Record<string, ICommand>;
6
- }
7
- export interface IRepoKitCommand {
8
- name: string;
9
- owner?: string;
10
- description: string;
11
- commands: Record<string, ICommand>;
12
- }
13
- export interface ICommand {
14
- command: string;
15
- description: string;
16
- args?: Record<string, string>;
17
- }
18
- export interface ILocatedCommand extends IRepoKitCommand {
19
- location: string;
20
- }
21
- export type AsyncTask<T> = () => Promise<T>;
package/dist/types.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });