@panomc/plugin-kit 0.0.0-stage → 1.0.0-dev.62

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 (89) hide show
  1. package/assets/pano-bootstrap.css +17903 -0
  2. package/bin/__tests__/new/e2e.test.js +111 -0
  3. package/bin/__tests__/new/helpers.js +76 -0
  4. package/bin/__tests__/new/new.test.js +472 -0
  5. package/bin/new.js +530 -0
  6. package/bin/pano-plugin.js +162 -0
  7. package/bin/templates/plugin/README.md +30 -0
  8. package/bin/templates/plugin/_gitignore +15 -0
  9. package/bin/templates/plugin/build.gradle.kts +389 -0
  10. package/bin/templates/plugin/gradle/wrapper/gradle-wrapper.jar +0 -0
  11. package/bin/templates/plugin/gradle/wrapper/gradle-wrapper.properties +7 -0
  12. package/bin/templates/plugin/gradle.properties +55 -0
  13. package/bin/templates/plugin/gradlew +249 -0
  14. package/bin/templates/plugin/gradlew.bat +92 -0
  15. package/bin/templates/plugin/package.json.tpl +14 -0
  16. package/bin/templates/plugin/rollup.config.js +2 -0
  17. package/bin/templates/plugin/settings.gradle.kts +5 -0
  18. package/bin/templates/plugin/src/main/kotlin/__PKGPATH__/__CLASS__Plugin.kt +50 -0
  19. package/bin/templates/plugin/src/main/kotlin/__PKGPATH__/frontend/ExampleFallbackPage.kt +28 -0
  20. package/bin/templates/plugin/src/main/kotlin/__PKGPATH__/routes/GetHelloAPI.kt +19 -0
  21. package/bin/templates/plugin/src/main/kotlin/com/panomc/plugins/license/LicenseGuard.kt +30 -0
  22. package/bin/templates/plugin/src/main/kotlin/com/panomc/plugins/license/PluginLicenseClient.kt +144 -0
  23. package/bin/templates/plugin/src/main/resources/config.conf +1 -0
  24. package/bin/templates/plugin/src/main/resources/frontend-targets.json +1 -0
  25. package/bin/templates/plugin/src/main/resources/locales/en-US.json +3 -0
  26. package/bin/templates/plugin/src/main/resources/logo.png +0 -0
  27. package/bin/templates/plugin/src/theme/views/HelloPage.svelte +26 -0
  28. package/bin/ui.js +96 -0
  29. package/package.json +48 -4
  30. package/src/config.js +191 -0
  31. package/src/controller/__tests__/controller.test.js +647 -0
  32. package/src/controller/index.js +604 -0
  33. package/src/dev.js +208 -0
  34. package/src/index.js +22 -0
  35. package/src/rollup/__tests__/controllers/controllers.test.js +418 -0
  36. package/src/rollup/__tests__/controllers/fixture.js +143 -0
  37. package/src/rollup/__tests__/controllers/golden/controllers.json +34 -0
  38. package/src/rollup/__tests__/controllers/golden/controllers.types.js +69 -0
  39. package/src/rollup/__tests__/controllers/golden/pano-plugin.json +16 -0
  40. package/src/rollup/__tests__/controllers/golden/pano-plugin.lock.json +27 -0
  41. package/src/rollup/__tests__/controllers/golden/pano-plugin.with-views.json +54 -0
  42. package/src/rollup/__tests__/preset/preset.test.js +418 -0
  43. package/src/rollup/__tests__/rules/_build.js +39 -0
  44. package/src/rollup/__tests__/rules/_fixture.js +83 -0
  45. package/src/rollup/__tests__/rules/helpers.test.js +148 -0
  46. package/src/rollup/__tests__/rules/rules.test.js +259 -0
  47. package/src/rollup/__tests__/rules/stamp.test.js +113 -0
  48. package/src/rollup/__tests__/samples/samples.test.js +481 -0
  49. package/src/rollup/__tests__/seams/config.test.js +78 -0
  50. package/src/rollup/__tests__/seams/lock.test.js +124 -0
  51. package/src/rollup/__tests__/seams/sdk-seams.test.js +93 -0
  52. package/src/rollup/__tests__/seams/stubs.test.js +52 -0
  53. package/src/rollup/__tests__/views/helpers.js +82 -0
  54. package/src/rollup/__tests__/views/views.test.js +522 -0
  55. package/src/rollup/__tests__/widgets/helpers.js +117 -0
  56. package/src/rollup/__tests__/widgets/widgets.test.js +422 -0
  57. package/src/rollup/cli-build.js +90 -0
  58. package/src/rollup/cli-check.js +280 -0
  59. package/src/rollup/cli-classes.js +75 -0
  60. package/src/rollup/client-gen.js +67 -0
  61. package/src/rollup/controllers.js +434 -0
  62. package/src/rollup/entry.js +250 -0
  63. package/src/rollup/helpers.js +193 -0
  64. package/src/rollup/index.js +601 -0
  65. package/src/rollup/integrate.js +205 -0
  66. package/src/rollup/lock.js +230 -0
  67. package/src/rollup/meta.js +479 -0
  68. package/src/rollup/rules.js +950 -0
  69. package/src/rollup/samples.js +667 -0
  70. package/src/rollup/stamp.js +410 -0
  71. package/src/rollup/types.js +248 -0
  72. package/src/rollup/views.js +1205 -0
  73. package/src/rollup/widgets.js +1000 -0
  74. package/src/styles/__tests__/fallback/__snapshots__/build-fallback-css.test.js.snap +173 -0
  75. package/src/styles/__tests__/fallback/build-fallback-css.test.js +526 -0
  76. package/src/styles/__tests__/fallback/fixtures/base.css +247 -0
  77. package/src/styles/__tests__/fallback/plugins.test.js +301 -0
  78. package/src/styles/__tests__/lint/check-styles.test.js +423 -0
  79. package/src/styles/__tests__/lint/fixtures/ProductCard.golden.svelte +13 -0
  80. package/src/styles/__tests__/lint/fixtures/ProductCard.in.svelte +13 -0
  81. package/src/styles/__tests__/lint/semantic-classes.test.js +364 -0
  82. package/src/styles/bootstrap-classes.js +155 -0
  83. package/src/styles/check-styles.js +626 -0
  84. package/src/styles/fallback-css.js +1182 -0
  85. package/src/styles/plugin-css.js +237 -0
  86. package/src/styles/scan.js +206 -0
  87. package/src/styles/semantic-classes.js +436 -0
  88. package/src/styles/tokens.map.js +53 -0
  89. package/README.md +0 -3
