create-tauri-cordis-plugin 0.0.0-stage → 0.2.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 TixXin
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,7 @@
1
- # Temporary Holding Version
1
+ # `create-tauri-cordis-plugin`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Scaffolds a TypeScript + React plugin project for apps powered by [`tauri-cordis`](https://github.com/TixXin/tauri-cordis):
4
+
5
+ ```bash
6
+ npm create tauri-cordis-plugin@latest my-plugin -- --scope demo
7
+ ```
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env node
2
+ import { runCli } from "../src/index.mjs";
3
+
4
+ runCli(process.argv.slice(2)).then(
5
+ (code) => {
6
+ process.exitCode = code;
7
+ },
8
+ (error) => {
9
+ process.stderr.write(`error: ${error instanceof Error ? error.message : String(error)}\n`);
10
+ process.exitCode = 1;
11
+ },
12
+ );
package/package.json CHANGED
@@ -1,6 +1,48 @@
1
1
  {
2
2
  "name": "create-tauri-cordis-plugin",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0",
4
+ "description": "Scaffolds a TypeScript + React plugin project for tauri-cordis applications",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/TixXin/tauri-cordis.git",
10
+ "directory": "packages/create-plugin"
11
+ },
12
+ "homepage": "https://github.com/TixXin/tauri-cordis",
13
+ "bugs": {
14
+ "url": "https://github.com/TixXin/tauri-cordis/issues"
15
+ },
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "files": [
20
+ "bin",
21
+ "src",
22
+ "README.md",
23
+ "LICENSE"
24
+ ],
25
+ "bin": {
26
+ "create-tauri-cordis-plugin": "bin/create-tauri-cordis-plugin.mjs"
27
+ },
28
+ "exports": {
29
+ ".": {
30
+ "types": "./src/index.d.mts",
31
+ "default": "./src/index.mjs"
32
+ },
33
+ "./package.json": "./package.json"
34
+ },
35
+ "engines": {
36
+ "node": ">=22.15"
37
+ },
38
+ "dependencies": {
39
+ "@tauri-cordis/manifest": "0.2.0"
40
+ },
41
+ "devDependencies": {
42
+ "@tauri-cordis/cli": "0.2.0",
43
+ "tauri-cordis": "0.2.0"
44
+ },
45
+ "scripts": {
46
+ "test": "node --test \"test/**/*.test.mjs\""
47
+ }
6
48
  }
