Skip to content

Commit a0ff8a1

Browse files
committed
refactor: move ShortcutManager types to the types/common file
1 parent 7cfb4b2 commit a0ff8a1

File tree

3 files changed

+47
-57
lines changed

3 files changed

+47
-57
lines changed

README.md

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,7 @@ const devServer = new DevServer(appRoot, {
5050
pattern: 'resources/views/**/*.edge',
5151
reloadServer: false,
5252
}
53-
],
54-
55-
/**
56-
* The assets bundler process to start
57-
*/
58-
assets: {
59-
enabled: true,
60-
name: 'vite',
61-
cmd: 'vite',
62-
args: []
63-
}
53+
]
6454
})
6555

6656
devServer.onError((error) => {
@@ -87,9 +77,6 @@ await devServer.start()
8777
## Test runner
8878
The `TestRunner` is used to execute the `bin/test.ts` file of your AdonisJS application. Like the `DevServer`, the `TestRunner` allows you to watch for file changes and re-run the tests. The following steps are taken to re-run tests in watch mode.
8979

90-
> [!NOTE]
91-
> Read [Using a file watcher](#using-a-file-watcher) section to understand which files are watched by the file watcher.
92-
9380
- If the changed file is a test file, only tests for that file will be re-run.
9481
- Otherwise, all tests will re-run with respect to the initial filters applied when running the `node ace test` command.
9582

@@ -176,17 +163,6 @@ const bundler = new Bundler(appRoot, ts, {
176163
reloadServer: false,
177164
}
178165
],
179-
180-
/**
181-
* The assets bundler to use to bundle the frontend
182-
* assets
183-
*/
184-
assets: {
185-
enabled: true,
186-
name: 'vite',
187-
cmd: 'vite',
188-
args: ['build']
189-
}
190166
})
191167
```
192168

src/shortcuts_manager.ts

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,12 @@
77
* file that was distributed with this source code.
88
*/
99

10-
import type { Logger } from '@poppinss/cliui'
11-
12-
/**
13-
* Keyboard shortcut definition
14-
*/
15-
export interface KeyboardShortcut {
16-
key: string
17-
description: string
18-
handler: () => void
19-
}
20-
21-
/**
22-
* Callbacks for keyboard shortcuts actions
23-
*/
24-
export interface KeyboardShortcutsCallbacks {
25-
onRestart: () => void
26-
onClear: () => void
27-
onQuit: () => void
28-
}
29-
30-
/**
31-
* Shortcuts manager options
32-
*/
33-
export interface ShortcutsManagerOptions {
34-
logger: Logger
35-
callbacks: KeyboardShortcutsCallbacks
36-
}
10+
import { type Logger } from '@poppinss/cliui'
11+
import {
12+
type ShortcutsManagerOptions,
13+
type KeyboardShortcut,
14+
type KeyboardShortcutsCallbacks,
15+
} from './types/common.ts'
3716

3817
/**
3918
* Manages keyboard shortcuts for development server
@@ -90,10 +69,11 @@ export class ShortcutsManager {
9069
* Initialize keyboard shortcuts
9170
*/
9271
setup() {
93-
if (!process.stdin.isTTY) return
72+
if (!process.stdin.isTTY) {
73+
return
74+
}
9475

9576
process.stdin.setRawMode(true)
96-
9777
this.#keyPressHandler = (data: Buffer) => this.#handleKeyPress(data.toString())
9878
process.stdin.on('data', this.#keyPressHandler)
9979
}
@@ -103,10 +83,14 @@ export class ShortcutsManager {
10383
*/
10484
#handleKeyPress(key: string) {
10585
// Handle Ctrl+C (0x03) and Ctrl+D (0x04)
106-
if (key === '\u0003' || key === '\u0004') return this.#callbacks.onQuit()
86+
if (key === '\u0003' || key === '\u0004') {
87+
return this.#callbacks.onQuit()
88+
}
10789

10890
const shortcut = this.#shortcuts.find((s) => s.key === key)
109-
if (shortcut) shortcut.handler()
91+
if (shortcut) {
92+
shortcut.handler()
93+
}
11094
}
11195

11296
/**
@@ -134,7 +118,9 @@ export class ShortcutsManager {
134118
* Cleanup keyboard shortcuts
135119
*/
136120
cleanup() {
137-
if (!process.stdin.isTTY) return
121+
if (!process.stdin.isTTY) {
122+
return
123+
}
138124

139125
process.stdin.setRawMode(false)
140126
process.stdin.removeListener('data', this.#keyPressHandler!)

src/types/common.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* file that was distributed with this source code.
88
*/
99

10+
import type { Logger } from '@poppinss/cliui'
11+
1012
import {
1113
type BundlerHooks,
1214
type DevServerHooks,
@@ -186,3 +188,29 @@ export type TestRunnerOptions = {
186188
* Options accepted by the project bundler
187189
*/
188190
export type BundlerOptions = AssemblerRcFile
191+
192+
/**
193+
* Keyboard shortcut definition
194+
*/
195+
export interface KeyboardShortcut {
196+
key: string
197+
description: string
198+
handler: () => void
199+
}
200+
201+
/**
202+
* Callbacks for keyboard shortcuts actions
203+
*/
204+
export interface KeyboardShortcutsCallbacks {
205+
onRestart: () => void
206+
onClear: () => void
207+
onQuit: () => void
208+
}
209+
210+
/**
211+
* Shortcuts manager options
212+
*/
213+
export interface ShortcutsManagerOptions {
214+
logger: Logger
215+
callbacks: KeyboardShortcutsCallbacks
216+
}

0 commit comments

Comments
 (0)