mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-04-23 20:51:12 +08:00
update to modern code style (#1738)
* mv create-react-app/index.js -> create-react-app/creteReactApp.js * update to modern code style * var -> cosnt * set trailing-coma to es5 for prettier
This commit is contained in:
committed by
Dan Abramov
parent
43873dc9b8
commit
fe7b5c212b
28
packages/react-dev-utils/getProcessForPort.js
vendored
28
packages/react-dev-utils/getProcessForPort.js
vendored
@@ -18,8 +18,8 @@ var execOptions = {
|
||||
stdio: [
|
||||
'pipe', // stdin (default)
|
||||
'pipe', // stdout (default)
|
||||
'ignore' //stderr
|
||||
]
|
||||
'ignore', //stderr
|
||||
],
|
||||
};
|
||||
|
||||
function isProcessAReactApp(processCommand) {
|
||||
@@ -27,7 +27,10 @@ function isProcessAReactApp(processCommand) {
|
||||
}
|
||||
|
||||
function getProcessIdOnPort(port) {
|
||||
return execSync('lsof -i:' + port + ' -P -t -sTCP:LISTEN', execOptions).trim();
|
||||
return execSync(
|
||||
'lsof -i:' + port + ' -P -t -sTCP:LISTEN',
|
||||
execOptions
|
||||
).trim();
|
||||
}
|
||||
|
||||
function getPackageNameInDirectory(directory) {
|
||||
@@ -35,26 +38,30 @@ function getPackageNameInDirectory(directory) {
|
||||
|
||||
try {
|
||||
return require(packagePath).name;
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function getProcessCommand(processId, processDirectory) {
|
||||
var command = execSync('ps -o command -p ' + processId + ' | sed -n 2p', execOptions);
|
||||
var command = execSync(
|
||||
'ps -o command -p ' + processId + ' | sed -n 2p',
|
||||
execOptions
|
||||
);
|
||||
|
||||
if (isProcessAReactApp(command)) {
|
||||
const packageName = getPackageNameInDirectory(processDirectory);
|
||||
return (packageName) ? packageName + '\n' : command;
|
||||
return packageName ? packageName + '\n' : command;
|
||||
} else {
|
||||
return command;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function getDirectoryOfProcessById(processId) {
|
||||
return execSync('lsof -p '+ processId + ' | awk \'$4=="cwd" {print $9}\'', execOptions).trim();
|
||||
return execSync(
|
||||
'lsof -p ' + processId + ' | awk \'$4=="cwd" {print $9}\'',
|
||||
execOptions
|
||||
).trim();
|
||||
}
|
||||
|
||||
function getProcessForPort(port) {
|
||||
@@ -63,10 +70,9 @@ function getProcessForPort(port) {
|
||||
var directory = getDirectoryOfProcessById(processId);
|
||||
var command = getProcessCommand(processId, directory);
|
||||
return chalk.cyan(command) + chalk.blue(' in ') + chalk.cyan(directory);
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = getProcessForPort;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user