@tui-sandbox/library 11.3.2 → 11.3.3

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": "@tui-sandbox/library",
3
- "version": "11.3.2",
3
+ "version": "11.3.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/mikavilpas/tui-sandbox"
@@ -0,0 +1,22 @@
1
+ import { parseArguments } from "./parseArguments.js"
2
+
3
+ it(`can parse "neovim prepare"`, async () => {
4
+ expect(await parseArguments(["neovim", "prepare"])).toEqual({ action: "neovim prepare" })
5
+ expect(await parseArguments(["neovim", "prepare", "foo"])).toBeUndefined()
6
+ })
7
+
8
+ describe("neovim exec", () => {
9
+ it(`can parse "neovim exec <command>"`, async () => {
10
+ expect(await parseArguments(["neovim", "exec", "foo"])).toEqual({ action: "neovim exec", command: "foo" })
11
+ })
12
+
13
+ it(`only allows one argument`, async () => {
14
+ expect(await parseArguments(["neovim", "exec"])).toBeUndefined()
15
+ expect(await parseArguments(["neovim", "exec", "foo", "bar"])).toBeUndefined()
16
+ })
17
+ })
18
+
19
+ it(`can parse "start"`, async () => {
20
+ expect(await parseArguments(["start"])).toEqual({ action: "start" })
21
+ expect(await parseArguments(["start", "foo"])).toBeUndefined()
22
+ })
@@ -0,0 +1,48 @@
1
+ import assert from "assert"
2
+ import * as z from "zod"
3
+
4
+ export const parseArguments = async (args: string[]): Promise<ParseArgumentsResult | undefined> => {
5
+ {
6
+ // tui neovim prepare
7
+ const schema = z.tuple([z.literal("neovim"), z.literal("prepare")])
8
+ const prepareArguments = schema.safeParse(args)
9
+ if (prepareArguments.success) {
10
+ return {
11
+ action: "neovim prepare",
12
+ }
13
+ }
14
+ }
15
+
16
+ {
17
+ // tui neovim exec <command> [<args>...]
18
+ const schema = z.tuple([z.literal("neovim"), z.literal("exec"), z.string()])
19
+ const execArguments = schema.safeParse(args)
20
+ if (execArguments.success) {
21
+ const command = execArguments.data.at(2)
22
+ assert(command, "No command provided for neovim exec")
23
+ return {
24
+ action: "neovim exec",
25
+ command,
26
+ }
27
+ }
28
+ }
29
+
30
+ {
31
+ // tui start
32
+ const schema = z.tuple([z.literal("start")])
33
+ const result = schema.safeParse(args)
34
+ if (result.success) {
35
+ return {
36
+ action: "start",
37
+ }
38
+ }
39
+ }
40
+ }
41
+
42
+ export type ParseArgumentsResult =
43
+ | { action: "neovim prepare" }
44
+ | {
45
+ action: "neovim exec"
46
+ command: string
47
+ }
48
+ | { action: "start" }
@@ -1,4 +1,3 @@
1
- import assert from "node:assert"
2
1
  import path from "node:path"
3
2
  import { installDependencies } from "../server/applications/neovim/api.js"
4
3
  import type { StdoutOrStderrMessage } from "../server/applications/neovim/NeovimApplication.js"
@@ -7,6 +6,7 @@ import { prepareNewTestDirectory } from "../server/applications/neovim/prepareNe
7
6
  import { createCypressSupportFile } from "../server/cypress-support/createCypressSupportFile.js"
8
7
  import type { TestServerConfig } from "../server/index.js"
9
8
  import { startTestServer, updateTestdirectorySchemaFile } from "../server/index.js"
9
+ import { parseArguments } from "./parseArguments.js"
10
10
 
11
11
  //
12
12
  // This is the main entrypoint to tui-sandbox
