File tree 1 file changed +5
-18
lines changed
1 file changed +5
-18
lines changed Original file line number Diff line number Diff line change 1
- import { execSync } from 'node:child_process ' ;
1
+ import fs from 'node:fs ' ;
2
2
import express from 'express' ;
3
- import chokidar from 'chokidar' ;
4
3
5
4
/**
6
- * Host a static local server using the specified directory as root
5
+ * Starts a static local server
7
6
* @param root Root directory
8
7
* @param options Server options
9
8
*/
@@ -12,27 +11,15 @@ function server(root: string, options: {
12
11
* Port to listen on
13
12
*/
14
13
port : number ;
15
- /**
16
- * Watch directory
17
- */
18
- watch ?: string ;
19
- /**
20
- * Command to run on change
21
- */
22
- command ?: string ;
23
14
} ) {
15
+ if ( ! fs . lstatSync ( root ) . isDirectory ( ) )
16
+ throw new Error ( 'Root must be a directory' ) ;
17
+
24
18
const app = express ( ) ;
25
19
app . use ( express . static ( root ) ) ;
26
20
app . listen ( options . port , ( ) => {
27
21
console . log ( `Server is listening on http://localhost:${ options . port } /` ) ;
28
22
} ) ;
29
-
30
- chokidar . watch ( options . watch ?? root ) . on ( 'change' , ( path ) => {
31
- if ( options . command )
32
- execSync ( options . command . replace ( / \$ p a t h / g, path ) , {
33
- stdio : 'inherit' ,
34
- } ) ;
35
- } ) ;
36
23
}
37
24
38
25
export default server ;
You can’t perform that action at this time.
0 commit comments