@@ -0,0 +1,20 @@
1
+ export interface ScaffoldOptions {
2
+ dir: string;
3
+ scope: string;
4
+ name: string;
5
+ appKey?: string;
6
+ slot?: string;
7
+ windowName?: string;
8
+ displayName?: { "zh-CN": string; en: string };
9
+ description?: { "zh-CN": string; en: string };
10
+ }
11
+
12
+ export interface ScaffoldResult {
13
+ packageName: string;
14
+ dir: string;
15
+ files: string[];
16
+ }
17
+
18
+ export declare function projectFiles(options: Omit<ScaffoldOptions, "dir">): Record<string, string>;
19
+ export declare function scaffoldPlugin(options: ScaffoldOptions): ScaffoldResult;
20
+ export declare function runCli(argv: string[], cwd?: string): Promise<number>;
package/src/index.mjs ADDED
@@ -0,0 +1,163 @@
1
+ import { existsSync, mkdirSync, readdirSync, writeFileSync } from "node:fs";
2
+ import { basename, dirname, join, resolve } from "node:path";
3
+ import { parseArgs } from "node:util";
4
+ import { checkPluginName } from "@tauri-cordis/manifest";
5
+
6
+ const ICON_SVG = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="9"/><path d="M12 8v4l3 3"/></svg>\n';
7
+
8
+ export function projectFiles(options) {
9
+ const scope = String(options.scope ?? "example").replace(/^@/, "").toLowerCase();
10
+ const name = String(options.name ?? "hello-plugin").toLowerCase();
11
+ const appKey = options.appKey ?? "fuyu";
12
+ const windowName = options.windowName ?? "main";
13
+ const slot = options.slot ?? `${windowName}.panel/v1`;
14
+ const packageName = `@${scope}/${name}`;
15
+ const repository = `github:${scope}/${name}`;
16
+ const problem = checkPluginName(packageName, repository, { officialScope: appKey });
17
+ if (problem) throw new Error(`Invalid plugin name ${packageName}: ${problem.message}`);
18
+
19
+ const displayName = options.displayName ?? { "zh-CN": name, en: name };
20
+ const description = options.description ?? { "zh-CN": `${name} 插件`, en: `${name} plugin` };
21
+
22
+ const pkg = {
23
+ name: packageName,
24
+ version: "0.1.0",
25
+ type: "module",
26
+ description: description.en,
27
+ license: "MIT",
28
+ repository,
29
+ engines: { [appKey]: ">=0.1.0" },
30
+ scripts: {
31
+ dev: "tauri-cordis-plugin dev",
32
+ build: "tauri-cordis-plugin build",
33
+ check: "tauri-cordis-plugin check",
34
+ pack: "tauri-cordis-plugin pack",
35
+ typecheck: "tsc --noEmit",
36
+ },
37
+ devDependencies: {
38
+ "@tauri-cordis/cli": "^0.2.0",
39
+ "@types/react": "^19.1.8",
40
+ react: "^19.1.0",
41
+ "tauri-cordis": "^0.2.0",
42
+ typescript: "~5.8.3",
43
+ },
44
+ [appKey]: {
45
+ manifest: 1,
46
+ displayName,
47
+ description,
48
+ icon: "assets/icon.svg",
49
+ categories: ["utilities"],
50
+ host: "dist/host.js",
51
+ client: { [windowName]: `dist/${windowName}.js` },
52
+ slots: [slot],
53
+ },
54
+ };
55
+
56
+ return {
57
+ "package.json": `${JSON.stringify(pkg, null, 2)}\n`,
58
+ "tsconfig.json": `${JSON.stringify(
59
+ {
60
+ compilerOptions: {
61
+ target: "ES2022",
62
+ lib: ["ES2022", "DOM"],
63
+ module: "ESNext",
64
+ moduleResolution: "Bundler",
65
+ jsx: "react-jsx",
66
+ strict: true,
67
+ noEmit: true,
68
+ },
69
+ include: ["src"],
70
+ },
71
+ null,
72
+ 2,
73
+ )}\n`,
74
+ ".gitignore": "node_modules/\ndist/\nbuild/\n",
75
+ "assets/icon.svg": ICON_SVG,
76
+ "src/host.ts": [
77
+ 'import type { Context } from "tauri-cordis";',
78
+ "",
79
+ "export const name = " + JSON.stringify(name) + ";",
80
+ "",
81
+ "export default function apply(ctx: Context) {",
82
+ " let ticks = 0;",
83
+ ' ctx.clients.handle("ping", () => ({ ticks }));',
84
+ " ctx.setInterval(() => {",
85
+ " ticks += 1;",
86
+ ' ctx.clients.publish("tick", { ticks });',
87
+ " }, 1000);",
88
+ "}",
89
+ "",
90
+ ].join("\n"),
91
+ [`src/${windowName}.tsx`]: [
92
+ 'import { useEffect, useState } from "react";',
93
+ 'import type { Context } from "tauri-cordis";',
94
+ 'import "./styles.css";',
95
+ "",
96
+ "function Panel({ ctx }: { ctx: Context }) {",
97
+ " const [ticks, setTicks] = useState(0);",
98
+ " useEffect(() => {",
99
+ ' void ctx.host.call<{ ticks: number }>("ping").then((res) => setTicks(res.ticks));',
100
+ ' const off = ctx.host.on("tick", (payload: { ticks: number }) => setTicks(payload.ticks));',
101
+ " return () => { void off(); };",
102
+ " }, [ctx]);",
103
+ ' return <div className="tc-plugin-card">Ticks: {ticks}</div>;',
104
+ "}",
105
+ "",
106
+ "export default function apply(ctx: Context) {",
107
+ ` ctx.slots.add(${JSON.stringify(slot)} as never, {`,
108
+ ` id: ${JSON.stringify(`${packageName}:panel`)},`,
109
+ " component: () => <Panel ctx={ctx} />,",
110
+ " });",
111
+ "}",
112
+ "",
113
+ ].join("\n"),
114
+ "src/styles.css": ".tc-plugin-card { padding: 8px 12px; border-radius: 8px; }\n",
115
+ "README.md": `# ${packageName}\n\nA plugin built with [tauri-cordis](https://github.com/TixXin/tauri-cordis).\n`,
116
+ };
117
+ }
118
+
119
+ export function scaffoldPlugin(options) {
120
+ const dir = resolve(options.dir);
121
+ if (existsSync(dir) && readdirSync(dir).length > 0) {
122
+ throw new Error(`Target directory is not empty: ${dir}`);
123
+ }
124
+ const files = projectFiles(options);
125
+ for (const [rel, content] of Object.entries(files)) {
126
+ const target = join(dir, rel);
127
+ mkdirSync(dirname(target), { recursive: true });
128
+ writeFileSync(target, content, "utf8");
129
+ }
130
+ const pkg = JSON.parse(files["package.json"]);
131
+ return { packageName: pkg.name, dir, files: Object.keys(files).sort() };
132
+ }
133
+
134
+ export async function runCli(argv, cwd = process.cwd()) {
135
+ const { values, positionals } = parseArgs({
136
+ args: argv,
137
+ allowPositionals: true,
138
+ options: {
139
+ scope: { type: "string", default: "demo" },
140
+ name: { type: "string" },
141
+ "app-key": { type: "string", default: "fuyu" },
142
+ window: { type: "string", default: "main" },
143
+ slot: { type: "string" },
144
+ help: { type: "boolean", short: "h", default: false },
145
+ },
146
+ });
147
+ if (values.help || positionals.length === 0) {
148
+ process.stdout.write("Usage: create-tauri-cordis-plugin <folder> [--scope <owner>] [--name <plugin-name>] [--app-key <key>]\n");
149
+ return values.help ? 0 : 1;
150
+ }
151
+ const dir = resolve(cwd, positionals[0]);
152
+ const name = values.name ?? basename(dir);
153
+ const result = scaffoldPlugin({
154
+ dir,
155
+ scope: values.scope,
156
+ name,
157
+ appKey: values["app-key"],
158
+ windowName: values.window,
159
+ slot: values.slot,
160
+ });
161
+ process.stdout.write(`Created ${result.packageName} in ${result.dir}\n`);
162
+ return 0;
163
+ }