@vlandoss/run-run 0.0.7 → 0.0.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vlandoss/run-run",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "The CLI toolbox to fullstack common scripts in Variable Land",
5
5
  "homepage": "https://github.com/variableland/dx/tree/main/packages/run-run#readme",
6
6
  "bugs": {
package/src/main.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import { isProcessOutput } from "@vlandoss/clibuddy";
2
2
  import { createProgram, type Options } from "./program";
3
+ import { parseArgs } from "./program/parse-args";
3
4
  import { logger } from "./services/logger";
4
5
 
5
6
  export async function main(options: Options) {
6
7
  try {
7
- const { cmd } = await createProgram(options);
8
- await cmd.parseAsync();
8
+ const { program } = await createProgram(options);
9
+ await program.parseAsync(parseArgs(), { from: "user" });
9
10
  } catch (error) {
10
11
  if (!isProcessOutput(error)) {
11
12
  logger.error("Cannot run main successfully", error);
@@ -3,7 +3,7 @@
3
3
  exports[`should match command: "help" 1`] = `
4
4
  "🦊 R U N - R U N: The CLI toolbox to fullstack common scripts in Variable Land 👊
5
5
 
6
- Usage: rr|run-run [options] [command]
6
+ Usage: rr|run-run [options] <command...>
7
7
 
8
8
  Options:
9
9
  -v, --version output the version number
@@ -30,7 +30,7 @@ Acknowledgment:
30
30
  exports[`should match command: "--help" 1`] = `
31
31
  "🦊 R U N - R U N: The CLI toolbox to fullstack common scripts in Variable Land 👊
32
32
 
33
- Usage: rr|run-run [options] [command]
33
+ Usage: rr|run-run [options] <command...>
34
34
 
35
35
  Options:
36
36
  -v, --version output the version number
@@ -64,6 +64,17 @@ exports[`should match command: "-v" 1`] = `
64
64
  "
65
65
  `;
66
66
 
67
+ exports[`should match help message for command "run" 1`] = `
68
+ "Usage: rr run [options] <cmds...>
69
+
70
+ Arguments:
71
+ cmds commands to execute in sequence (e.g. 'check tsc')
72
+
73
+ Options:
74
+ -h, --help display help for command
75
+ "
76
+ `;
77
+
67
78
  exports[`should match help message for command "check" 1`] = `
68
79
  "Usage: rr check|test:static [options]
69
80
 
@@ -145,11 +156,3 @@ Commands:
145
156
  help [command] display help for command
146
157
  "
147
158
  `;
148
-
149
- exports[`should match "check" command 1`] = `"biome check --colors=force"`;
150
-
151
- exports[`should match "lint" command 1`] = `"biome check --colors=force --formatter-enabled=false"`;
152
-
153
- exports[`should match "fmt" command 1`] = `"biome format --no-errors-on-unmatched --colors=force"`;
154
-
155
- exports[`should match "tsc" command 1`] = `"tsc --noEmit"`;
@@ -1,7 +1,7 @@
1
1
  import { afterEach, expect, test } from "bun:test";
2
- import { createTestProgram, execCli, mocked, parseProgram } from "test/helpers";
2
+ import { createTestProgram, execCli, mocked } from "test/helpers";
3
3
 
4
- const { cmd, ctx } = await createTestProgram();
4
+ const { program, ctx } = await createTestProgram();
5
5
  const $ = ctx.shell.$;
6
6
 
7
7
  const rootCommands = ["help", "--help", "--version", "-v"];
@@ -18,7 +18,7 @@ for (const cmd of rootCommands) {
18
18
  });
19
19
  }
20
20
 
21
- for (const command of cmd.commands) {
21
+ for (const command of program.commands) {
22
22
  const cmd = command.name();
23
23
 
24
24
  test(`should match help message for command "${cmd}"`, async () => {
@@ -27,21 +27,3 @@ for (const command of cmd.commands) {
27
27
  expect(stdout).toMatchSnapshot();
28
28
  });
29
29
  }
30
-
31
- const hardCommands = ["info:pkg", "clean", "tools"];
32
-
33
- const easyTesteableCommands = cmd.commands.filter((command) => {
34
- const isHard = hardCommands.some((cmd) => command.name() === cmd);
35
- return !isHard;
36
- });
37
-
38
- for (const command of easyTesteableCommands) {
39
- const cmd = command.name();
40
-
41
- test(`should match "${cmd}" command`, async () => {
42
- await parseProgram([cmd]);
43
-
44
- expect($).toHaveBeenCalledTimes(1);
45
- expect(mocked($).mock.results[0]?.value).toMatchSnapshot();
46
- });
47
- }
@@ -0,0 +1,14 @@
1
+ import { createCommand } from "commander";
2
+ import type { Context } from "~/services/ctx";
3
+
4
+ export function createRunCommand(ctx: Context) {
5
+ const program = createCommand("run")
6
+ .argument("<cmds...>", "commands to execute in sequence (e.g. 'check tsc')")
7
+ .action(async function runRunAction(cmds: string[]) {
8
+ const { $ } = ctx.shell;
9
+ const commands = cmds.map((cmd) => $`rr ${cmd}`);
10
+ await Promise.all(commands);
11
+ });
12
+
13
+ return program;
14
+ }
@@ -10,9 +10,11 @@ export function createTypecheckCommand(ctx: Context) {
10
10
  .action(async function typecheckAction() {
11
11
  const { appPkg, shell } = ctx;
12
12
 
13
- async function singleTypecheck(dir?: string): Promise<boolean | undefined> {
13
+ async function singleTypecheck(dir?: string, options?: { logger?: typeof logger }): Promise<boolean | undefined> {
14
+ const log = options?.logger ?? logger;
15
+
14
16
  if (!appPkg.hasFile("tsconfig.json", dir)) {
15
- logger.info("No tsconfig.json found, skipping typecheck");
17
+ log.info("No tsconfig.json found, skipping typecheck");
16
18
  return;
17
19
  }
18
20
 
@@ -34,7 +36,9 @@ export function createTypecheckCommand(ctx: Context) {
34
36
  try {
35
37
  childLogger.start("Type checking started");
36
38
 
37
- const success = await singleTypecheck(project.rootDir);
39
+ const success = await singleTypecheck(project.rootDir, {
40
+ logger: childLogger,
41
+ });
38
42
 
39
43
  if (success) {
40
44
  childLogger.success("Typecheck completed");
@@ -1,10 +1,11 @@
1
1
  import { getVersion } from "@vlandoss/clibuddy";
2
- import { Command } from "commander";
2
+ import { createCommand } from "commander";
3
3
  import { createContext } from "~/services/ctx";
4
4
  import { createCheckCommand } from "./commands/check";
5
5
  import { createCleanCommand } from "./commands/clean";
6
6
  import { createFormatCommand } from "./commands/format";
7
7
  import { createLintCommand } from "./commands/lint";
8
+ import { createRunCommand } from "./commands/run";
8
9
  import { createToolsCommand } from "./commands/tools";
9
10
  import { createTypecheckCommand } from "./commands/typecheck";
10
11
  import { BANNER_TEXT, CREDITS_TEXT } from "./ui";
@@ -16,11 +17,15 @@ export type Options = {
16
17
  export async function createProgram(options: Options) {
17
18
  const ctx = await createContext(options.binDir);
18
19
 
19
- const cmd = new Command("rr")
20
+ const program = createCommand("rr")
20
21
  .alias("run-run")
22
+ .usage("[options] <command...>")
21
23
  .version(getVersion(ctx.binPkg), "-v, --version")
22
24
  .addHelpText("before", BANNER_TEXT)
23
25
  .addHelpText("after", CREDITS_TEXT)
26
+ .addCommand(createRunCommand(ctx), {
27
+ hidden: true,
28
+ })
24
29
  .addCommand(createCheckCommand(ctx))
25
30
  .addCommand(createLintCommand(ctx))
26
31
  .addCommand(createFormatCommand(ctx))
@@ -30,5 +35,5 @@ export async function createProgram(options: Options) {
30
35
  hidden: true,
31
36
  });
32
37
 
33
- return { cmd, ctx };
38
+ return { program, ctx };
34
39
  }
@@ -0,0 +1,10 @@
1
+ export function parseArgs(argv = process.argv) {
2
+ const args = argv.slice(2);
3
+ const allArgsAreCommands = args.every((arg) => !arg.startsWith("-"));
4
+
5
+ if (allArgsAreCommands && args.length > 1) {
6
+ return ["run", ...args];
7
+ }
8
+
9
+ return args;
10
+ }