From d2754aac5307e1b5eb9627040fa5f1b89f7a1ff4 Mon Sep 17 00:00:00 2001 From: baranwang Date: Sat, 2 Nov 2024 23:18:38 +0800 Subject: [PATCH] feat: update --- .changeset/short-jobs-smile.md | 14 +++ packages/modkit/plugins/loon/src/template.ts | 96 +++++++++++-------- .../plugins/quantumultx/src/template.ts | 10 +- 3 files changed, 75 insertions(+), 45 deletions(-) create mode 100644 .changeset/short-jobs-smile.md diff --git a/.changeset/short-jobs-smile.md b/.changeset/short-jobs-smile.md new file mode 100644 index 0000000..9cf3ee4 --- /dev/null +++ b/.changeset/short-jobs-smile.md @@ -0,0 +1,14 @@ +--- +"@iringo/modkit-plugin-quantumultx": major +"@iringo/modkit-plugin-boxjs": major +"@iringo/modkit-plugin-stash": major +"@iringo/modkit-plugin-surge": major +"@iringo/modkit-plugin-loon": major +"@iringo/modkit-plugin-dts": major +"@iringo/arguments-builder": major +"@iringo/sgmoudle-tools": major +"@iringo/modkit-shared": major +"@iringo/modkit": major +--- + +first version diff --git a/packages/modkit/plugins/loon/src/template.ts b/packages/modkit/plugins/loon/src/template.ts index 52f213f..f90e576 100644 --- a/packages/modkit/plugins/loon/src/template.ts +++ b/packages/modkit/plugins/loon/src/template.ts @@ -34,11 +34,13 @@ const mockDataTypeMap: Record = { export class LoonTemplate extends Template { get Metadata() { - const { name, description, ...rest } = this.metadata; - const result: Record = {}; + const { name, description, version, system, extra = {} } = this.metadata; + const result: Record = {}; result.name = name; result.desc = description; - Object.entries(rest).forEach(([key, value]) => { + result.version = version; + result.system = system?.join(', '); + Object.entries(extra).forEach(([key, value]) => { result[key] = Array.isArray(value) ? value.join(',') : value; }); return this.renderKeyValuePairs(result, { prefix: '#!' }); @@ -103,44 +105,56 @@ export class LoonTemplate extends Template { } get Script() { - return this.content.script - ?.map((script, index) => { - let line = ''; - const { type, pattern, cronexp, scriptKey, argument, injectArgument, name, ...rest } = script; - switch (type) { - case 'http-request': - case 'http-response': - line += `${type} ${pattern} `; - break; - case 'cron': - line += `${type} "${cronexp}" `; - break; - case 'generic': - line += `${type} `; - break; - // case 'network-changed': - case 'event': - line += 'network-changed '; - break; - case 'dns': - default: - logger.warn(`[Loon] Unsupported script type: ${type}`); - break; - } - const parameters: Record = {}; - parameters['script-path'] = this.utils.getScriptPath(scriptKey); - parameters.tag = name || `Script${index}`; - objectEntries(rest).forEach(([key, value]) => { - parameters[toKebabCase(key)] = value; - }); - if (injectArgument || argument) { - parameters.argument = argument || `[${this.source.arguments?.map((item) => `{${item.key}}`).join(',')}]`; - } - line += this.renderKeyValuePairs(parameters, { join: ', ', separator: '=' }); - return line; - }) - .join('\n') - .trim(); + return this.content.script?.map((script, index) => { + let line = ''; + switch (script.type) { + case 'http-request': + case 'http-response': + line += `${script.type} ${script.pattern},`; + break; + case 'cron': + line += `${script.type} "${script.cronexp}",`; + break; + case 'generic': + line += `${script.type} `; + break; + // case 'network-changed': + case 'event': + line += 'network-changed '; + break; + default: + logger.warn(`[Loon] Unsupported script type: ${script.type}`); + break; + } + line += `script-path=${this.utils.getScriptPath(script.scriptKey)},`; + line += objectEntries(script) + .map(([key, value]) => { + switch (key) { + case 'name': + return `tag = ${value || `Script${index}`}`; + case 'argument': + return `argument = ${value}`; + case 'injectArgument': { + if (!script.argument && value) { + return `argument = [${this.source.arguments?.map((item) => `{${item.key}}`).join(',')}]`; + } + return ''; + } + case 'type': + case 'pattern': + case 'cronexp': + case 'scriptKey': + return ''; + + default: + return `${key} = ${value}`; + } + }) + .filter(Boolean) + .join(',') + .trim(); + return line; + }); } get MITM() { diff --git a/packages/modkit/plugins/quantumultx/src/template.ts b/packages/modkit/plugins/quantumultx/src/template.ts index 30335db..a65d075 100644 --- a/packages/modkit/plugins/quantumultx/src/template.ts +++ b/packages/modkit/plugins/quantumultx/src/template.ts @@ -1,4 +1,4 @@ -import { type RuleType, Template, logger, objectEntries, toKebabCase } from '@iringo/modkit-shared'; +import { type RuleType, Template, logger } from '@iringo/modkit-shared'; const ruleTypeMap: Record = { DOMAIN: 'host', @@ -27,11 +27,13 @@ const ruleTypeMap: Record = { export class QuantumultxTemplate extends Template { get Metadata() { - const { name, description, ...rest } = this.metadata; - const result: Record = {}; + const { name, description, version, system, extra = {} } = this.metadata; + const result: Record = {}; result.name = name; result.desc = description; - Object.entries(rest).forEach(([key, value]) => { + result.version = version; + result.system = system?.join(', '); + Object.entries(extra).forEach(([key, value]) => { result[key] = Array.isArray(value) ? value.join(',') : value; }); return this.renderKeyValuePairs(result, { prefix: '#!' });