Skip to content

Commit

Permalink
feat: 优化错误提示
Browse files Browse the repository at this point in the history
  • Loading branch information
geekdada committed Jan 1, 2021
1 parent f86af92 commit 6690cd9
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 93 deletions.
6 changes: 3 additions & 3 deletions lib/command/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class LintCommand extends Command {

// istanbul ignore next
public get description(): string {
return '运行 ESLint 检查';
return '运行 JS 语法检查';
}

public async run(ctx): Promise<void> {
Expand All @@ -30,10 +30,10 @@ class LintCommand extends Command {
}

if (!result) {
console.log('⚠️ ESLint 测试不通过');
console.log('⚠️ JS 语法检查不通过,请根据提示修改文件');
process.exit(1);
} else {
console.log('✅ ESLint 检查通过');
console.log('✅ JS 语法检查通过');
}
}
}
Expand Down
174 changes: 84 additions & 90 deletions lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ export const getShadowsocksJSONConfig = async (
const response = ConfigCache.has(url)
? JSON.parse(ConfigCache.get(url) as string)
: await (async () => {
const res = await httpClient.get(url);
const res = await httpClient.get(url);

ConfigCache.set(url, res.body);
ConfigCache.set(url, res.body);

return JSON.parse(res.body);
})();
return JSON.parse(res.body);
})();