@@ -28,8 +28,10 @@ const config = {
28
28
  // the arguments passed to this script start at index 2
29
29
  const args = process.argv.slice(2)
30
30
 
31
- if (args[0] === "neovim") {
32
- if (args[1] === "prepare" && args.length === 2) {
31
+ const command = await parseArguments(args)
32
+
33
+ switch (command?.action) {
34
+ case "neovim prepare": {
33
35
  const NVIM_APPNAME = process.env["NVIM_APPNAME"]
34
36
  console.log(`🚀 Installing neovim dependencies${NVIM_APPNAME ? ` for NVIM_APPNAME=${NVIM_APPNAME}` : ""}...`)
35
37
  await installDependencies(
@@ -42,15 +44,7 @@ if (args[0] === "neovim") {
42
44
  })
43
45
  process.exit(0)
44
46
  }
45
-
46
- if (!(args[1] === "exec" && args.length === 3)) {
47
- showUsageAndExit()
48
- }
49
-
50
- const command = args[2]
51
- assert(command, "No command provided")
52
-
53
- {
47
+ case "neovim exec": {
54
48
  // automatically dispose of the neovim instance when done
55
49
  await using app = new NeovimApplication(config.directories.testEnvironmentPath)
56
50
  app.events.on("stdout" satisfies StdoutOrStderrMessage, data => {
@@ -61,41 +55,42 @@ if (args[0] === "neovim") {
61
55
  testDirectory,
62
56
  {
63
57
  filename: "empty.txt",
64
- headlessCmd: command,
58
+ headlessCmd: command.command,
65
59
  NVIM_APPNAME: process.env["NVIM_APPNAME"],
66
60
  },
67
61
  { cols: 80, rows: 24 }
68
62
  )
69
63
  await app.application.untilExit()
64
+ break
70
65
  }
66
+ case "start": {
67
+ try {
68
+ await createCypressSupportFile({
69
+ cypressSupportDirectoryPath: path.join(cwd, "cypress", "support"),
70
+ supportFileName: "tui-sandbox.ts",
71
+ })
72
+ } catch (e) {
73
+ console.error("Failed to createCypressSupportFile", e)
74
+ }
71
75
 
72
- process.exit(0)
73
- }
74
-
75
- if (args[0] !== "start") {
76
- showUsageAndExit()
77
- }
78
- console.log(`🚀 Starting test server in ${cwd} - this should be the root of your integration-tests directory 🤞🏻`)
79
-
80
- try {
81
- await createCypressSupportFile({
82
- cypressSupportDirectoryPath: path.join(cwd, "cypress", "support"),
83
- supportFileName: "tui-sandbox.ts",
84
- })
85
- } catch (e) {
86
- console.error("Failed to createCypressSupportFile", e)
87
- }
88
-
89
- try {
90
- await updateTestdirectorySchemaFile(config.directories)
91
- } catch (e) {
92
- console.error("Failed to updateTestdirectorySchemaFile", e)
93
- }
76
+ try {
77
+ await updateTestdirectorySchemaFile(config.directories)
78
+ } catch (e) {
79
+ console.error("Failed to updateTestdirectorySchemaFile", e)
80
+ }
94
81
 
95
- try {
96
- await startTestServer(config)
97
- } catch (e) {
98
- console.error("Failed to startTestServer", e)
82
+ try {
83
+ console.log(`🚀 Starting test server in ${cwd} - this should be the root of your integration-tests directory 🤞🏻`)
84
+ await startTestServer(config)
85
+ } catch (e) {
86
+ console.error("Failed to startTestServer", e)
87
+ }
88
+ break
89
+ }
90
+ default: {
91
+ command satisfies undefined
92
+ showUsageAndExit()
93
+ }
99
94
  }
100
95
 
101
96
  function showUsageAndExit() {
@@ -105,6 +100,7 @@ function showUsageAndExit() {
105
100
  `Usage (pick one):`,
106
101
  ` tui start`,
107
102
  ` tui neovim exec '<ex-command>'`,
103
+ ` tui neovim prepare`,
108
104
  ].join("\n")
109
105
  )
110
106