@@ -0,0 +1,143 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import { rollup } from "rollup";
5
+ import { panoControllers } from "../../controllers.js";
6
+ import { panoMeta } from "../../meta.js";
7
+ import { panoTypes } from "../../types.js";
8
+
9
+ /** Cart controller of the fixture plugin; `retry` and `replaceRequest` are the keys the lock tests remove. */
10
+ export function cartSource({ version = 1, actions = ["add", "setQuantity", "clear", "retry"], state = ["status", "lines", "count", "replaceRequest"], extra = "" } = {}) {
11
+ const initial = { status: "'idle'", lines: "[]", count: "0", replaceRequest: "null" };
12
+ const stateBody = state.map((key) => `${key}: ${initial[key] ?? "null"}`).join(", ");
13
+ const actionBody = actions
14
+ .map((name) =>
15
+ name === "add"
16
+ ? `add(line) { c.update((s) => ({ ...s, lines: [...s.lines, line], count: double(salePrice(s.lines.length + 1)) })); return Promise.resolve({ ok: true }); }`
17
+ : `${name}() { return Promise.resolve({ ok: true }); }`,
18
+ )
19
+ .join(",\n ");
20
+
21
+ return `import { defineController } from '@panomc/plugin-kit/controller';
22
+ import { double } from 'tiny-lib';
23
+ import { salePrice } from '../lib/sale.js';
24
+ ${extra}
25
+ export default defineController({
26
+ name: 'cart',
27
+ version: ${version},
28
+ state: () => ({ ${stateBody} }),
29
+ actions: (c) => ({
30
+ ${actionBody}
31
+ }),
32
+ });
33
+ `;
34
+ }
35
+
36
+ export const FORMAT_SOURCE = `import { defineController } from '@panomc/plugin-kit/controller';
37
+ import { pad } from './_private.js';
38
+
39
+ export default defineController({
40
+ name: 'format',
41
+ version: 1,
42
+ scope: 'instance',
43
+ actions: ({ host }) => ({
44
+ money: (cents) => pad(String(cents / 100)) + ' ' + host.t('plugins.pano-plugin-demo.currency'),
45
+ }),
46
+ });
47
+ `;
48
+
49
+ export const TYPES_SOURCE = `/**
50
+ * @typedef {Object} CartState
51
+ * @property {'idle' | 'busy'} status
52
+ * @property {{ id: number }[]} lines
53
+ * @property {number} count
54
+ */
55
+
56
+ export {};
57
+ `;
58
+
59
+ /**
60
+ * Creates a plugin folder in the temp directory.
61
+ *
62
+ * @param {Record<string, string | null>} [overrides] path -> content (null removes a default file)
63
+ * @returns {string} plugin root
64
+ */
65
+ const created = [];
66
+
67
+ /** Removes every fixture folder made so far (call from afterAll). */
68
+ export function cleanupFixtures() {
69
+ for (const root of created.splice(0)) fs.rmSync(root, { recursive: true, force: true });
70
+ }
71
+
72
+ export function makeFixture(overrides = {}) {
73
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), "pano-kit-fixture-"));
74
+ created.push(root);
75
+ const files = {
76
+ "gradle.properties": "pluginId=pano-plugin-demo\n",
77
+ "package.json": JSON.stringify({ name: "demo", version: "1.2.3" }),
78
+ "node_modules/tiny-lib/package.json": JSON.stringify({ name: "tiny-lib", version: "1.0.0", type: "module", main: "index.js" }),
79
+ "node_modules/tiny-lib/index.js": "export const double = (n) => n * 2;\n",
80
+ "src/theme/lib/sale.js": "export function salePrice(n) {\n return n + 1;\n}\n",
81
+ "src/theme/controllers/cart.js": cartSource(),
82
+ "src/theme/controllers/format.js": FORMAT_SOURCE,
83
+ "src/theme/controllers/_private.js": "export const pad = (s) => s.padStart(6, '0');\n",
84
+ "src/theme/controllers/nested/ignored.js": "throw new Error('sub-folders are private code, never entries');\n",
85
+ "src/theme/controllers/types.js": TYPES_SOURCE,
86
+ ...overrides,
87
+ };
88
+
89
+ for (const [file, content] of Object.entries(files)) {
90
+ if (content === null) continue;
91
+
92
+ const target = path.join(root, file);
93
+
94
+ fs.mkdirSync(path.dirname(target), { recursive: true });
95
+ fs.writeFileSync(target, content);
96
+ }
97
+
98
+ return root;
99
+ }
100
+
101
+ export function write(root, file, content) {
102
+ const target = path.join(root, file);
103
+
104
+ fs.mkdirSync(path.dirname(target), { recursive: true });
105
+ fs.writeFileSync(target, content);
106
+ }
107
+
108
+ export function read(root, file) {
109
+ return fs.readFileSync(path.join(root, file), "utf8");
110
+ }
111
+
112
+ export const OUT = "src/main/resources/plugin-ui";
113
+
114
+ /**
115
+ * Runs one rollup build with the three plugins, the way the preset composes them.
116
+ *
117
+ * @param {string} root
118
+ * @param {{ watch?: boolean, warnings?: string[], plugins?: import('rollup').Plugin[], version?: string }} [options]
119
+ */
120
+ export async function build(root, { watch = false, warnings = [], plugins = [], version } = {}) {
121
+ const options = { root };
122
+ const bundle = await rollup({
123
+ input: "pano:test-entry",
124
+ onwarn: (warning) => warnings.push(warning.message),
125
+ plugins: [
126
+ {
127
+ name: "test-entry",
128
+ resolveId: (id) => (id === "pano:test-entry" ? "\0entry" : null),
129
+ load: (id) => (id === "\0entry" ? "export default 1;" : null),
130
+ },
131
+ ...plugins,
132
+ panoControllers(options),
133
+ panoTypes(options),
134
+ panoMeta({ ...options, watch, version }),
135
+ ],
136
+ });
137
+
138
+ try {
139
+ await bundle.write({ dir: path.join(root, OUT, "client"), format: "es" });
140
+ } finally {
141
+ await bundle.close();
142
+ }
143
+ }
@@ -0,0 +1,34 @@
1
+ {
2
+ "demo/cart": {
3
+ "version": 1,
4
+ "scope": "app",
5
+ "state": [
6
+ "status",
7
+ "lines",
8
+ "count",
9
+ "replaceRequest"
10
+ ],
11
+ "actions": [
12
+ "add",
13
+ "setQuantity",
14
+ "clear",
15
+ "retry"
16
+ ],
17
+ "types": {
18
+ "state": "CartState",
19
+ "actions": "CartActions"
20
+ }
21
+ },
22
+ "demo/format": {
23
+ "version": 1,
24
+ "scope": "instance",
25
+ "state": [],
26
+ "actions": [
27
+ "money"
28
+ ],
29
+ "types": {
30
+ "state": "FormatState",
31
+ "actions": "FormatActions"
32
+ }
33
+ }
34
+ }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * @typedef {Object} CartState
3
+ * @property {'idle' | 'busy'} status
4
+ * @property {{ id: number }[]} lines
5
+ * @property {number} count
6
+ */
7
+
8
+ export {};
9
+
10
+ // ---- generated by @panomc/plugin-kit, do not edit below this line ----
11
+
12
+ /**
13
+ * What a theme, a web component or plain JS holds. `name` is "market/cart" (namespace + "/" + spec.name).
14
+ * `get()` is a snapshot, replaced on change and never mutated.
15
+ * @template S, A
16
+ * @typedef {Object} Controller
17
+ * @property {string} name
18
+ * @property {number} version
19
+ * @property {() => S} get
20
+ * @property {(run:(s:S)=>void) => (() => void)} subscribe
21
+ * @property {A} actions
22
+ * @property {() => void} destroy
23
+ */
24
+
25
+ /**
26
+ * @typedef {Object} ControllerHost
27
+ * @property {string} baseUrl
28
+ * @property {boolean} browser
29
+ * @property {(r:{method?:string, path:string, query?:object, body?:any, headers?:object, blob?:boolean}) => Promise<any>} request
30
+ * Parsed body in doc 04's shape (non-2xx = { error: { code, ... } }). `path` is what follows "/api/v1".
31
+ * A network failure resolves { error: { code: 'NETWORK_ERROR' } }; request never rejects.
32
+ * @property {() => {user:(object|null), csrfToken:(string|null)}} session
33
+ * @property {() => (string|undefined)} locale
34
+ * @property {(fn:(s:any)=>void) => (() => void)} onSession first bind, login, logout; a no-op on the server
35
+ * @property {(key:string, values?:object) => string} t full key: "plugins.pano-plugin-market.x"
36
+ * @property {(key:string, o?:{variant?:'success'|'danger'|'warning', values?:object}) => void} toast
37
+ * @property {(kind:'local'|'session') => (Storage|null)} storage
38
+ * @property {() => number} now
39
+ * @property {(url:string, o?:{replace?:boolean}) => void} navigate
40
+ * @property {(name:string) => boolean} feature
41
+ * @property {(returnTo?:string) => string} loginUrl
42
+ * @property {(returnTo?:string) => string} registerUrl
43
+ */
44
+
45
+ /**
46
+ * What `host.request` resolves, and what an action returns when it can fail: the parsed body, or the error envelope.
47
+ * @template [T=object]
48
+ * @typedef {T | { error: { code: string, message?: string, details?: object, fields?: Record<string, string> } }} ApiResult
49
+ */
50
+
51
+ /**
52
+ * Actions of demo/cart, generated from its action names (declare CartActions in types.js to type them).
53
+ * @typedef {{ add: (...args: any[]) => any, setQuantity: (...args: any[]) => any, clear: (...args: any[]) => any, retry: (...args: any[]) => any }} CartActions
54
+ */
55
+
56
+ /**
57
+ * State of demo/format, generated from the keys of its initial state (declare FormatState in types.js to type it).
58
+ * @typedef {{}} FormatState
59
+ */
60
+
61
+ /**
62
+ * Actions of demo/format, generated from its action names (declare FormatActions in types.js to type them).
63
+ * @typedef {{ money: (...args: any[]) => any }} FormatActions
64
+ */
65
+
66
+ /**
67
+ * Every public controller of demo, by full name.
68
+ * @typedef {{ 'demo/cart': Controller<CartState, CartActions>, 'demo/format': Controller<FormatState, FormatActions> }} Controllers
69
+ */
@@ -0,0 +1,16 @@
1
+ {
2
+ "format": 1,
3
+ "pluginId": "pano-plugin-demo",
4
+ "namespace": "demo",
5
+ "version": "1.2.3",
6
+ "sdk": 2,
7
+ "controllers": "contract/controllers.json",
8
+ "views": {},
9
+ "badges": {
10
+ "controllers": true,
11
+ "samples": false,
12
+ "semanticClasses": false,
13
+ "widgets": false,
14
+ "openapi": false
15
+ }
16
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "controllers": {
3
+ "demo/cart": {
4
+ "actions": [
5
+ "add",
6
+ "setQuantity",
7
+ "clear",
8
+ "retry"
9
+ ],
10
+ "state": [
11
+ "status",
12
+ "lines",
13
+ "count",
14
+ "replaceRequest"
15
+ ],
16
+ "version": 1
17
+ },
18
+ "demo/format": {
19
+ "actions": [
20
+ "money"
21
+ ],
22
+ "state": [],
23
+ "version": 1
24
+ }
25
+ },
26
+ "format": 1
27
+ }
@@ -0,0 +1,54 @@
1
+ {
2
+ "format": 1,
3
+ "pluginId": "pano-plugin-demo",
4
+ "namespace": "demo",
5
+ "version": "1.2.3",
6
+ "sdk": 2,
7
+ "viewImports": "warn",
8
+ "contract": "contract/views.json",
9
+ "controllers": "contract/controllers.json",
10
+ "views": {
11
+ "HelloPage": {
12
+ "samples": [],
13
+ "controllers": {},
14
+ "helpers": [],
15
+ "roots": [],
16
+ "classes": []
17
+ },
18
+ "ProductCard": {
19
+ "samples": [
20
+ "filled",
21
+ "empty"
22
+ ],
23
+ "controllers": {
24
+ "demo/cart": 1,
25
+ "demo/format": 1
26
+ },
27
+ "helpers": [
28
+ "lib/sale.js"
29
+ ],
30
+ "roots": [
31
+ "div"
32
+ ],
33
+ "classes": [
34
+ "demo-product-card"
35
+ ],
36
+ "attrs": [
37
+ "title"
38
+ ]
39
+ }
40
+ },
41
+ "styles": {
42
+ "fallback": "client/fallback.css",
43
+ "own": "client/plugin.css",
44
+ "hash": "9f2c1a7e",
45
+ "icons": true
46
+ },
47
+ "badges": {
48
+ "controllers": true,
49
+ "samples": true,
50
+ "semanticClasses": true,
51
+ "widgets": false,
52
+ "openapi": false
53
+ }
54
+ }