Client config: fix VS Code path by platform
This commit is contained in:
+41
-2
@@ -6,6 +6,45 @@ const path = require('path');
|
|||||||
|
|
||||||
const SERVER_NAME = 'funplay_cocos';
|
const SERVER_NAME = 'funplay_cocos';
|
||||||
|
|
||||||
|
function getUserHomePath() {
|
||||||
|
const home = os.homedir();
|
||||||
|
if (home) {
|
||||||
|
return home;
|
||||||
|
}
|
||||||
|
|
||||||
|
const homeDrive = process.env.HOMEDRIVE;
|
||||||
|
const homePath = process.env.HOMEPATH;
|
||||||
|
if (homeDrive && homePath) {
|
||||||
|
return `${homeDrive}${homePath}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return process.env.HOME || '';
|
||||||
|
}
|
||||||
|
|
||||||
|
function getVSCodeConfigPath(homePath) {
|
||||||
|
switch (process.platform) {
|
||||||
|
case 'win32': {
|
||||||
|
const appData = process.env.APPDATA || path.join(homePath, 'AppData', 'Roaming');
|
||||||
|
return path.join(appData, 'Code', 'User', 'mcp.json');
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'darwin': {
|
||||||
|
const primaryPath = path.join(homePath, 'Library', 'Application Support', 'Code', 'User', 'mcp.json');
|
||||||
|
const primaryDirectory = path.dirname(primaryPath);
|
||||||
|
if (fs.existsSync(primaryPath) || fs.existsSync(primaryDirectory)) {
|
||||||
|
return primaryPath;
|
||||||
|
}
|
||||||
|
return path.join(homePath, '.vscode', 'mcp.json');
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'linux':
|
||||||
|
return path.join(homePath, '.config', 'Code', 'User', 'mcp.json');
|
||||||
|
|
||||||
|
default:
|
||||||
|
return path.join(homePath, '.vscode', 'mcp.json');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function ensureParent(filePath) {
|
function ensureParent(filePath) {
|
||||||
const dir = path.dirname(filePath);
|
const dir = path.dirname(filePath);
|
||||||
if (dir && !fs.existsSync(dir)) {
|
if (dir && !fs.existsSync(dir)) {
|
||||||
@@ -67,7 +106,7 @@ function configureTomlTarget(target) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function buildTargets(config) {
|
function buildTargets(config) {
|
||||||
const home = os.homedir();
|
const home = getUserHomePath();
|
||||||
const url = `http://${config.host}:${config.port}/`;
|
const url = `http://${config.host}:${config.port}/`;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
@@ -88,7 +127,7 @@ function buildTargets(config) {
|
|||||||
{
|
{
|
||||||
id: 'vscode',
|
id: 'vscode',
|
||||||
name: 'VS Code',
|
name: 'VS Code',
|
||||||
configPath: path.join(home, '.vscode', 'mcp.json'),
|
configPath: getVSCodeConfigPath(home),
|
||||||
rootKey: 'servers',
|
rootKey: 'servers',
|
||||||
entry: { type: 'http', url },
|
entry: { type: 'http', url },
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user