1
- import { existsSync } from 'fs' ;
1
+ import { existsSync , readFileSync } from 'fs' ;
2
2
import { networkInterfaces } from 'os' ;
3
3
4
4
import { getConfigurationArgs } from './build-configuration' ;
5
5
import { InternalCommand } from './command-name' ;
6
6
import { ionicState } from './ionic-tree-provider' ;
7
7
import { certPath } from './live-reload' ;
8
8
import { FrameworkType , MonoRepoType } from './monorepo' ;
9
- import { npx , preflightNPMCheck } from './node-commands' ;
9
+ import { npmRun , npx , preflightNPMCheck } from './node-commands' ;
10
10
import { Project } from './project' ;
11
11
import { liveReloadSSL } from './live-reload' ;
12
12
import { ExtensionSetting , getExtSetting , getSetting , setSetting , WorkspaceSetting } from './workspace-state' ;
13
13
import { getWebConfiguration , WebConfigSetting } from './web-configuration' ;
14
14
import { window , workspace } from 'vscode' ;
15
15
import { write , writeError } from './logging' ;
16
16
import { createServer } from 'http' ;
17
+ import { join } from 'path' ;
17
18
18
19
/**
19
20
* Create the ionic serve command
@@ -77,11 +78,11 @@ async function ionicCLIServe(project: Project, dontOpenBrowser: boolean): Promis
77
78
serveFlags += ` --ssl-key='${ certPath ( 'key' ) } '` ;
78
79
}
79
80
80
- return `${ preop } ${ npx ( project . packageManager ) } ${ serveCmd ( project . frameworkType ) } ${ serveFlags } ` ;
81
+ return `${ preop } ${ npx ( project . packageManager ) } ${ serveCmd ( project ) } ${ serveFlags } ` ;
81
82
}
82
83
83
- function serveCmd ( framework : FrameworkType ) : string {
84
- switch ( framework ) {
84
+ function serveCmd ( project : Project ) : string {
85
+ switch ( project . frameworkType ) {
85
86
case 'angular' :
86
87
case 'angular-standalone' :
87
88
return 'ng serve' ;
@@ -92,11 +93,29 @@ function serveCmd(framework: FrameworkType): string {
92
93
return 'react-scripts start' ;
93
94
case 'vue' :
94
95
return 'vue-cli-service serve' ;
95
- default :
96
+ default : {
97
+ const cmd = guessServeCommand ( project ) ;
98
+ if ( cmd ) {
99
+ return cmd ;
100
+ }
96
101
writeError ( `serve command is not know for this project type` ) ;
102
+ }
97
103
}
98
104
}
99
105
106
+ function guessServeCommand ( project : Project ) : string | undefined {
107
+ const filename = join ( project . projectFolder ( ) , 'package.json' ) ;
108
+ if ( existsSync ( filename ) ) {
109
+ const packageFile = JSON . parse ( readFileSync ( filename , 'utf8' ) ) ;
110
+ if ( packageFile . scripts [ 'ionic:serve' ] ) {
111
+ return npmRun ( 'ionic:serve' ) ;
112
+ }
113
+ if ( packageFile . scripts ?. serve ) {
114
+ return npmRun ( 'serve' ) ;
115
+ }
116
+ }
117
+ return undefined ;
118
+ }
100
119
async function findNextPort ( port : number ) : Promise < number > {
101
120
let availablePort = port ;
102
121
while ( await isPortInUse ( availablePort ) ) {
0 commit comments