return (response.configs as ReadonlyArray<any>).map(
(item): ShadowsocksNodeConfig => {
Expand Down Expand Up @@ -153,8 +153,7 @@ export const getSurgeNodes = function (

if (config.obfs && ['ws', 'wss'].includes(config.obfs)) {
logger.warn(
`不支持为 Surge 生成 v2ray-plugin 的 Shadowsocks 节点,节点 ${
nodeConfig!.nodeName
`不支持为 Surge 生成 v2ray-plugin 的 Shadowsocks 节点,节点 ${nodeConfig!.nodeName
} 会被省略`
);
return void 0;
Expand Down Expand Up @@ -323,7 +322,7 @@ export const getSurgeNodes = function (

if (config.localPort === 0) {
throw new Error(
`为 Surge 生成 SSR 配置时必须为 Provider ${config.provider?.name} 设置 startPort`
`为 Surge 生成 SSR 配置时必须为 Provider ${config.provider?.name} 设置 startPort,参考 http://bit.ly/2LfIrNW`
);
}

Expand Down Expand Up @@ -364,13 +363,13 @@ export const getSurgeNodes = function (
configList.push(`ws-path=${config.path}`);
configList.push(
'ws-headers=' +
JSON.stringify(
getHeader({
host: config.host || config.hostname,
'user-agent': OBFS_UA,
..._.omit(config.wsHeaders, ['host']), // host 本质上是一个头信息,所以可能存在冲突的情况。以 host 属性为准。
})
)
JSON.stringify(
getHeader({
host: config.host || config.hostname,
'user-agent': OBFS_UA,
..._.omit(config.wsHeaders, ['host']), // host 本质上是一个头信息,所以可能存在冲突的情况。以 host 属性为准。
})
)
);
}

Expand Down Expand Up @@ -412,7 +411,7 @@ export const getSurgeNodes = function (

if (config.localPort === 0) {
throw new Error(
`为 Surge 生成 Vmess 配置时必须为 Provider ${config.provider?.name} 设置 startPort`
`为 Surge 生成 Vmess 配置时必须为 Provider ${config.provider?.name} 设置 startPort,参考 http://bit.ly/2LfIrNW`
);
}

Expand Down Expand Up @@ -510,8 +509,7 @@ export const getSurgeNodes = function (
// istanbul ignore next
default:
logger.warn(
`不支持为 Surge 生成 ${nodeConfig!.type} 的节点,节点 ${
nodeConfig!.nodeName
`不支持为 Surge 生成 ${nodeConfig!.type} 的节点,节点 ${nodeConfig!.nodeName
} 会被省略`
);
return void 0;
Expand Down Expand Up @@ -550,34 +548,34 @@ export const getClashNodes = function (
udp: nodeConfig['udp-relay'] === true,
...(nodeConfig.obfs && ['tls', 'http'].includes(nodeConfig.obfs)
? {
plugin: 'obfs',
'plugin-opts': {
mode: nodeConfig.obfs,
host: nodeConfig['obfs-host'],
},
}
plugin: 'obfs',
'plugin-opts': {
mode: nodeConfig.obfs,
host: nodeConfig['obfs-host'],
},
}
: null),
...(nodeConfig.obfs && ['ws', 'wss'].includes(nodeConfig.obfs)
? {
plugin: 'v2ray-plugin',
'plugin-opts': {
mode: 'websocket',
tls: nodeConfig.obfs === 'wss',
...(typeof nodeConfig.skipCertVerify === 'boolean' &&
plugin: 'v2ray-plugin',
'plugin-opts': {
mode: 'websocket',
tls: nodeConfig.obfs === 'wss',
...(typeof nodeConfig.skipCertVerify === 'boolean' &&
nodeConfig.obfs === 'wss'
? {
'skip-cert-verify': nodeConfig.skipCertVerify,
}
: null),
host: nodeConfig['obfs-host'],
path: nodeConfig['obfs-uri'] || '/',
mux:
typeof nodeConfig.mux === 'boolean'
? nodeConfig.mux
: false,
headers: nodeConfig.wsHeaders || {},
},
}
? {
'skip-cert-verify': nodeConfig.skipCertVerify,
}
: null),
host: nodeConfig['obfs-host'],
path: nodeConfig['obfs-uri'] || '/',
mux:
typeof nodeConfig.mux === 'boolean'
? nodeConfig.mux
: false,
headers: nodeConfig.wsHeaders || {},
},
}
: null),
};

Expand All @@ -594,22 +592,22 @@ export const getClashNodes = function (
...(nodeConfig.network === 'tcp'
? null
: {
network: nodeConfig.network,
}),
network: nodeConfig.network,
}),
tls: nodeConfig.tls,
...(typeof nodeConfig.skipCertVerify === 'boolean' && nodeConfig.tls
? {
'skip-cert-verify': nodeConfig.skipCertVerify,
}
'skip-cert-verify': nodeConfig.skipCertVerify,
}
: null),
...(nodeConfig.network === 'ws'
? {
'ws-path': nodeConfig.path,
'ws-headers': {
...(nodeConfig.host ? { host: nodeConfig.host } : null),
...nodeConfig.wsHeaders,
},
}
'ws-path': nodeConfig.path,
'ws-headers': {
...(nodeConfig.host ? { host: nodeConfig.host } : null),
...nodeConfig.wsHeaders,
},
}
: null),
};

Expand All @@ -627,13 +625,13 @@ export const getClashNodes = function (
cipher: nodeConfig.method,
...(ssrFormat === 'native'
? {
'obfs-param': nodeConfig.obfsparam ?? '',
'protocol-param': nodeConfig.protoparam ?? '',
}
'obfs-param': nodeConfig.obfsparam ?? '',
'protocol-param': nodeConfig.protoparam ?? '',
}
: {
obfsparam: nodeConfig.obfsparam ?? '',
protocolparam: nodeConfig.protoparam ?? '',
}),
obfsparam: nodeConfig.obfsparam ?? '',
protocolparam: nodeConfig.protoparam ?? '',
}),
udp: nodeConfig['udp-relay'] === true,
};
}
Expand All @@ -649,14 +647,14 @@ export const getClashNodes = function (
mode: nodeConfig.obfs,
...(nodeConfig['obfs-host']
? {
host: nodeConfig['obfs-host'],
}
host: nodeConfig['obfs-host'],
}
: null),
},
...(nodeConfig.version
? {
version: nodeConfig.version,
}
version: nodeConfig.version,
}
: null),
};

Expand Down Expand Up @@ -720,8 +718,7 @@ export const getClashNodes = function (
// istanbul ignore next
default:
logger.warn(
`不支持为 Clash 生成 ${nodeConfig!.type} 的节点,节点 ${
nodeConfig!.nodeName
`不支持为 Clash 生成 ${nodeConfig!.type} 的节点,节点 ${nodeConfig!.nodeName
} 会被省略`
);
return null;
Expand Down Expand Up @@ -759,8 +756,7 @@ export const getMellowNodes = function (
// istanbul ignore next
default:
logger.warn(
`不支持为 Mellow 生成 ${nodeConfig!.type} 的节点,节点 ${
nodeConfig!.nodeName
`不支持为 Mellow 生成 ${nodeConfig!.type} 的节点,节点 ${nodeConfig!.nodeName
} 会被省略`
);
return null;
Expand Down Expand Up @@ -814,10 +810,10 @@ export const getShadowsocksNodes = (
} = {
...(config.obfs
? {
plugin: `${encodeURIComponent(
`obfs-local;obfs=${config.obfs};obfs-host=${config['obfs-host']}`
)}`,
}
plugin: `${encodeURIComponent(
`obfs-local;obfs=${config.obfs};obfs-host=${config['obfs-host']}`
)}`,
}
: null),
...(groupName ? { group: encodeURIComponent(groupName) } : null),
};
Expand Down Expand Up @@ -1034,8 +1030,7 @@ export const getQuantumultNodes = function (
// istanbul ignore next
default:
logger.warn(
`不支持为 Quantumult 生成 ${nodeConfig!.type} 的节点,节点 ${
nodeConfig!.nodeName
`不支持为 Quantumult 生成 ${nodeConfig!.type} 的节点,节点 ${nodeConfig!.nodeName
} 会被省略`
);
return void 0;
Expand Down Expand Up @@ -1125,16 +1120,16 @@ export const getQuantumultXNodes = function (
...pickAndFormatStringList(nodeConfig, ['method', 'password']),
...(nodeConfig.obfs && ['http', 'tls'].includes(nodeConfig.obfs)
? [
`obfs=${nodeConfig.obfs}`,
`obfs-host=${nodeConfig['obfs-host']}`,
]
`obfs=${nodeConfig.obfs}`,
`obfs-host=${nodeConfig['obfs-host']}`,
]
: []),
...(nodeConfig.obfs && ['ws', 'wss'].includes(nodeConfig.obfs)
? [
`obfs=${nodeConfig.obfs}`,
`obfs-host=${nodeConfig['obfs-host'] || nodeConfig.hostname}`,
`obfs-uri=${nodeConfig['obfs-uri'] || '/'}`,
]
`obfs=${nodeConfig.obfs}`,
`obfs-host=${nodeConfig['obfs-host'] || nodeConfig.hostname}`,
`obfs-uri=${nodeConfig['obfs-uri'] || '/'}`,
]
: []),
...(nodeConfig['udp-relay'] ? [`udp-relay=true`] : []),
...(nodeConfig.tfo ? [`fast-open=${nodeConfig.tfo}`] : []),
Expand Down Expand Up @@ -1211,8 +1206,7 @@ export const getQuantumultXNodes = function (
// istanbul ignore next
default:
logger.warn(
`不支持为 QuantumultX 生成 ${nodeConfig!.type} 的节点,节点 ${
nodeConfig!.nodeName
`不支持为 QuantumultX 生成 ${nodeConfig!.type} 的节点,节点 ${nodeConfig!.nodeName
} 会被省略`
);
return void 0;
Expand Down Expand Up @@ -1249,9 +1243,9 @@ export const getShadowsocksNodesJSON = (
enable: true,
...(useObfs
? {
plugin: 'obfs-local',
'plugin-opts': `obfs=${nodeConfig.obfs};obfs-host=${nodeConfig['obfs-host']}`,
}
plugin: 'obfs-local',
'plugin-opts': `obfs=${nodeConfig.obfs};obfs-host=${nodeConfig['obfs-host']}`,
}
: null),
};
}
Expand Down Expand Up @@ -1347,9 +1341,9 @@ export const generateClashProxyGroup = (
proxies,
...(['url-test', 'fallback', 'load-balance'].includes(ruleType)
? {
url: options.proxyTestUrl,
interval: options.proxyTestInterval,
}
url: options.proxyTestUrl,
interval: options.proxyTestInterval,
}
: null),
};
};
Expand Down Expand Up @@ -1487,13 +1481,13 @@ export const formatV2rayConfig = (
serverName: nodeConfig.host || nodeConfig.hostname,
...(typeof nodeConfig.skipCertVerify === 'boolean'
? {
allowInsecure: nodeConfig.skipCertVerify,
}
allowInsecure: nodeConfig.skipCertVerify,
}
: null),
...(typeof nodeConfig.tls13 === 'boolean'
? {
allowInsecureCiphers: !nodeConfig.tls13,
}
allowInsecureCiphers: !nodeConfig.tls13,
}
: null),
},
};
Expand Down

0 comments on commit 6690cd9

Please sign in to comment.