@termix-ssh/plugin-sdk 1.0.1 → 1.0.4

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.
Files changed (40) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/LICENSE +202 -0
  3. package/README.md +4 -3
  4. package/cli/commands/build.mjs +37 -12
  5. package/cli/commands/dev.mjs +1 -1
  6. package/cli/commands/openapi.mjs +39 -0
  7. package/cli/commands/validate.mjs +67 -0
  8. package/cli/index.mjs +3 -0
  9. package/cli/lib/css-classes.mjs +37 -0
  10. package/dist/changelog.d.ts +3 -8
  11. package/dist/changelog.js +6 -14
  12. package/dist/docs.d.ts +28 -0
  13. package/dist/docs.js +39 -0
  14. package/dist/frontend.d.ts +17 -0
  15. package/dist/frontend.js +8 -0
  16. package/dist/host/{chunk-COGRSHKO.js → chunk-F5RZH6HE.js} +13 -2
  17. package/dist/host/{chunk-3KG44G55.js → chunk-O2OHNVFX.js} +1 -1
  18. package/dist/host/{chunk-7GL25GFS.js → chunk-RU4E5XLY.js} +531 -300
  19. package/dist/host/core-classes.json +1 -0
  20. package/dist/host/{linked-server-BD573BEG.js → linked-server-4VWYYABP.js} +1 -1
  21. package/dist/host/{rbac-api-7GHDJLU4.js → rbac-api-WIJVZH3M.js} +1 -1
  22. package/dist/host/testing-host.js +3 -3
  23. package/dist/host/types/src/ui/api/plugins-api.d.ts +23 -0
  24. package/dist/host/types/src/ui/api/system-status-api.d.ts +24 -0
  25. package/dist/host/types/src/ui/components/docs-link.d.ts +25 -0
  26. package/dist/host/types/src/ui/components/panel-layout.d.ts +3 -1
  27. package/dist/host/types/src/ui/hooks/use-installed-plugins.d.ts +6 -0
  28. package/dist/host/types/src/ui/lib/docs.d.ts +10 -0
  29. package/dist/host/types/src/ui/main-axios.d.ts +1 -0
  30. package/dist/host/types/src/ui/plugin-host/sdk-ui.d.ts +1 -0
  31. package/dist/host/types/src/ui/settings/settings-fields-util.d.ts +10 -0
  32. package/dist/host/ui.js +139 -110
  33. package/dist/host/{use-permissions-SKWXHWDJ.js → use-permissions-KIQCJ35M.js} +1 -1
  34. package/dist/manifest.d.ts +16 -1
  35. package/dist/manifest.js +84 -1
  36. package/dist/openapi.d.ts +43 -0
  37. package/dist/openapi.js +60 -0
  38. package/dist/testing/setup.js +1 -0
  39. package/package.json +12 -2
  40. package/schema/manifest.schema.json +27 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,74 @@
