mihoco 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +76 -2
- package/lib/bin.cjs +41 -0
- package/lib/bin.mjs +43 -0
- package/lib/index.cjs +8 -0
- package/lib/index.d.cts +1 -0
- package/lib/index.d.mts +1 -0
- package/lib/index.mjs +3 -0
- package/package.json +57 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Lucius Shao <i@void.mu>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,77 @@
|
|
|
1
|
-
#
|
|
1
|
+
# mihoco
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Write a Mihomo profile in TypeScript and export it as YAML. Declare a proxy or group once and reference it from routing rules, DNS settings, and other groups. `mihoco` is an unofficial CLI and library for Node.js.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install `mihoco` in the project that contains your profiles. This gives you both the CLI and the helpers you import in TypeScript.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install --save-dev mihoco
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
With pnpm, use `pnpm add -D mihoco`. If pnpm flags the `esbuild` install script, run `pnpm approve-builds` to review it. Run the project-local CLI with `npx mihoco` or `pnpm exec mihoco`.
|
|
14
|
+
|
|
15
|
+
To put the `mihoco` command on your shell's PATH, install it globally.
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
npm install --global mihoco
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```text
|
|
24
|
+
mihoco <profile.ts> [options]
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
`<profile.ts>` is the path to a TypeScript file whose default export is a configuration object. The file can import other TypeScript modules. Its package imports resolve from the profile's project, including when you run the global CLI.
|
|
28
|
+
|
|
29
|
+
| Option | Description |
|
|
30
|
+
| --- | --- |
|
|
31
|
+
| `-o, --output <file>` | Write YAML to this file. By default, YAML goes to stdout. |
|
|
32
|
+
| `-h, --help` | Print the command syntax and exit. |
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
mihoco ./profile.ts
|
|
36
|
+
mihoco ./profile.ts --output profile.yaml
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
For a one-off export of a self-contained profile, run `npx mihoco ./profile.ts`.
|
|
40
|
+
|
|
41
|
+
## Example
|
|
42
|
+
|
|
43
|
+
Save this as `profile.ts` in the project where you installed `mihoco`.
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { defineProfile, DIRECT, group, proxy, route, routes, rule } from 'mihoco'
|
|
47
|
+
|
|
48
|
+
const office = proxy.socks5('Office', { server: '192.0.2.8', port: 1080 })
|
|
49
|
+
const work = group.select('Work', [office, DIRECT], { 'default-selected': office })
|
|
50
|
+
|
|
51
|
+
export default defineProfile({
|
|
52
|
+
mode: 'rule',
|
|
53
|
+
'mixed-port': 7890,
|
|
54
|
+
rules: routes([
|
|
55
|
+
route(rule.domain.suffix('example.org'), work),
|
|
56
|
+
route(rule.match(), DIRECT),
|
|
57
|
+
]),
|
|
58
|
+
})
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Generate `profile.yaml` with the local CLI.
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
|
+
npx mihoco ./profile.ts -o profile.yaml
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The file includes the `Office` proxy, the `Work` selector, and these routing rules.
|
|
68
|
+
|
|
69
|
+
```yaml
|
|
70
|
+
rules:
|
|
71
|
+
- DOMAIN-SUFFIX,example.org,Work
|
|
72
|
+
- MATCH,DIRECT
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Using the library
|
|
76
|
+
|
|
77
|
+
`mihoco` re-exports the authoring API from `mihoco-core`. The result of `defineProfile` is a plain JavaScript object, so another script can import the same default export and pass it to a YAML serializer.
|
package/lib/bin.cjs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
let node_fs_promises = require("node:fs/promises");
|
|
3
|
+
let node_path = require("node:path");
|
|
4
|
+
let node_url = require("node:url");
|
|
5
|
+
let node_util = require("node:util");
|
|
6
|
+
let tsx_esm_api = require("tsx/esm/api");
|
|
7
|
+
let yaml = require("yaml");
|
|
8
|
+
|
|
9
|
+
// src/bin.ts
|
|
10
|
+
const usage = "Usage: mihoco <profile.ts> [-o, --output <profile.yaml>]";
|
|
11
|
+
async function main() {
|
|
12
|
+
const { values, positionals } = (0, node_util.parseArgs)({
|
|
13
|
+
allowPositionals: true,
|
|
14
|
+
options: {
|
|
15
|
+
output: {
|
|
16
|
+
type: "string",
|
|
17
|
+
short: "o"
|
|
18
|
+
},
|
|
19
|
+
help: {
|
|
20
|
+
type: "boolean",
|
|
21
|
+
short: "h"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
if (values.help) {
|
|
26
|
+
console.log(usage);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (positionals.length !== 1) throw new Error(usage);
|
|
30
|
+
const input = (0, node_url.pathToFileURL)((0, node_path.resolve)(positionals[0])).href;
|
|
31
|
+
const loaded = await (0, tsx_esm_api.tsImport)(input, require("url").pathToFileURL(__filename).href);
|
|
32
|
+
const profile = loaded.default?.__esModule === true ? loaded.default.default : loaded.default;
|
|
33
|
+
if (!profile || Object.getPrototypeOf(profile) !== Object.prototype && Object.getPrototypeOf(profile) !== null) throw new Error(`${positionals[0]} must default-export a configuration object`);
|
|
34
|
+
const yaml$1 = (0, yaml.stringify)(profile, { aliasDuplicateObjects: false });
|
|
35
|
+
if (values.output !== void 0) await (0, node_fs_promises.writeFile)(values.output, yaml$1, "utf8");
|
|
36
|
+
else process.stdout.write(yaml$1);
|
|
37
|
+
}
|
|
38
|
+
main().catch((error) => {
|
|
39
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
40
|
+
process.exitCode = 1;
|
|
41
|
+
});
|
package/lib/bin.mjs
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { writeFile } from "node:fs/promises";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
import { parseArgs } from "node:util";
|
|
6
|
+
import { tsImport } from "tsx/esm/api";
|
|
7
|
+
import { stringify } from "yaml";
|
|
8
|
+
|
|
9
|
+
// src/bin.ts
|
|
10
|
+
const usage = "Usage: mihoco <profile.ts> [-o, --output <profile.yaml>]";
|
|
11
|
+
async function main() {
|
|
12
|
+
const { values, positionals } = parseArgs({
|
|
13
|
+
allowPositionals: true,
|
|
14
|
+
options: {
|
|
15
|
+
output: {
|
|
16
|
+
type: "string",
|
|
17
|
+
short: "o"
|
|
18
|
+
},
|
|
19
|
+
help: {
|
|
20
|
+
type: "boolean",
|
|
21
|
+
short: "h"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
if (values.help) {
|
|
26
|
+
console.log(usage);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (positionals.length !== 1) throw new Error(usage);
|
|
30
|
+
const input = pathToFileURL(resolve(positionals[0])).href;
|
|
31
|
+
const loaded = await tsImport(input, import.meta.url);
|
|
32
|
+
const profile = loaded.default?.__esModule === true ? loaded.default.default : loaded.default;
|
|
33
|
+
if (!profile || Object.getPrototypeOf(profile) !== Object.prototype && Object.getPrototypeOf(profile) !== null) throw new Error(`${positionals[0]} must default-export a configuration object`);
|
|
34
|
+
const yaml = stringify(profile, { aliasDuplicateObjects: false });
|
|
35
|
+
if (values.output !== void 0) await writeFile(values.output, yaml, "utf8");
|
|
36
|
+
else process.stdout.write(yaml);
|
|
37
|
+
}
|
|
38
|
+
main().catch((error) => {
|
|
39
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
40
|
+
process.exitCode = 1;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export { };
|
package/lib/index.cjs
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
|
|
2
|
+
var mihoco_core = require("mihoco-core");
|
|
3
|
+
Object.keys(mihoco_core).forEach(function (k) {
|
|
4
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
5
|
+
enumerable: true,
|
|
6
|
+
get: function () { return mihoco_core[k]; }
|
|
7
|
+
});
|
|
8
|
+
});
|
package/lib/index.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "mihoco-core";
|
package/lib/index.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "mihoco-core";
|
package/lib/index.mjs
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,60 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mihoco",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "A CLI and library for writing Mihomo profiles in TypeScript and exporting them as YAML.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/index.cjs",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib"
|
|
9
|
+
],
|
|
10
|
+
"bin": {
|
|
11
|
+
"mihoco": "./lib/bin.mjs"
|
|
12
|
+
},
|
|
13
|
+
"author": {
|
|
14
|
+
"name": "unbyte",
|
|
15
|
+
"url": "https://github.com/unbyte"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"homepage": "https://github.com/unbyte/mihoco#readme",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/unbyte/mihoco.git",
|
|
22
|
+
"directory": "packages/mihoco"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/unbyte/mihoco/issues"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"mihomo",
|
|
29
|
+
"clash",
|
|
30
|
+
"typescript",
|
|
31
|
+
"proxy",
|
|
32
|
+
"yaml",
|
|
33
|
+
"cli"
|
|
34
|
+
],
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"tsx": "^4.23.15",
|
|
40
|
+
"yaml": "^2.9.1",
|
|
41
|
+
"mihoco-core": "0.0.1"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsdown"
|
|
45
|
+
},
|
|
46
|
+
"module": "lib/index.mjs",
|
|
47
|
+
"types": "lib/index.d.mts",
|
|
48
|
+
"exports": {
|
|
49
|
+
".": {
|
|
50
|
+
"import": {
|
|
51
|
+
"types": "./lib/index.d.mts",
|
|
52
|
+
"default": "./lib/index.mjs"
|
|
53
|
+
},
|
|
54
|
+
"require": {
|
|
55
|
+
"types": "./lib/index.d.cts",
|
|
56
|
+
"default": "./lib/index.cjs"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
6
60
|
}
|