@ratatoskr.io/create-plugin 0.0.0-stage → 0.0.2
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 +19 -2
- package/bin/create-plugin.js +160 -0
- package/package.json +42 -4
- package/template/README.md +15 -0
- package/template/_gitignore +4 -0
- package/template/schemas/game.sal +11 -0
- package/template/src/main.ts +26 -0
- package/template/tsconfig.json +20 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Asgard
|
|
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,20 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ratatoskr.io/create-plugin
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Makes a new [Wraith](https://wraith.io) plugin in TypeScript or JavaScript.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
npm create @ratatoskr.io/plugin my-plugin
|
|
7
|
+
cd my-plugin
|
|
8
|
+
npm install
|
|
9
|
+
npm run dev
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
It asks for a title, summary, author and the game it's for, then writes `wraith.json`, a starting `src/main.ts` and a schema. Pass `--help` for the options, like `--js` or `--game <exe or id>`.
|
|
13
|
+
|
|
14
|
+
If Wraith's installed, the plugin starts out with typings from it, and with its version as the minimum it needs. See [Setting up](https://docs.wraith.io/plugins/js/setup/) for the rest.
|
|
15
|
+
|
|
16
|
+
Wraith runs on Windows, so plugins build there.
|
|
17
|
+
|
|
18
|
+
## License
|
|
19
|
+
|
|
20
|
+
MIT, see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// `npm create @ratatoskr.io/plugin [folder]` makes a new Wraith plugin.
|
|
3
|
+
|
|
4
|
+
import { cpSync, existsSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { createInterface } from "node:readline/promises";
|
|
6
|
+
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { findWraith, isDevVersion, loadProject, manifestFile, schemaUrl, types, validateManifest } from "@ratatoskr.io/plugin-tools";
|
|
9
|
+
|
|
10
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
const template = join(here, "..", "template");
|
|
12
|
+
const toolsVersion = JSON.parse(readFileSync(join(here, "..", "package.json"), "utf8")).dependencies["@ratatoskr.io/plugin-tools"];
|
|
13
|
+
|
|
14
|
+
const usage = `Usage: npm create @ratatoskr.io/plugin [folder] -- [options]
|
|
15
|
+
Options:
|
|
16
|
+
--name <name> the plugin's name: its folder once installed (a-z, 0-9, _ and -)
|
|
17
|
+
--title <title> what it's called
|
|
18
|
+
--summary <text> one line about it (--description works too)
|
|
19
|
+
--author <author>
|
|
20
|
+
--game <exe or id> the game it's for: its exe (game.exe), or its ID (wraith identify)
|
|
21
|
+
--js JavaScript, not TypeScript
|
|
22
|
+
--yes take the defaults for anything not given
|
|
23
|
+
--tools <spec> the @ratatoskr.io/plugin-tools to depend on (default ${toolsVersion})`;
|
|
24
|
+
|
|
25
|
+
const namePattern = /^[a-z0-9][a-z0-9_-]{1,63}$/;
|
|
26
|
+
|
|
27
|
+
function parseArgs(argv) {
|
|
28
|
+
const options = {};
|
|
29
|
+
const rest = [];
|
|
30
|
+
for (let i = 0; i < argv.length; i++) {
|
|
31
|
+
const a = argv[i];
|
|
32
|
+
if (a === "--js" || a === "--yes" || a === "--help") options[a.slice(2)] = true;
|
|
33
|
+
else if (a.startsWith("--")) options[a.slice(2)] = argv[++i];
|
|
34
|
+
else rest.push(a);
|
|
35
|
+
}
|
|
36
|
+
return { options, folder: rest[0] };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function ask(options, folder) {
|
|
40
|
+
const interactive = !options.yes && process.stdin.isTTY;
|
|
41
|
+
const rl = interactive ? createInterface({ input: process.stdin, output: process.stdout }) : null;
|
|
42
|
+
const question = async (text, fallback, check = () => true) => {
|
|
43
|
+
if (!rl) return fallback;
|
|
44
|
+
for (;;) {
|
|
45
|
+
const answer = (await rl.question(`${text}${fallback ? ` (${fallback})` : ""}: `)).trim() || fallback;
|
|
46
|
+
if (check(answer)) return answer;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
try {
|
|
50
|
+
const dir = folder ?? (await question("Folder", "my-plugin", (a) => !!a));
|
|
51
|
+
const name = options.name ?? (await question("Name (its folder once installed)", toName(basename(resolve(dir))), (a) => namePattern.test(a)));
|
|
52
|
+
const title = options.title ?? (await question("Title", toTitle(name)));
|
|
53
|
+
const summary = options.summary ?? options.description ?? (await question("Summary (one line)", `${title}, a Wraith plugin`));
|
|
54
|
+
const author = options.author ?? (await question("Author", ""));
|
|
55
|
+
const game = options.game ?? (await question("Game (its exe, or ID from `wraith identify`; empty: any)", ""));
|
|
56
|
+
const js = options.js ?? (rl ? /^j/i.test(await question("TypeScript or JavaScript", "TypeScript")) : false);
|
|
57
|
+
return { dir: resolve(dir), name, title, summary, author, game, js };
|
|
58
|
+
} finally {
|
|
59
|
+
rl?.close();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const toName = (s) => {
|
|
64
|
+
const name = s.toLowerCase().replace(/[^a-z0-9_-]+/g, "-").replace(/^[-_]+|-+$/g, "").slice(0, 64);
|
|
65
|
+
return namePattern.test(name) ? name : "my-plugin";
|
|
66
|
+
};
|
|
67
|
+
const toTitle = (name) => name.split(/[-_]/).filter(Boolean).map((w) => w[0].toUpperCase() + w.slice(1)).join(" ");
|
|
68
|
+
|
|
69
|
+
function manifest({ name, title, summary, author, game }, wraithVersion) {
|
|
70
|
+
const m = { $schema: schemaUrl, id: name, kind: "plugin", version: "0.1.0", title, summary };
|
|
71
|
+
if (author) m.author = author;
|
|
72
|
+
if (wraithVersion) m.wraith = wraithVersion;
|
|
73
|
+
if (game) m.game = { [/\.exe$/i.test(game) ? "exes" : "ids"]: [game] };
|
|
74
|
+
m.provider = "js";
|
|
75
|
+
return JSON.stringify(m, null, 2) + "\n";
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function main(argv) {
|
|
79
|
+
const { options, folder } = parseArgs(argv);
|
|
80
|
+
if (options.help) {
|
|
81
|
+
console.log(usage);
|
|
82
|
+
return 0;
|
|
83
|
+
}
|
|
84
|
+
if (options.name && !namePattern.test(options.name)) {
|
|
85
|
+
console.error(`"${options.name}" can't be a plugin's name: 2-64 of a-z, 0-9, _ and -, starting with a letter or digit`);
|
|
86
|
+
return 1;
|
|
87
|
+
}
|
|
88
|
+
const answers = await ask(options, folder);
|
|
89
|
+
const { dir, name, title, js } = answers;
|
|
90
|
+
if (existsSync(dir) && readdirSync(dir).length) {
|
|
91
|
+
console.error(`${dir} isn't empty`);
|
|
92
|
+
return 1;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// A released Wraith's version is the plugin's starting minimum
|
|
96
|
+
let wraith = null;
|
|
97
|
+
try {
|
|
98
|
+
wraith = await findWraith({ download: false });
|
|
99
|
+
} catch {}
|
|
100
|
+
const minimum = wraith && !isDevVersion(wraith.version) && /^[0-9]+(\.[0-9]+){0,2}$/.test(wraith.version) ? wraith.version : null;
|
|
101
|
+
const manifestText = manifest(answers, minimum);
|
|
102
|
+
const problems = validateManifest(JSON.parse(manifestText));
|
|
103
|
+
if (problems.length) {
|
|
104
|
+
console.error(`Can't make its ${manifestFile}:\n ${problems.join("\n ")}`);
|
|
105
|
+
return 1;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
cpSync(template, dir, { recursive: true });
|
|
109
|
+
renameSync(join(dir, "_gitignore"), join(dir, ".gitignore"));
|
|
110
|
+
const ext = js ? "js" : "ts";
|
|
111
|
+
if (js) {
|
|
112
|
+
const main = readFileSync(join(dir, "src", "main.ts"), "utf8");
|
|
113
|
+
writeFileSync(join(dir, "src", "main.js"), `// @ts-check (against .wraith/types: see tsconfig.json)\n${main}`);
|
|
114
|
+
rmSync(join(dir, "src", "main.ts"));
|
|
115
|
+
}
|
|
116
|
+
for (const file of [join("src", `main.${ext}`), "README.md"]) {
|
|
117
|
+
const path = join(dir, file);
|
|
118
|
+
writeFileSync(path, readFileSync(path, "utf8").replaceAll("__TITLE__", title).replaceAll("__NAME__", name).replaceAll("__EXT__", ext).replaceAll("__LANGUAGE__", js ? "JavaScript" : "TypeScript"));
|
|
119
|
+
}
|
|
120
|
+
writeFileSync(join(dir, manifestFile), manifestText);
|
|
121
|
+
writeFileSync(join(dir, "package.json"), JSON.stringify({
|
|
122
|
+
name,
|
|
123
|
+
version: "0.1.0",
|
|
124
|
+
private: true,
|
|
125
|
+
type: "module",
|
|
126
|
+
scripts: {
|
|
127
|
+
build: "wraith-plugin build",
|
|
128
|
+
dev: "wraith-plugin dev",
|
|
129
|
+
pack: "wraith-plugin pack",
|
|
130
|
+
types: "wraith-plugin types",
|
|
131
|
+
},
|
|
132
|
+
devDependencies: {
|
|
133
|
+
"@ratatoskr.io/plugin-tools": options.tools ?? toolsVersion,
|
|
134
|
+
typescript: "^7.0.2",
|
|
135
|
+
},
|
|
136
|
+
}, null, 2) + "\n");
|
|
137
|
+
|
|
138
|
+
const where = relative(process.cwd(), dir) || ".";
|
|
139
|
+
console.log(`\nMade ${title} in ${where}.`);
|
|
140
|
+
if (wraith) {
|
|
141
|
+
try {
|
|
142
|
+
types(loadProject(dir), wraith);
|
|
143
|
+
console.log(`Typings from Wraith ${wraith.version} (${wraith.exe}) are in .wraith/types.`);
|
|
144
|
+
} catch (e) {
|
|
145
|
+
console.log(`Couldn't write the typings yet (${e.message}): \`npm run types\` will.`);
|
|
146
|
+
}
|
|
147
|
+
} else {
|
|
148
|
+
console.log("No Wraith found here: the first build downloads the latest (or install the Wraith app).");
|
|
149
|
+
}
|
|
150
|
+
console.log(`\nNext:\n cd ${where}\n npm install\n npm run dev`);
|
|
151
|
+
return 0;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
main(process.argv.slice(2)).then(
|
|
155
|
+
(code) => (process.exitCode = code),
|
|
156
|
+
(e) => {
|
|
157
|
+
console.error(e.message);
|
|
158
|
+
process.exitCode = 1;
|
|
159
|
+
},
|
|
160
|
+
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ratatoskr.io/create-plugin",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Makes a new JavaScript or TypeScript Wraith plugin: npm create @ratatoskr.io/plugin",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"wraith",
|
|
7
|
+
"wraith-plugin",
|
|
8
|
+
"modding",
|
|
9
|
+
"game-modding",
|
|
10
|
+
"create",
|
|
11
|
+
"scaffold",
|
|
12
|
+
"template",
|
|
13
|
+
"typescript",
|
|
14
|
+
"javascript"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://docs.wraith.io/plugins/js/setup/",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/ratatoskr/js-sdk/issues"
|
|
19
|
+
},
|
|
20
|
+
"author": "Asgard (https://github.com/asgardkat)",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/ratatoskr/js-sdk.git",
|
|
25
|
+
"directory": "packages/create-plugin"
|
|
26
|
+
},
|
|
27
|
+
"type": "module",
|
|
28
|
+
"bin": {
|
|
29
|
+
"create-plugin": "./bin/create-plugin.js"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"bin",
|
|
33
|
+
"template"
|
|
34
|
+
],
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=20"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"test": "node --test"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@ratatoskr.io/plugin-tools": "^0.0.2"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# __TITLE__
|
|
2
|
+
|
|
3
|
+
A Wraith plugin in __LANGUAGE__.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
npm install
|
|
7
|
+
npm run dev
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
- `npm run dev` builds into `dist/` and again on every change. Run `wraith dev add dist` once so Wraith loads it from there.
|
|
11
|
+
- `npm run build` type checks and builds once.
|
|
12
|
+
- `npm run pack` makes a zip to share or upload to the [Wraith Hub](https://hub.wraith.io).
|
|
13
|
+
- `npm run types` refreshes the typings in `.wraith/types` after updating Wraith.
|
|
14
|
+
|
|
15
|
+
What it can do is in [the docs](https://docs.wraith.io/plugins/js/setup/).
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// The game's types. Every .sal in schemas/ is the "schema" module, so
|
|
2
|
+
// `import { Player } from "schema"`. `npm run types` and every build type it.
|
|
3
|
+
|
|
4
|
+
struct Vec3 { f32 x; f32 y; f32 z; }
|
|
5
|
+
|
|
6
|
+
struct Player {
|
|
7
|
+
[Offset(0x10)] u8[32] name;
|
|
8
|
+
[Offset(0x30)] f32 health;
|
|
9
|
+
[Offset(0x40)] Vec3 pos;
|
|
10
|
+
[Offset(0x50)] Player* target;
|
|
11
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { frame, imgui, input, log, memory } from "wraith";
|
|
2
|
+
import { ImGuiWindowFlags, KeyPhase, Player } from "schema";
|
|
3
|
+
|
|
4
|
+
let visible = true;
|
|
5
|
+
// A real plugin finds it, like `[Sig("48 8B 05 ?? ?? ?? ??", Rip)] static Player* instance;` in its schema
|
|
6
|
+
let playerAddress = 0;
|
|
7
|
+
|
|
8
|
+
input.bind({ id: "toggle", name: "Show the window", chord: { key: "f8", mods: 0 } }, (phase) => {
|
|
9
|
+
if (phase === KeyPhase.pressed) visible = !visible;
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
frame.onFrame(() => {
|
|
13
|
+
if (!visible) return;
|
|
14
|
+
if (imgui.Begin("__TITLE__", null, ImGuiWindowFlags.AlwaysAutoResize)) {
|
|
15
|
+
imgui.TextUnformatted(`Hello from ${memory.main().name}`);
|
|
16
|
+
const player = playerAddress === 0 ? null : Player.at(playerAddress);
|
|
17
|
+
if (player) {
|
|
18
|
+
imgui.TextUnformatted(`${player.name} has ${player.health.toFixed(0)} health`);
|
|
19
|
+
if (imgui.Button("Heal")) {
|
|
20
|
+
player.health = 100;
|
|
21
|
+
log.info(`Healed ${player.name}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
imgui.End();
|
|
26
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2023",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "Bundler",
|
|
6
|
+
"lib": ["ES2023"],
|
|
7
|
+
"types": [],
|
|
8
|
+
"strict": true,
|
|
9
|
+
"noEmit": true,
|
|
10
|
+
"isolatedModules": true,
|
|
11
|
+
"allowJs": true,
|
|
12
|
+
"checkJs": true,
|
|
13
|
+
"paths": {
|
|
14
|
+
"wraith": ["./.wraith/types/wraith.d.ts"],
|
|
15
|
+
"schema": ["./.wraith/types/schema.d.ts"],
|
|
16
|
+
"salamander": ["./.wraith/types/salamander.d.ts"]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"include": ["src", ".wraith/types"]
|
|
20
|
+
}
|