1
+ # Changelog
2
+
3
+ ## 1.0.4
4
+
5
+ ### Fixed
6
+
7
+ - `termix-plugin build` puts a plugin's own Tailwind classes in core's utilities layer, so responsive, hover and group variants and `className` overrides on SDK components work. Plain classes core already ships stay below core's utilities as before, while variants core ships go with the plugin's own so `max-h-56 md:max-h-none` keeps its order. Rebuild a plugin to pick it up
8
+
9
+ ## 1.0.3
10
+
11
+ Plugin API 1.2.0.
12
+
13
+ ### Added
14
+
15
+ - `docs` manifest field: an https link to the plugin's docs. Termix shows it as a Documentation link on the plugin's page and in its settings
16
+ - `env` manifest field: the environment variables the plugin reads, listed in its docs and on its page
17
+ - `app.docs` and `useDocsUrl()` for links into the plugin's own docs, and `DocsLink` in `@termix-ssh/plugin-sdk/ui`
18
+ - `PanelShell` takes a `docs` link and shows it as a book icon in the header
19
+ - `@termix-ssh/plugin-sdk/openapi` with `buildOpenApi()`, and `termix-plugin openapi`, which writes `dist/openapi.json` from the `@openapi` blocks in `src/backend`. `build` runs it too
20
+ - `@termix-ssh/plugin-sdk/docs` with `pluginDocsUrl()`, `pluginDocsPage()` and `pluginEnvVars()`
21
+ - `termix-plugin validate` warns when `docs/index.md` is missing or the source reads an env var the manifest does not list
22
+
23
+ ## 1.0.2
24
+
25
+ ### Added
26
+
27
+ - `features` manifest field: up to 20 short lines about what the plugin does, shown on its page. `pluginFeatures()` reads them
28
+
29
+ ### Changed
30
+
31
+ - `parseChangelog()` and `validateChangelog()` flag a `## Unreleased` section. Notes go under the version they ship in
32
+
33
+ ### Removed
34
+
35
+ - `Changelog.unreleased`
36
+
37
+ ## 1.0.1
38
+
39
+ ### Added
40
+
41
+ - Plugin API 1.1
42
+ - `app.registerOnboardingStep()` adds a step to onboarding, with `OnboardingStepProps` and `OnboardingStepContribution`. Needs `engine.api` 1.1
43
+ - `video` manifest field: a YouTube link shown at the top of the plugin's page, read with `youtubeVideoId()`
44
+ - `@termix-ssh/plugin-sdk/changelog` parses and checks a plugin's `CHANGELOG.md`
45
+ - `termix-plugin changelog` prints one version's notes from `CHANGELOG.md`
46
+ - `termix-plugin dev` installs a plugin on a running server and reinstalls it on every change. Needs developer mode and an admin API key
47
+ - `renderOnboardingStep()` and `registered.onboardingSteps()` in `renderWithApp()`
48
+ - `AddButton`, `FormFooter`, `ListRow`, `ListRowAction`, `ListRowFolder`, `ListBadge` and `PanelList` in `@termix-ssh/plugin-sdk/ui`
49
+ - `PanelSearch` takes `disabled`, `title`, `onEnter` and `inputRef`, and `SurfaceScope` takes `onClose`
50
+
51
+ ### Changed
52
+
53
+ - Release notes moved from `CHANGELOG.json` to `CHANGELOG.md`, which `pack` now ships. `validate` flags a leftover `CHANGELOG.json`
54
+ - `ConnectionScreen` dropped `errorMessage` and `retryLabel` and gained `onClose`. `ConnectionLogPanel` dropped `position`
55
+ - Plugin tests run in worker threads, since forked workers crash now and then on Windows
56
+ - The test setup stubs `ResizeObserver` for Radix controls under jsdom
57
+ - `onboarding` is a reserved plugin id
58
+
59
+ ### Deprecated
60
+
61
+ - The `onboarding.*` action slots. Use `registerOnboardingStep()`
62
+
63
+ ### Removed
64
+
65
+ - `schema/changelog.schema.json`
66
+
67
+ ## 1.0.0
68
+
69
+ ### Added
70
+
71
+ - Backend, frontend, database, manifest, capability and settings types for plugin API 1.0
72
+ - Testing helpers and a Vitest preset for plugin tests
73
+ - The `@termix-ssh/plugin-sdk/ui` component set
74
+ - The `termix-plugin` CLI to build, validate, test, pack, sign and write migrations
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -12,7 +12,7 @@
12
12
 
13
13
  ## Overview
14
14
 
