@motrix/plugin-cli 2.0.0
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 +9 -0
- package/README.md +80 -0
- package/dist/bin/create-motrix-plugin.js +56 -0
- package/dist/bin/motrix-plugin.js +15237 -0
- package/dist/templates/basic-resolver/README.md.tpl +13 -0
- package/dist/templates/basic-resolver/esbuild.config.mjs.tpl +13 -0
- package/dist/templates/basic-resolver/locales/en-US.json.tpl +4 -0
- package/dist/templates/basic-resolver/locales/zh-CN.json.tpl +4 -0
- package/dist/templates/basic-resolver/motrix-plugin.json.tpl +18 -0
- package/dist/templates/basic-resolver/package.json.tpl +17 -0
- package/dist/templates/basic-resolver/src/index.ts.tpl +7 -0
- package/dist/templates/basic-resolver/tsconfig.json.tpl +13 -0
- package/dist/templates/post-action/README.md.tpl +13 -0
- package/dist/templates/post-action/esbuild.config.mjs.tpl +13 -0
- package/dist/templates/post-action/locales/en-US.json.tpl +4 -0
- package/dist/templates/post-action/locales/zh-CN.json.tpl +4 -0
- package/dist/templates/post-action/motrix-plugin.json.tpl +17 -0
- package/dist/templates/post-action/package.json.tpl +17 -0
- package/dist/templates/post-action/src/index.ts.tpl +8 -0
- package/dist/templates/post-action/tsconfig.json.tpl +13 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018-present Dr_rOot
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# @motrix/plugin-cli
|
|
2
|
+
|
|
3
|
+
Command-line developer tools for authoring, validating, and packaging
|
|
4
|
+
[Motrix](https://motrix.app) plugins.
|
|
5
|
+
|
|
6
|
+
Ships two bins:
|
|
7
|
+
|
|
8
|
+
- **`motrix-plugin`** — the main developer tool (init/dev/validate/lint/pack)
|
|
9
|
+
- **`create-motrix-plugin`** — a thin scaffolder invoked via `pnpm create motrix-plugin`
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pnpm add -D @motrix/plugin-cli
|
|
15
|
+
# or run without installing:
|
|
16
|
+
pnpm dlx @motrix/plugin-cli init my-plugin
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Commands
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
motrix-plugin init <name> [-t basic-resolver|post-action] [-p <publisher>]
|
|
23
|
+
```
|
|
24
|
+
Scaffold a new plugin project from a template (`basic-resolver` or
|
|
25
|
+
`post-action`) into `./<name>`.
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
motrix-plugin dev
|
|
29
|
+
```
|
|
30
|
+
Watch-build the plugin with esbuild and relaunch a local Motrix install
|
|
31
|
+
against it (found via `$MOTRIX_BIN` or a standard Motrix install location).
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
motrix-plugin validate
|
|
35
|
+
```
|
|
36
|
+
Validate `motrix-plugin.json` against
|
|
37
|
+
[`@motrix/plugin-manifest-schema`](https://www.npmjs.com/package/@motrix/plugin-manifest-schema) —
|
|
38
|
+
the same schema the Motrix host uses when installing a plugin.
|
|
39
|
+
|
|
40
|
+
### Schema versioning
|
|
41
|
+
|
|
42
|
+
`validate` checks your manifest against the `@motrix/plugin-manifest-schema`
|
|
43
|
+
version **embedded in the CLI at build time** — not whatever copy of the
|
|
44
|
+
schema your own project has installed. Keep `@motrix/plugin-cli` up to date
|
|
45
|
+
so its embedded schema matches the Motrix host you're targeting; schema
|
|
46
|
+
releases always ship together with a matching CLI release (lockstep), so
|
|
47
|
+
staying current on the CLI keeps you current on the schema too.
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
motrix-plugin lint
|
|
51
|
+
```
|
|
52
|
+
Static checks beyond schema validation: locale coverage
|
|
53
|
+
(`contributes`/UI strings present in every declared locale) and
|
|
54
|
+
top-level side-effect detection (guest code must not run effectful code at
|
|
55
|
+
module scope).
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
motrix-plugin validate-host-permissions
|
|
59
|
+
```
|
|
60
|
+
Sanity-check `hostPermissions` match patterns and warn on overly broad grants
|
|
61
|
+
(e.g. `<all_urls>`).
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
motrix-plugin pack
|
|
65
|
+
```
|
|
66
|
+
Bundle the plugin with esbuild and zip it into a `.moext` distributable,
|
|
67
|
+
enforcing the per-bundle and total package size limits.
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
pnpm create motrix-plugin my-plugin [template]
|
|
71
|
+
```
|
|
72
|
+
Equivalent to `motrix-plugin init`, usable without a prior install via the
|
|
73
|
+
`create-*` npm convention.
|
|
74
|
+
|
|
75
|
+
## Learn more
|
|
76
|
+
|
|
77
|
+
- Manifest shape reference: [`@motrix/plugin-manifest-schema`](https://www.npmjs.com/package/@motrix/plugin-manifest-schema)
|
|
78
|
+
- Plugin runtime types: [`@motrix/plugin-api`](https://www.npmjs.com/package/@motrix/plugin-api)
|
|
79
|
+
- Design background: `docs/superpowers/specs/2026-05-09-plugin-ecosystem-design.md`
|
|
80
|
+
in the [motrix-turbo](https://gitlab.com/agalwood/motrix-turbo) repository
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/commands/init.ts
|
|
4
|
+
import { copyFile, mkdir, readdir, readFile, writeFile } from "fs/promises";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import { fileURLToPath } from "url";
|
|
7
|
+
var TEMPLATES = path.resolve(
|
|
8
|
+
fileURLToPath(import.meta.url),
|
|
9
|
+
"../../templates"
|
|
10
|
+
);
|
|
11
|
+
async function init(opts) {
|
|
12
|
+
const target = path.resolve(opts.destDir, opts.projectName);
|
|
13
|
+
await mkdir(target, { recursive: true });
|
|
14
|
+
const src = path.join(TEMPLATES, opts.template);
|
|
15
|
+
await copyTree(src, target, {
|
|
16
|
+
PROJECT_NAME: opts.projectName,
|
|
17
|
+
PUBLISHER: opts.publisher,
|
|
18
|
+
PLUGIN_ID: `${opts.publisher}.${opts.projectName}`
|
|
19
|
+
});
|
|
20
|
+
return { created: target };
|
|
21
|
+
}
|
|
22
|
+
async function copyTree(src, dst, vars) {
|
|
23
|
+
for (const e of await readdir(src, { withFileTypes: true })) {
|
|
24
|
+
const sp = path.join(src, e.name);
|
|
25
|
+
const dp = path.join(dst, e.name.replace(/\.tpl$/, ""));
|
|
26
|
+
if (e.isDirectory()) {
|
|
27
|
+
await mkdir(dp, { recursive: true });
|
|
28
|
+
await copyTree(sp, dp, vars);
|
|
29
|
+
} else if (e.name.endsWith(".tpl")) {
|
|
30
|
+
let content = await readFile(sp, "utf8");
|
|
31
|
+
for (const [k, v] of Object.entries(vars))
|
|
32
|
+
content = content.replaceAll(`{{${k}}}`, v);
|
|
33
|
+
await writeFile(dp, content);
|
|
34
|
+
} else {
|
|
35
|
+
await copyFile(sp, dp);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// src/bin/create-motrix-plugin.ts
|
|
41
|
+
var validTemplates = ["basic-resolver", "post-action"];
|
|
42
|
+
var [name = "my-plugin", rawTemplate = "basic-resolver"] = process.argv.slice(2);
|
|
43
|
+
if (!validTemplates.includes(rawTemplate)) {
|
|
44
|
+
console.error(
|
|
45
|
+
`Unknown template: ${rawTemplate}. Available: ${validTemplates.join(", ")}`
|
|
46
|
+
);
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
var template = rawTemplate;
|
|
50
|
+
await init({
|
|
51
|
+
projectName: name,
|
|
52
|
+
template,
|
|
53
|
+
destDir: process.cwd(),
|
|
54
|
+
publisher: "me"
|
|
55
|
+
});
|
|
56
|
+
console.log("Created", name);
|