4
4
debounce,
5
5
getIp,
6
6
deleteFolderRecursive,
7
- readJSONFile ,
7
+ readJSONCFile ,
8
8
} = require ( './util' ) ;
9
9
const path = require ( 'path' ) ;
10
+ const fs = require ( 'fs' ) ;
10
11
11
12
function run ( ) {
12
13
const [ runCmd , tscArgs , runArgs , isCleanDirectory ] = parseArgs ( process . argv ) ;
@@ -16,19 +17,30 @@ function run() {
16
17
const projectIndex = tscArgs . findIndex ( arg => arg === '--project' ) ;
17
18
if ( projectIndex !== - 1 ) {
18
19
const projectPath = tscArgs [ projectIndex + 1 ] ;
19
- const tsconfig = readJSONFile ( path . resolve ( cwd , projectPath ) ) ;
20
- outDir = tsconfig . compilerOptions . outDir ;
20
+ const tsconfig = readJSONCFile ( path . resolve ( cwd , projectPath ) ) ;
21
+ if ( tsconfig . compilerOptions ) {
22
+ outDir = tsconfig . compilerOptions . outDir ;
23
+ }
21
24
} else {
22
25
const outDirIndex = tscArgs . findIndex ( arg => arg === '--outDir' ) ;
23
26
if ( outDirIndex !== - 1 ) {
24
27
outDir = tscArgs [ outDirIndex + 1 ] ;
25
28
} else {
26
- const tsconfig = readJSONFile ( path . resolve ( cwd , 'tsconfig.json' ) ) ;
27
- outDir = tsconfig . compilerOptions . outDir ;
29
+ const tsconfig = readJSONCFile ( path . resolve ( cwd , 'tsconfig.json' ) ) ;
30
+ if ( tsconfig . compilerOptions ) {
31
+ outDir = tsconfig . compilerOptions . outDir ;
32
+ }
28
33
}
29
34
}
30
35
31
- runArgs . push ( '--baseDir' , path . resolve ( cwd , outDir ) ) ;
36
+ if ( ! outDir ) {
37
+ outDir = 'dist' ;
38
+ }
39
+
40
+ const baseDir = path . resolve ( cwd , outDir ) ;
41
+ if ( fs . existsSync ( baseDir ) ) {
42
+ runArgs . push ( '--baseDir' , path . resolve ( cwd , outDir ) ) ;
43
+ }
32
44
33
45
if ( isCleanDirectory ) {
34
46
/**
0 commit comments