@termix-ssh/plugin-sdk 1.0.2 → 1.0.5
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/CHANGELOG.md +31 -0
- package/LICENSE +202 -0
- package/README.md +4 -2
- package/cli/commands/build.mjs +44 -19
- package/cli/commands/dev.mjs +1 -1
- package/cli/commands/migrations.mjs +2 -2
- package/cli/commands/openapi.mjs +39 -0
- package/cli/commands/validate.mjs +72 -0
- package/cli/index.mjs +3 -0
- package/cli/lib/css-classes.mjs +37 -0
- package/dist/changelog.d.ts +3 -1
- package/dist/changelog.js +12 -2
- package/dist/db.d.ts +1 -1
- package/dist/db.js +1 -1
- package/dist/ddl.js +4 -1
- package/dist/docs.d.ts +28 -0
- package/dist/docs.js +39 -0
- package/dist/frontend.d.ts +17 -0
- package/dist/frontend.js +8 -0
- package/dist/host/{chunk-XKMRKQFN.js → chunk-KOOUKYW3.js} +1 -1
- package/dist/host/{chunk-LKYAVM4T.js → chunk-OEOKIKXC.js} +18 -9
- package/dist/host/{chunk-SS43S6VI.js → chunk-VETPF5WI.js} +478 -431
- package/dist/host/core-classes.json +1 -0
- package/dist/host/{linked-server-DW5P3NLZ.js → linked-server-RWBK427T.js} +1 -1
- package/dist/host/{rbac-api-JKISXZEP.js → rbac-api-UJGGTQVA.js} +1 -1
- package/dist/host/testing-host.js +3 -3
- package/dist/host/types/src/types/credential-sidebar-preferences.d.ts +1 -1
- package/dist/host/types/src/ui/api/plugins-api.d.ts +6 -0
- package/dist/host/types/src/ui/components/docs-link.d.ts +25 -0
- package/dist/host/types/src/ui/components/panel-layout.d.ts +3 -1
- package/dist/host/types/src/ui/lib/docs.d.ts +10 -0
- package/dist/host/types/src/ui/lib/error-message.d.ts +1 -1
- package/dist/host/types/src/ui/main-axios.d.ts +1 -2
- package/dist/host/types/src/ui/plugin-host/sdk-ui.d.ts +1 -0
- package/dist/host/ui.js +18 -8
- package/dist/host/{use-permissions-5CZEA3P4.js → use-permissions-P3DC7ZDR.js} +1 -1
- package/dist/host-commands.js +1 -1
- package/dist/manifest.d.ts +7 -1
- package/dist/manifest.js +48 -1
- package/dist/openapi.d.ts +43 -0
- package/dist/openapi.js +60 -0
- package/dist/testing/setup.js +1 -0
- package/package.json +22 -1
- package/schema/manifest.schema.json +21 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.0.5
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- `execCommand` timeout errors no longer include the command, which could hold a sudo password
|
|
8
|
+
- `termix-plugin validate` fails when a plugin ships migrations for some database engines but not all three
|
|
9
|
+
- `termix-plugin migrations` loads the table definitions from a path with a `#` or other URL characters in it
|
|
10
|
+
- Text, json and encrypted columns are `longtext` on MySQL in new migrations, so they are no longer capped at 64KB. Existing migrations keep `text`
|
|
11
|
+
- `i18next`, `react-dom`, `react-i18next` and `sonner` are optional peer dependencies, so npm stops installing them into backend-only plugins
|
|
12
|
+
- `termix-plugin validate` accepts a beta version like `1.1.0-beta.1` when the changelog's newest release is `1.1.0` or older, so beta releases pass
|
|
13
|
+
|
|
14
|
+
## 1.0.4
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- `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
|
|
19
|
+
|
|
20
|
+
## 1.0.3
|
|
21
|
+
|
|
22
|
+
Plugin API 1.2.0.
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
|
|
26
|
+
- `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
|
|
27
|
+
- `env` manifest field: the environment variables the plugin reads, listed in its docs and on its page
|
|
28
|
+
- `app.docs` and `useDocsUrl()` for links into the plugin's own docs, and `DocsLink` in `@termix-ssh/plugin-sdk/ui`
|
|
29
|
+
- `PanelShell` takes a `docs` link and shows it as a book icon in the header
|
|
30
|
+
- `@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
|
|
31
|
+
- `@termix-ssh/plugin-sdk/docs` with `pluginDocsUrl()`, `pluginDocsPage()` and `pluginEnvVars()`
|
|
32
|
+
- `termix-plugin validate` warns when `docs/index.md` is missing or the source reads an env var the manifest does not list
|
|
33
|
+
|
|
3
34
|
## 1.0.2
|
|
4
35
|
|
|
5
36
|
### Added
|
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
|
|
|
@@ -28,8 +28,10 @@ npm install --save-dev @termix-ssh/plugin-sdk
|
|
|
28
28
|
|
|
29
29
|
```bash
|
|
30
30
|
npx termix-plugin build # bundle dist/backend.js and dist/frontend.js
|
|
31
|
+
npx termix-plugin patch # apply the plugin's dependency patches (build does this too)
|
|
31
32
|
npx termix-plugin test # run the plugin's Vitest suite
|
|
32
33
|
npx termix-plugin validate # check manifest.json and the files it names
|
|
34
|
+
npx termix-plugin openapi # write dist/openapi.json from @openapi comments
|
|
33
35
|
npx termix-plugin migrations # write migrations from the table definitions
|
|
34
36
|
npx termix-plugin pack # write <id>-<version>.tmxplug
|
|
35
37
|
npx termix-plugin changelog # print this version's notes from CHANGELOG.md
|
|
@@ -39,7 +41,7 @@ npx termix-plugin keygen --out <dir> # make a new signing key pair
|
|
|
39
41
|
npx termix-plugin dev --server <url> --key <tmx_...> # install on a server and reinstall on every change
|
|
40
42
|
```
|
|
41
43
|
|
|
42
|
-
`dev` needs developer mode on (
|
|
44
|
+
`dev` needs developer mode on (Settings, General) and an API key from an
|
|
43
45
|
admin account. It installs the plugin from a file, marked unverified, and
|
|
44
46
|
reinstalls it each time you save. `TERMIX_SERVER_URL` and `TERMIX_API_KEY` work
|
|
45
47
|
in place of the flags. Reload the page to pick up frontend changes.
|
package/cli/commands/build.mjs
CHANGED
|
@@ -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,35 +98,44 @@ export function applyPatches(cwd, pluginId) {
|
|
|
96
98
|
}
|
|
97
99
|
}
|
|
98
100
|
|
|
99
|
-
const
|
|
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
|
-
/**
|
|
109
|
-
* Compiles the Tailwind classes the plugin's frontend uses into
|
|
110
|
-
* dist/frontend.css, against the theme core ships in the SDK. Core only
|
|
111
|
-
* compiles its own classes, so a class no core file happens to use would
|
|
112
|
-
* otherwise have no CSS at all. Appended to whatever CSS the bundle already
|
|
113
|
-
* produced (a library's stylesheet the plugin imports).
|
|
114
|
-
*/
|
|
115
111
|
/**
|
|
116
112
|
* Moves a plugin's Tailwind layers under their own names. Core orders
|
|
117
113
|
* termix-plugin-utilities above its base styles and below its own utilities,
|
|
118
114
|
* so a plugin's copy of `.hidden` can never beat core's `md:flex` just
|
|
119
|
-
* because the plugin's file loaded later.
|
|
115
|
+
* because the plugin's file loaded later. Only classes core also ships go
|
|
116
|
+
* there; `utilities: false` keeps the rest in core's own utilities layer.
|
|
120
117
|
*/
|
|
121
|
-
export function lowerPluginLayers(css) {
|
|
118
|
+
export function lowerPluginLayers(css, { utilities = true } = {}) {
|
|
119
|
+
const layers = utilities ? "properties|utilities" : "properties";
|
|
122
120
|
return css.replace(
|
|
123
|
-
|
|
121
|
+
new RegExp(`@layer (${layers})(?=[\\s{;,])`, "g"),
|
|
124
122
|
"@layer termix-plugin-$1",
|
|
125
123
|
);
|
|
126
124
|
}
|
|
127
125
|
|
|
126
|
+
/** Classes core's CSS has rules for, or null with an SDK built before 1.0.4. */
|
|
127
|
+
function readCoreClasses() {
|
|
128
|
+
if (!fs.existsSync(CORE_CLASSES)) return null;
|
|
129
|
+
return new Set(JSON.parse(fs.readFileSync(CORE_CLASSES, "utf8")));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Compiles the Tailwind classes the plugin's frontend uses into
|
|
134
|
+
* dist/frontend.css, against the theme core ships in the SDK. Core only
|
|
135
|
+
* compiles its own classes, so a class no core file happens to use would
|
|
136
|
+
* otherwise have no CSS at all. Appended to whatever CSS the bundle already
|
|
137
|
+
* produced (a library's stylesheet the plugin imports).
|
|
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
|
-
|
|
140
|
-
|
|
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
|
|
155
|
-
|
|
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
|
}
|
package/cli/commands/dev.mjs
CHANGED
|
@@ -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
|
|
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.",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
import fs from "node:fs";
|
|
19
19
|
import path from "node:path";
|
|
20
|
-
import { fileURLToPath } from "node:url";
|
|
20
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
21
21
|
import * as esbuild from "esbuild";
|
|
22
22
|
import { BACKEND_EXTERNALS } from "../lib/externals.mjs";
|
|
23
23
|
import { readManifest, resolveEntry } from "../lib/plugin-dir.mjs";
|
|
@@ -53,7 +53,7 @@ async function loadDefinitions(cwd) {
|
|
|
53
53
|
external: BACKEND_EXTERNALS,
|
|
54
54
|
});
|
|
55
55
|
|
|
56
|
-
const module = await import(
|
|
56
|
+
const module = await import(pathToFileURL(outfile).href);
|
|
57
57
|
const tables = module.tables ?? module.default;
|
|
58
58
|
if (!Array.isArray(tables)) {
|
|
59
59
|
throw new Error(
|
|
@@ -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.
|
|
@@ -151,6 +218,11 @@ async function validateMigrations(cwd, pluginId) {
|
|
|
151
218
|
const present = DIALECTS.filter((dialect) =>
|
|
152
219
|
fs.existsSync(path.join(root, dialect)),
|
|
153
220
|
);
|
|
221
|
+
for (const dialect of DIALECTS) {
|
|
222
|
+
if (present.length > 0 && !present.includes(dialect)) {
|
|
223
|
+
problems.push(`migrations/${dialect} is missing`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
154
226
|
|
|
155
227
|
const byDialect = new Map();
|
|
156
228
|
for (const dialect of present) {
|
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
|
+
}
|
package/dist/changelog.d.ts
CHANGED
|
@@ -52,7 +52,9 @@ export declare function parseChangelog(markdown: string): {
|
|
|
52
52
|
};
|
|
53
53
|
/**
|
|
54
54
|
* Checks a CHANGELOG.md. With a manifest version, the newest release has to
|
|
55
|
-
* be that version, so a release never ships without its notes.
|
|
55
|
+
* be that version, so a release never ships without its notes. A beta like
|
|
56
|
+
* 1.1.0-beta.2 gets its notes from git, so it only needs the newest release
|
|
57
|
+
* to be 1.1.0 or older.
|
|
56
58
|
*/
|
|
57
59
|
export declare function validateChangelog(markdown: string, manifestVersion?: string): string[];
|
|
58
60
|
/**
|
package/dist/changelog.js
CHANGED
|
@@ -145,7 +145,9 @@ export function parseChangelog(markdown) {
|
|
|
145
145
|
}
|
|
146
146
|
/**
|
|
147
147
|
* Checks a CHANGELOG.md. With a manifest version, the newest release has to
|
|
148
|
-
* be that version, so a release never ships without its notes.
|
|
148
|
+
* be that version, so a release never ships without its notes. A beta like
|
|
149
|
+
* 1.1.0-beta.2 gets its notes from git, so it only needs the newest release
|
|
150
|
+
* to be 1.1.0 or older.
|
|
149
151
|
*/
|
|
150
152
|
export function validateChangelog(markdown, manifestVersion) {
|
|
151
153
|
const { changelog, problems } = parseChangelog(markdown);
|
|
@@ -154,7 +156,15 @@ export function validateChangelog(markdown, manifestVersion) {
|
|
|
154
156
|
return problems;
|
|
155
157
|
}
|
|
156
158
|
const newest = changelog.releases[0].version;
|
|
157
|
-
|
|
159
|
+
const base = manifestVersion
|
|
160
|
+
? semver.valid(semver.coerce(manifestVersion))
|
|
161
|
+
: null;
|
|
162
|
+
const betaOk = !!manifestVersion &&
|
|
163
|
+
!!semver.prerelease(manifestVersion) &&
|
|
164
|
+
!!base &&
|
|
165
|
+
!!semver.valid(newest) &&
|
|
166
|
+
semver.lte(newest, base);
|
|
167
|
+
if (manifestVersion && newest !== manifestVersion && !betaOk) {
|
|
158
168
|
problems.push(`the newest release is ${newest}, but the manifest version is ${manifestVersion}`);
|
|
159
169
|
}
|
|
160
170
|
return problems;
|
package/dist/db.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ interface Builder<T extends PluginColumn = PluginColumn> {
|
|
|
37
37
|
}
|
|
38
38
|
/** Auto-incrementing surrogate key: integer on sqlite, serial, auto_increment. */
|
|
39
39
|
export declare const id: () => Builder<PluginColumn>;
|
|
40
|
-
/** Unbounded string. Never indexable: MySQL cannot index TEXT. */
|
|
40
|
+
/** Unbounded string, LONGTEXT on MySQL. Never indexable: MySQL cannot index TEXT. */
|
|
41
41
|
export declare const text: () => Builder<PluginColumn>;
|
|
42
42
|
/** Bounded string. Indexable on every engine. */
|
|
43
43
|
export declare const varchar: (length?: number) => Builder<PluginColumn>;
|
package/dist/db.js
CHANGED
|
@@ -28,7 +28,7 @@ function builder(column) {
|
|
|
28
28
|
}
|
|
29
29
|
/** Auto-incrementing surrogate key: integer on sqlite, serial, auto_increment. */
|
|
30
30
|
export const id = () => builder({ type: "id", primaryKey: true, notNull: true });
|
|
31
|
-
/** Unbounded string. Never indexable: MySQL cannot index TEXT. */
|
|
31
|
+
/** Unbounded string, LONGTEXT on MySQL. Never indexable: MySQL cannot index TEXT. */
|
|
32
32
|
export const text = () => builder({ type: "text" });
|
|
33
33
|
/** Bounded string. Indexable on every engine. */
|
|
34
34
|
export const varchar = (length = KEY_LENGTH) => builder({ type: "varchar", length });
|