15
- `@termix-ssh/plugin-sdk` is what every [Termix](https://github.com/Termix-SSH/Termix) plugin builds against, including the ones that ship with Termix. It has the types for a plugin's backend and frontend, table definitions, the manifest schema, test helpers, and the `termix-plugin` CLI. The easiest way to start is the [Termix Plugin Template](https://github.com/Termix-SSH/Termix-Plugin-Template).
15
+ `@termix-ssh/plugin-sdk` is what every [Termix](https://github.com/Termix-SSH/Termix) plugin builds against, including the ones that ship with Termix. It has the types for a plugin's backend and frontend, table definitions, the manifest schema, test helpers, and the `termix-plugin` CLI. The easiest way to start is the [Termix Plugin Template](https://github.com/Termix-SSH/Termix-Plugin-Template). The full guide is at [docs.termix.site/develop](https://docs.termix.site/develop).
16
16
 
17
17
  <br />
18
18
 
@@ -30,6 +30,7 @@ npm install --save-dev @termix-ssh/plugin-sdk
30
30
  npx termix-plugin build # bundle dist/backend.js and dist/frontend.js
31
31
  npx termix-plugin test # run the plugin's Vitest suite
32
32
  npx termix-plugin validate # check manifest.json and the files it names
33
+ npx termix-plugin openapi # write dist/openapi.json from @openapi comments
33
34
  npx termix-plugin migrations # write migrations from the table definitions
34
35
  npx termix-plugin pack # write <id>-<version>.tmxplug
35
36
  npx termix-plugin changelog # print this version's notes from CHANGELOG.md
@@ -39,7 +40,7 @@ npx termix-plugin keygen --out <dir> # make a new signing key pair
39
40
  npx termix-plugin dev --server <url> --key <tmx_...> # install on a server and reinstall on every change
40
41
  ```
41
42
 
42
- `dev` needs developer mode on (Admin settings, Plugins) and an API key from an
43
+ `dev` needs developer mode on (Settings, General) and an API key from an
43
44
  admin account. It installs the plugin from a file, marked unverified, and
44
45
  reinstalls it each time you save. `TERMIX_SERVER_URL` and `TERMIX_API_KEY` work
45
46
  in place of the flags. Reload the page to pick up frontend changes.
@@ -48,7 +49,7 @@ in place of the flags. Reload the page to pick up frontend changes.
48
49
 
49
50
  ## Support
50
51
 
51
- To report a bug or request a feature, open a [support ticket](https://github.com/Termix-SSH/Support/issues/new/choose). You need to be logged in to GitHub. Please be as detailed as possible, preferably in English.
52
+ Bugs and ideas for the SDK or the `termix-plugin` CLI go in the [Termix repo](https://github.com/Termix-SSH/Termix/issues/new/choose). You need to be logged in to GitHub. Please be as detailed as possible, preferably in English.
52
53
 
53
54
  For discussions and questions, join the [Discord](https://discord.gg/jVQGdvHDrf) server.
54
55
 
@@ -6,6 +6,8 @@ import * as esbuild from "esbuild";
6
6
  import { BACKEND_EXTERNALS, FRONTEND_EXTERNALS } from "../lib/externals.mjs";
7
7
  import { staticUrlImports } from "../lib/static-url-imports.mjs";
8
8
  import { readManifest, resolveEntry, copyDir } from "../lib/plugin-dir.mjs";
9
+ import { openapi } from "./openapi.mjs";
10
+ import { splitByCoreClasses } from "../lib/css-classes.mjs";
9
11
 
10
12
  const BACKEND_ENTRIES = [
11
13
  "src/backend/index.ts",
@@ -96,14 +98,15 @@ export function applyPatches(cwd, pluginId) {
96
98
  }
97
99
  }
98
100
 
99
- const THEME_CSS = path.join(
101
+ const HOST_DIR = path.join(
100
102
  path.dirname(fileURLToPath(import.meta.url)),
101
103
  "..",
102
104
  "..",
103
105
  "dist",
104
106
  "host",
105
- "theme.css",
106
107
  );
108
+ const THEME_CSS = path.join(HOST_DIR, "theme.css");
109
+ const CORE_CLASSES = path.join(HOST_DIR, "core-classes.json");
107
110
 
108
111
  /**
109
112
  * Compiles the Tailwind classes the plugin's frontend uses into
@@ -116,15 +119,23 @@ const THEME_CSS = path.join(
116
119
  * Moves a plugin's Tailwind layers under their own names. Core orders
117
120
  * termix-plugin-utilities above its base styles and below its own utilities,
118
121
  * so a plugin's copy of `.hidden` can never beat core's `md:flex` just
119
- * because the plugin's file loaded later.
122
+ * because the plugin's file loaded later. Only classes core also ships go
123
+ * there; `utilities: false` keeps the rest in core's own utilities layer.
120
124
  */
121
- export function lowerPluginLayers(css) {
125
+ export function lowerPluginLayers(css, { utilities = true } = {}) {
126
+ const layers = utilities ? "properties|utilities" : "properties";
122
127
  return css.replace(
123
- /@layer (properties|utilities)(?=[\s{;,])/g,
128
+ new RegExp(`@layer (${layers})(?=[\\s{;,])`, "g"),
124
129
  "@layer termix-plugin-$1",
125
130
  );
126
131
  }
127
132
 
133
+ /** Classes core's CSS has rules for, or null with an SDK built before 1.0.4. */
134
+ function readCoreClasses() {
135
+ if (!fs.existsSync(CORE_CLASSES)) return null;
136
+ return new Set(JSON.parse(fs.readFileSync(CORE_CLASSES, "utf8")));
137
+ }
138
+
128
139
  export async function buildTailwind(cwd, outDir) {
129
140
  const { compile, optimize } = await import("@tailwindcss/node");
130
141
  const { Scanner } = await import("@tailwindcss/oxide");
@@ -136,10 +147,9 @@ export async function buildTailwind(cwd, outDir) {
136
147
  `@import ${JSON.stringify(THEME_CSS.replaceAll("\\", "/"))};`,
137
148
  '@import "tailwindcss/utilities.css" layer(utilities);',
138
149
  ].join("\n");
139
- const compiler = await compile(input, {
140
- base: path.dirname(THEME_CSS),
141
- onDependency: () => {},
142
- });
150
+ // build() adds to what a compiler already emitted, so each half gets its own.
151
+ const compiler = () =>
152
+ compile(input, { base: path.dirname(THEME_CSS), onDependency: () => {} });
143
153
  const scanner = new Scanner({
144
154
  sources: [
145
155
  {
@@ -151,9 +161,23 @@ export async function buildTailwind(cwd, outDir) {
151
161
  });
152
162
  // Flattened and minified the way core's own CSS is, so it does not rely
153
163
  // on native CSS nesting.
154
- const css = lowerPluginLayers(
155
- optimize(compiler.build(scanner.scan()), { minify: true }).code.trim(),
156
- );
164
+ const emit = async (candidates, options) =>
165
+ candidates.length === 0
166
+ ? ""
167
+ : lowerPluginLayers(
168
+ optimize((await compiler()).build(candidates), {
169
+ minify: true,
170
+ }).code.trim(),
171
+ options,
172
+ );
173
+ const candidates = scanner.scan();
174
+ const coreClasses = readCoreClasses();
175
+ const { shared, own } = coreClasses
176
+ ? splitByCoreClasses(candidates, coreClasses)
177
+ : { shared: candidates, own: [] };
178
+ const css = [await emit(shared), await emit(own, { utilities: false })]
179
+ .filter(Boolean)
180
+ .join("\n");
157
181
  if (!css) return;
158
182
  const target = path.join(outDir, "frontend.css");
159
183
  const existing = fs.existsSync(target) ? fs.readFileSync(target, "utf8") : "";
@@ -241,6 +265,7 @@ export async function build({ cwd }) {
241
265
 
242
266
  copyDir(path.join(cwd, "locales"), path.join(outDir, "locales"));
243
267
  copyDir(path.join(cwd, "migrations"), path.join(outDir, "migrations"));
268
+ await openapi({ cwd, quiet: true });
244
269
 
245
270
  console.log(`built ${pluginId}`);
246
271
  }
@@ -42,7 +42,7 @@ export function resolveDevOptions(args, env = process.env) {
42
42
 
43
43
  const HINTS = {
44
44
  DEVELOPER_MODE_OFF:
45
- "Turn on developer mode in Admin settings, under Plugins, then save again.",
45
+ "Turn on Plugin developer mode in Settings, General, then save again.",
46
46
  SIGNED_ONLY:
47
47
  "The server sets TERMIX_REQUIRE_SIGNED_PLUGINS, so it never installs unsigned files.",
48
48
  BUNDLED_ID: "That id ships with Termix. Use a different id while developing.",
@@ -0,0 +1,39 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { readManifest } from "../lib/plugin-dir.mjs";
4
+ import { loadSdkModule } from "./validate.mjs";
5
+
6
+ /**
7
+ * Writes dist/openapi.json from the @openapi blocks in src/backend. A plugin
8
+ * with no documented routes gets no file.
9
+ */
10
+ export async function openapi({ cwd, quiet = false }) {
11
+ const manifest = readManifest(cwd);
12
+ const pluginId = manifest.id ?? path.basename(cwd);
13
+ const backendDir = path.join(cwd, "src", "backend");
14
+ if (!fs.existsSync(backendDir)) return null;
15
+
16
+ const { buildOpenApi, hasOpenApiPaths } = await loadSdkModule("openapi");
17
+ const spec = await buildOpenApi({
18
+ title: `${manifest.name ?? pluginId} API`,
19
+ version: manifest.version ?? "0.0.0",
20
+ description: manifest.description,
21
+ files: [path.join(backendDir, "**", "*.{ts,tsx,js,mjs}")],
22
+ });
23
+
24
+ const target = path.join(cwd, "dist", "openapi.json");
25
+ if (!hasOpenApiPaths(spec)) {
26
+ fs.rmSync(target, { force: true });
27
+ if (!quiet) console.log(`${pluginId}: no documented routes`);
28
+ return null;
29
+ }
30
+
31
+ fs.mkdirSync(path.dirname(target), { recursive: true });
32
+ fs.writeFileSync(target, `${JSON.stringify(spec, null, 2)}\n`);
33
+ if (!quiet) {
34
+ console.log(
35
+ `wrote dist/openapi.json (${Object.keys(spec.paths).length} paths)`,
36
+ );
37
+ }
38
+ return target;
39
+ }
@@ -41,6 +41,10 @@ export async function validate({ cwd }) {
41
41
  problems.push(...validatePackage(cwd, raw));
42
42
  problems.push(...(await validateChangelogFile(cwd, raw)));
43
43
 
44
+ for (const warning of docsWarnings(cwd, raw)) {
45
+ console.warn(` warn ${warning}`);
46
+ }
47
+
44
48
  if (problems.length > 0) {
45
49
  for (const problem of problems) console.error(` ${problem}`);
46
50
  throw new Error(`${raw.id ?? path.basename(cwd)}: manifest is not valid.`);
@@ -49,6 +53,69 @@ export async function validate({ cwd }) {
49
53
  console.log(`ok ${raw.id ?? path.basename(cwd)}`);
50
54
  }
51
55
 
56
+ /** Env vars core sets for everyone, so a plugin need not list them. */
57
+ const CORE_ENV = new Set([
58
+ "DATA_DIR",
59
+ "NODE_ENV",
60
+ "PORT",
61
+ "BASE_PATH",
62
+ "VERSION",
63
+ "HOME",
64
+ "TMPDIR",
65
+ "TEMP",
66
+ "TMP",
67
+ "PATH",
68
+ "APPDATA",
69
+ "LOCALAPPDATA",
70
+ "USERPROFILE",
71
+ "ELECTRON_EMBEDDED",
72
+ ]);
73
+
74
+ const ENV_READS = [
75
+ /process\.env\.([A-Z][A-Z0-9_]*)/g,
76
+ /process\.env\[\s*["'`]([A-Z][A-Z0-9_]*)["'`]\s*\]/g,
77
+ /\benv\.([A-Z][A-Z0-9_]*)\b/g,
78
+ /\benv\[\s*["'`]([A-Z][A-Z0-9_]*)["'`]\s*\]/g,
79
+ ];
80
+
81
+ function walkSources(dir, out = []) {
82
+ if (!fs.existsSync(dir)) return out;
83
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
84
+ const full = path.join(dir, entry.name);
85
+ if (entry.isDirectory()) walkSources(full, out);
86
+ else if (/\.(ts|tsx|js|mjs|cjs)$/.test(entry.name)) out.push(full);
87
+ }
88
+ return out;
89
+ }
90
+
91
+ /**
92
+ * Docs gaps that do not block a release: no docs/index.md, or a process.env
93
+ * read the manifest does not list in env.
94
+ */
95
+ export function docsWarnings(cwd, raw) {
96
+ const warnings = [];
97
+ if (!fs.existsSync(path.join(cwd, "docs", "index.md"))) {
98
+ warnings.push("docs/index.md is missing, so the plugin has no docs page");
99
+ }
100
+ const declared = new Set(
101
+ Array.isArray(raw.env) ? raw.env.map((e) => e?.name) : [],
102
+ );
103
+ const missing = new Set();
104
+ for (const file of walkSources(path.join(cwd, "src"))) {
105
+ const text = fs.readFileSync(file, "utf8");
106
+ for (const pattern of ENV_READS) {
107
+ for (const match of text.matchAll(pattern)) {
108
+ const name = match[1];
109
+ if (!declared.has(name) && !CORE_ENV.has(name)) missing.add(name);
110
+ }
111
+ }
112
+ }
113
+ for (const name of [...missing].sort()) {
114
+ warnings.push(`reads ${name} but manifest env does not list it`);
115
+ }
116
+ return warnings;
117
+ }
118
+
52
119
  /**
53
120
  * package.json has to agree with the manifest: the same version, and a real
54
121
  * SDK range rather than "*", so a plugin built against a newer SDK says so.
package/cli/index.mjs CHANGED
@@ -15,6 +15,7 @@ import { sign, verify, keygen } from "./commands/sign.mjs";
15
15
  import { migrations } from "./commands/migrations.mjs";
16
16
  import { dev } from "./commands/dev.mjs";
17
17
  import { changelog } from "./commands/changelog.mjs";
18
+ import { openapi } from "./commands/openapi.mjs";
18
19
 
19
20
  const COMMANDS = {
20
21
  build,
@@ -32,6 +33,7 @@ const COMMANDS = {
32
33
  migrations,
33
34
  dev,
34
35
  changelog,
36
+ openapi,
35
37
  };
36
38
 
37
39
  const [command, ...args] = process.argv.slice(2);
@@ -50,6 +52,7 @@ if (!command || command === "--help" || command === "-h") {
50
52
  " verify Check a .tmxplug's .sig <file> --key <base64>[,...]",
51
53
  " keygen Write a new signing key pair [--out dir]",
52
54
  " migrations Generate migrations from the plugin's table definitions",
55
+ " openapi Write dist/openapi.json from the @openapi blocks in src/backend",
53
56
  " changelog Print a version's notes from CHANGELOG.md [--version x.y.z]",
54
57
  " dev Build, pack and install on a running server, again on every change",
55
58
  " [--server url] [--key tmx_...] [--once]",
@@ -0,0 +1,37 @@
1
+ /**
2
+ * The class names a stylesheet has rules for, unescaped, so `.md\:w-44`
3
+ * reads as the candidate `md:w-44` a plugin writes.
4
+ */
5
+ export function classNamesInCss(css) {
6
+ const names = new Set();
7
+ // Declarations hold numbers like 0.25rem, so only selectors are read.
8
+ const selectors = css.replace(/\{[^{}]*\}/g, "{}");
9
+ for (const match of selectors.matchAll(
10
+ /\.((?:\\[0-9a-fA-F]{1,6} ?|\\.|[\w-])+)/g,
11
+ )) {
12
+ names.add(
13
+ match[1].replace(/\\([0-9a-fA-F]{1,6}) ?|\\(.)/g, (_all, hex, char) =>
14
+ hex ? String.fromCodePoint(parseInt(hex, 16)) : char,
15
+ ),
16
+ );
17
+ }
18
+ return names;
19
+ }
20
+
21
+ /**
22
+ * Splits a plugin's candidates by whether core's own CSS already has them.
23
+ * A plain class core ships keeps the plugin's copy below core's utilities, so
24
+ * it can never reorder core's rules. Everything else goes in core's utilities
25
+ * layer: plugin-only classes, and every variant (md:, hover:, ...) even when
26
+ * core ships it, so `max-h-56 md:max-h-none` is ordered in one build and a
27
+ * variant still beats core's own base class.
28
+ */
29
+ export function splitByCoreClasses(candidates, coreClasses) {
30
+ const shared = [];
31
+ const own = [];
32
+ for (const candidate of candidates) {
33
+ const plain = !candidate.includes(":");
34
+ (plain && coreClasses.has(candidate) ? shared : own).push(candidate);
35
+ }
36
+ return { shared, own };
37
+ }
@@ -3,12 +3,7 @@
3
3
  *
4
4
  * # Changelog
5
5
  *
6
- * ## Unreleased
7
- *
8
- * ### Added
9
- * - Something merged but not shipped yet
10
- *
11
- * ## 1.1.0 - 2026-10-06
6
+ * ## 1.1.0
12
7
  *
13
8
  * An optional summary paragraph.
14
9
  *
@@ -19,7 +14,8 @@
19
14
  * - Something broken
20
15
  *
21
16
  * Releases are listed newest first, and the newest one has to be the
22
- * manifest version. The date is optional until the version ships.
17
+ * manifest version. Notes go straight under the version they ship in, there
18
+ * is no Unreleased section.
23
19
  */
24
20
  export declare const CHANGE_TYPES: readonly ["added", "changed", "fixed", "removed", "deprecated", "security"];
25
21
  export type ChangeType = (typeof CHANGE_TYPES)[number];
@@ -34,7 +30,6 @@ export interface ChangelogRelease {
34
30
  changes: ChangelogChange[];
35
31
  }
36
32
  export interface Changelog {
37
- unreleased: ChangelogChange[];
38
33
  /** Newest first, as written. */
39
34
  releases: ChangelogRelease[];
40
35
  }