44 debounce,
55 getIp,
66 deleteFolderRecursive,
7- readJSONFile ,
7+ readJSONCFile ,
88} = require ( './util' ) ;
99const path = require ( 'path' ) ;
10+ const fs = require ( 'fs' ) ;
1011
1112function run ( ) {
1213 const [ runCmd , tscArgs , runArgs , isCleanDirectory ] = parseArgs ( process . argv ) ;
@@ -16,19 +17,30 @@ function run() {
1617 const projectIndex = tscArgs . findIndex ( arg => arg === '--project' ) ;
1718 if ( projectIndex !== - 1 ) {
1819 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+ }
2124 } else {
2225 const outDirIndex = tscArgs . findIndex ( arg => arg === '--outDir' ) ;
2326 if ( outDirIndex !== - 1 ) {
2427 outDir = tscArgs [ outDirIndex + 1 ] ;
2528 } 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+ }
2833 }
2934 }
3035
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+ }
3244
3345 if ( isCleanDirectory ) {
3446 /**
0 commit comments