@reliverse/rempts 1.7.15 โ 1.7.17
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/README.md +68 -84
- package/bin/components/launcher/run-command.js +16 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
- ๐ช minimal API surface, maximum expressiveness
|
|
26
26
|
- ๐งช scriptable for testing, stable for production
|
|
27
27
|
- ๐๏ธ no more hacking together `inquirer`/`citty`/`commander`/`chalk`
|
|
28
|
-
- ๐ automatic command creation (`bun dler rempts init
|
|
28
|
+
- ๐ automatic command creation (`bun dler rempts --init cmd1 cmd2`)
|
|
29
|
+
- ๐ฆโ๐ฅ automatic creation of `src/app/cmds.ts` file (`bun dler rempts`)
|
|
29
30
|
|
|
30
31
|
## Installation
|
|
31
32
|
|
|
@@ -37,8 +38,8 @@ bun add @reliverse/rempts
|
|
|
37
38
|
|
|
38
39
|
```bash
|
|
39
40
|
bun add -D @reliverse/dler
|
|
40
|
-
bun dler rempts init
|
|
41
|
-
bun dler rempts
|
|
41
|
+
bun dler rempts --init cmd1 cmd2 # creates `src/app/cmd1/cmd.ts` and `src/app/cmd2/cmd.ts` files
|
|
42
|
+
bun dler rempts # creates `src/app/cmds.ts` file
|
|
42
43
|
```
|
|
43
44
|
|
|
44
45
|
## Usage Examples
|
|
@@ -229,7 +230,7 @@ export default defineCommand({
|
|
|
229
230
|
**Hint**:
|
|
230
231
|
|
|
231
232
|
- Install `bun add -D @reliverse/dler`
|
|
232
|
-
- Use `bun dler rempts init
|
|
233
|
+
- Use `bun dler rempts --init cmd1 cmd2` to init commands for rempts launcher's automatically
|
|
233
234
|
|
|
234
235
|
### Advanced Launcher Usage
|
|
235
236
|
|
|
@@ -307,7 +308,7 @@ await runMain(defineCommand({}));
|
|
|
307
308
|
|
|
308
309
|
```bash
|
|
309
310
|
bun add -D @reliverse/dler
|
|
310
|
-
bun dler rempts init
|
|
311
|
+
bun dler rempts --init my-cmd-1 # or: dler rempts --init my-cmd-1 my-cmd-2 --main src/mod.ts
|
|
311
312
|
# * `--main` is optional, default is `./src/mod.ts`
|
|
312
313
|
# * you can specify multiple commands at once
|
|
313
314
|
```
|
|
@@ -662,111 +663,94 @@ export default defineCommand({
|
|
|
662
663
|
});
|
|
663
664
|
```
|
|
664
665
|
|
|
665
|
-
|
|
666
|
-
// example/launcher/app/minimal/cmd.ts
|
|
667
|
-
|
|
668
|
-
import { relinka } from "@reliverse/relinka";
|
|
669
|
-
import { defineArgs, defineCommand } from "@reliverse/rempts";
|
|
670
|
-
|
|
671
|
-
export default defineCommand({
|
|
672
|
-
meta: {
|
|
673
|
-
name: "minimal",
|
|
674
|
-
description: "hello world",
|
|
675
|
-
},
|
|
676
|
-
args: defineArgs({
|
|
677
|
-
name: {
|
|
678
|
-
type: "string",
|
|
679
|
-
description: "your name",
|
|
680
|
-
required: true,
|
|
681
|
-
},
|
|
682
|
-
}),
|
|
683
|
-
run({ args }) {
|
|
684
|
-
relinka("success", `๐ Hello, ${args.name}!`);
|
|
685
|
-
},
|
|
686
|
-
});
|
|
687
|
-
```
|
|
688
|
-
|
|
689
|
-
**Pro Tips & Best Practices**:
|
|
666
|
+
### Loading Commands with `loadCommand`
|
|
690
667
|
|
|
691
|
-
|
|
692
|
-
- You can use any name for the `cmds.ts` file and store it anywhere, but `src/app/cmds.ts` is a good convention you can follow.
|
|
693
|
-
- Use the async function pattern for lazy loading if you have many commands or care about startup performance.
|
|
694
|
-
- Use eager loading (const) for small CLIs or demos where simplicity is preferred.
|
|
668
|
+
The `loadCommand` utility helps you load command files from your filesystem. It automatically handles:
|
|
695
669
|
|
|
696
|
-
|
|
670
|
+
- Relative paths (both `./build` and `build` work the same)
|
|
671
|
+
- Automatic detection of `cmd.{ts,js}` files
|
|
672
|
+
- Clear error messages when files are not found
|
|
697
673
|
|
|
698
674
|
```ts
|
|
699
|
-
|
|
675
|
+
import { loadCommand } from "@reliverse/rempts";
|
|
700
676
|
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
677
|
+
// These are equivalent:
|
|
678
|
+
const cmd1 = await loadCommand("./build"); // Looks for build/cmd.ts or build/cmd.js
|
|
679
|
+
const cmd2 = await loadCommand("build"); // Same as above
|
|
680
|
+
const cmd3 = await loadCommand("./build/cmd"); // Explicit path to cmd file
|
|
704
681
|
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
// ...more commands
|
|
682
|
+
// You can then use the loaded command with runCmd:
|
|
683
|
+
await runCmd(cmd1, ["--some-flag"]);
|
|
710
684
|
```
|
|
711
685
|
|
|
712
|
-
Usage:
|
|
713
|
-
|
|
714
686
|
```ts
|
|
715
|
-
//
|
|
687
|
+
// src/app/cmds.ts
|
|
688
|
+
export const getBuildCmd = async (): Promise<Command> => loadCommand("./build");
|
|
716
689
|
|
|
717
|
-
|
|
690
|
+
// src/cli.ts
|
|
718
691
|
import { runCmd } from "@reliverse/rempts";
|
|
719
|
-
|
|
720
|
-
await runCmd(await
|
|
721
|
-
// OR:
|
|
722
|
-
// const hooksCmd = await cmdHooks();
|
|
723
|
-
// await runCmd(hooksCmd, ["--flag"]);
|
|
692
|
+
import { getBuildCmd } from "./app/cmds";
|
|
693
|
+
await runCmd(await getBuildCmd(), ["--prod"]);
|
|
724
694
|
```
|
|
725
695
|
|
|
726
|
-
**
|
|
727
|
-
|
|
728
|
-
```ts
|
|
729
|
-
// example/launcher/app/cmds.ts
|
|
730
|
-
export const hooksCmd = (await import("./hooks/cmd.js")).default;
|
|
731
|
-
export const fooCmd = (await import("./foo/cmd.js")).default;
|
|
732
|
-
// ...more commands
|
|
733
|
-
```
|
|
696
|
+
**Error Handling:**
|
|
697
|
+
If the command file is not found, you'll get a clear error message:
|
|
734
698
|
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
await runCmd(hooksCmd, ["--flag"]);
|
|
699
|
+
```bash
|
|
700
|
+
No command file found in /path/to/build. Expected to find either:
|
|
701
|
+
- /path/to/build/cmd.ts
|
|
702
|
+
- /path/to/build/cmd.js
|
|
703
|
+
Please ensure one of these files exists and exports a default command.
|
|
742
704
|
```
|
|
743
705
|
|
|
744
|
-
**
|
|
706
|
+
**Best Practices:**
|
|
745
707
|
|
|
746
|
-
|
|
708
|
+
- Use `loadCommand` when you need to load commands from the filesystem
|
|
709
|
+
- Use `runCmd` to execute the loaded command with arguments
|
|
710
|
+
- Keep your command files in a consistent location (e.g., `src/app/yourCmdName/cmd.ts`)
|
|
711
|
+
- Export commands from a central file like `src/app/cmds.ts` for better organization
|
|
747
712
|
|
|
748
713
|
```ts
|
|
749
|
-
|
|
750
|
-
import {
|
|
714
|
+
// example/launcher/app/cmds.ts
|
|
715
|
+
import { loadCommand } from "@reliverse/rempts";
|
|
751
716
|
|
|
752
|
-
|
|
753
|
-
|
|
717
|
+
export async function getBuildCmd() {
|
|
718
|
+
return loadCommand("./build");
|
|
719
|
+
}
|
|
754
720
|
|
|
755
|
-
|
|
721
|
+
export async function getDeployCmd() {
|
|
722
|
+
return loadCommand("./deploy");
|
|
723
|
+
}
|
|
756
724
|
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
await
|
|
725
|
+
// Usage:
|
|
726
|
+
import { getBuildCmd } from "./cmds";
|
|
727
|
+
const buildCmd = await getBuildCmd();
|
|
728
|
+
await runCmd(buildCmd, ["--prod"]);
|
|
760
729
|
```
|
|
761
730
|
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
**Performance Note:**
|
|
731
|
+
```ts
|
|
732
|
+
// example/launcher/app/minimal/cmd.ts
|
|
765
733
|
|
|
766
|
-
|
|
767
|
-
|
|
734
|
+
import { relinka } from "@reliverse/relinka";
|
|
735
|
+
import { defineArgs, defineCommand } from "@reliverse/rempts";
|
|
768
736
|
|
|
769
|
-
|
|
737
|
+
export default defineCommand({
|
|
738
|
+
meta: {
|
|
739
|
+
name: "minimal",
|
|
740
|
+
description: "hello world",
|
|
741
|
+
},
|
|
742
|
+
args: defineArgs({
|
|
743
|
+
name: {
|
|
744
|
+
type: "string",
|
|
745
|
+
description: "your name",
|
|
746
|
+
required: true,
|
|
747
|
+
},
|
|
748
|
+
}),
|
|
749
|
+
run({ args }) {
|
|
750
|
+
relinka("success", `๐ Hello, ${args.name}!`);
|
|
751
|
+
},
|
|
752
|
+
});
|
|
753
|
+
```
|
|
770
754
|
|
|
771
755
|
## Argument Types: Usage Comparison
|
|
772
756
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { resolve } from "@reliverse/pathkit";
|
|
1
|
+
import { resolve, dirname } from "@reliverse/pathkit";
|
|
2
2
|
import fs from "@reliverse/relifso";
|
|
3
3
|
import { relinka } from "@reliverse/relinka";
|
|
4
4
|
import { createJiti } from "jiti";
|
|
5
|
+
import process from "node:process";
|
|
5
6
|
const jiti = createJiti(import.meta.url, {
|
|
6
7
|
debug: process.env.NODE_ENV === "development",
|
|
7
8
|
fsCache: true,
|
|
@@ -9,8 +10,21 @@ const jiti = createJiti(import.meta.url, {
|
|
|
9
10
|
});
|
|
10
11
|
export async function loadCommand(cmdPath) {
|
|
11
12
|
try {
|
|
13
|
+
const err = new Error();
|
|
14
|
+
const stack = err.stack?.split("\n");
|
|
15
|
+
let callerFile;
|
|
16
|
+
if (stack) {
|
|
17
|
+
for (const line of stack) {
|
|
18
|
+
const match = /\((.*):(\d+):(\d+)\)/.exec(line) || /at (.*):(\d+):(\d+)/.exec(line);
|
|
19
|
+
if (match?.[1] && !match[1].includes("run-command")) {
|
|
20
|
+
callerFile = match[1];
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const callerDir = callerFile ? dirname(callerFile) : process.cwd();
|
|
12
26
|
const normalizedPath = cmdPath.replace(/^\.\//, "");
|
|
13
|
-
const resolvedPath =
|
|
27
|
+
const resolvedPath = resolve(callerDir, normalizedPath);
|
|
14
28
|
if (!resolvedPath.endsWith("cmd.ts") && !resolvedPath.endsWith("cmd.js")) {
|
|
15
29
|
const possiblePaths = [
|
|
16
30
|
resolve(resolvedPath, "cmd.ts"),
|