1
1
var chalk = require ( 'chalk' ) ;
2
2
var execSync = require ( 'child_process' ) . execSync ;
3
+ var path = require ( 'path' ) ;
3
4
4
5
var execOptions = { encoding : 'utf8' } ;
5
6
@@ -11,9 +12,27 @@ function getProcessIdsOnPort(port) {
11
12
return execSync ( 'lsof -i:' + port + ' -P -t' , execOptions ) . match ( / ( \S + ) / g) ;
12
13
}
13
14
14
- function getProcessCommandById ( processId ) {
15
+ function getPackageNameInDirectory ( directory ) {
16
+ var packagePath = path . join ( directory . trim ( ) , 'package.json' ) ;
17
+
18
+ try {
19
+ return require ( packagePath ) . name ;
20
+ } catch ( e ) {
21
+ return null ;
22
+ }
23
+
24
+ }
25
+
26
+ function getProcessCommand ( processId , processDirectory ) {
15
27
var command = execSync ( 'ps -o command -p ' + processId + ' | sed -n 2p' , execOptions ) ;
16
- return ( isProcessAReactApp ( command ) ) ? 'create-react-app\n' : command ;
28
+
29
+ if ( isProcessAReactApp ( command ) ) {
30
+ const packageName = getPackageNameInDirectory ( processDirectory ) ;
31
+ return ( packageName ) ? packageName + '\n' : command ;
32
+ } else {
33
+ return command ;
34
+ }
35
+
17
36
}
18
37
19
38
function getDirectoryOfProcessById ( processId ) {
@@ -25,8 +44,8 @@ function getProcessForPort(port) {
25
44
var processIds = getProcessIdsOnPort ( port ) ;
26
45
27
46
var processCommandsAndDirectories = processIds . map ( function ( processId ) {
28
- var command = getProcessCommandById ( processId ) ;
29
47
var directory = getDirectoryOfProcessById ( processId ) ;
48
+ var command = getProcessCommand ( processId , directory ) ;
30
49
return chalk . cyan ( command ) + chalk . blue ( ' in ' ) + chalk . cyan ( directory ) ;
31
50
} ) ;
32
51
0 commit comments