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

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 +46 -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 +72 -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
package/bin/ui.js ADDED
@@ -0,0 +1,96 @@
1
+ /**
2
+ * ui.js — shared CLI presentation layer for the pano-plugin commands that talk to a person.
3
+ *
4
+ * A copy of packages/theme-core/bin/ui.js (doc 02 section 8): the kit has no dependency on the engine, so the
5
+ * file is duplicated and only the brand line and the docs address differ.
6
+ *
7
+ * Wraps @clack/prompts + picocolors so every command speaks the same visual
8
+ * language (styled intro/outro, spinners, prompts) and shares the TTY/CI
9
+ * detection that keeps check/build/new <id> safe to run non-interactively.
10
+ *
11
+ * Both packages are OPTIONAL at runtime: a consumer whose installer skipped
12
+ * the engine's transitive dependencies (bun does this for file:-linked
13
+ * submodule setups with a stale lockfile) must still be able to run
14
+ * check/build/new <id> — they just get plain, unstyled output. Only the
15
+ * interactive wizard genuinely needs @clack and says so when it's missing.
16
+ */
17
+ import { readFileSync } from "node:fs";
18
+ import { join, dirname } from "node:path";
19
+ import { fileURLToPath } from "node:url";
20
+
21
+ let clack;
22
+ try {
23
+ // computed specifier: keeps bun from resolving the import eagerly at load
24
+ clack = await import("@clack/" + "prompts");
25
+ } catch {
26
+ const line = (msg = "") => console.log(msg);
27
+ const missing = () => {
28
+ console.error(
29
+ "the interactive wizard needs @clack/prompts (run bun install in the theme, or pass arguments instead)",
30
+ );
31
+ process.exit(1);
32
+ };
33
+ clack = {
34
+ intro: line,
35
+ outro: line,
36
+ note: (msg, title) => line(title ? `\n${title}\n${msg}` : msg),
37
+ log: { info: line, warn: line, error: line, success: line, step: line, message: line },
38
+ cancel: line,
39
+ isCancel: () => false,
40
+ spinner: () => ({ start: line, stop: line, message: line }),
41
+ text: missing,
42
+ confirm: missing,
43
+ select: missing,
44
+ };
45
+ }
46
+
47
+ let pc;
48
+ try {
49
+ pc = (await import("pico" + "colors")).default;
50
+ } catch {
51
+ pc = new Proxy({}, { get: () => (s) => String(s) });
52
+ }
53
+
54
+ export { clack, pc };
55
+
56
+ // Re-export the clack primitives the commands reach for, so callers import
57
+ // from one place instead of poking at the namespace.
58
+ export const { intro, outro, text, confirm, select, spinner, cancel, isCancel, note, log } =
59
+ clack;
60
+
61
+ const binDir = dirname(fileURLToPath(import.meta.url));
62
+ export const corePkg = JSON.parse(
63
+ readFileSync(join(binDir, "..", "package.json"), "utf-8"),
64
+ );
65
+ export const version = corePkg.version;
66
+
67
+ /**
68
+ * Interactive when we own a real TTY and are not inside CI. Every command that
69
+ * might prompt gates on this — a non-interactive invocation (scripts, CI,
70
+ * postinstall, piped stdin) must never block waiting for input.
71
+ */
72
+ export function isInteractive() {
73
+ return Boolean(process.stdout.isTTY) && !process.env.CI;
74
+ }
75
+
76
+ /**
77
+ * Unwrap a clack prompt result, honoring Ctrl+C: on cancel we print the
78
+ * standard cancel line and exit non-zero so nothing half-completes.
79
+ */
80
+ export function cancelGuard(value) {
81
+ if (isCancel(value)) {
82
+ cancel("Operation cancelled.");
83
+ process.exit(1);
84
+ }
85
+ return value;
86
+ }
87
+
88
+ /** Styled brand header: "pano plugin-kit vX.Y.Z". */
89
+ export function brandIntro() {
90
+ intro(
91
+ `${pc.bgCyan(pc.black(" pano "))} ${pc.bold("plugin-kit")} ${pc.dim(`v${version}`)}`,
92
+ );
93
+ }
94
+
95
+ /** Docs entry point, referenced by the next-steps of new. */
96
+ export const DOCS_URL = "https://panomc.com/docs/";
package/package.json CHANGED
@@ -1,6 +1,48 @@
1
1
  {
2
2
  "name": "@panomc/plugin-kit",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0-dev.61",
4
+ "description": "Build tooling for Pano plugins: the panoPlugin() rollup preset, the pano-plugin CLI and the controller core.",
5
+ "author": "PanoMC",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "repository": {
9
+ "url": "https://github.com/PanoMC/sdk"
10
+ },
11
+ "exports": {
12
+ ".": "./src/index.js",
13
+ "./rollup": "./src/rollup/index.js",
14
+ "./controller": "./src/controller/index.js",
15
+ "./package.json": "./package.json"
16
+ },
17
+ "bin": {
18
+ "plugin-kit": "./bin/pano-plugin.js",
19
+ "pano-plugin": "./bin/pano-plugin.js"
20
+ },
21
+ "files": [
22
+ "src",
23
+ "bin",
24
+ "assets"
25
+ ],
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "dependencies": {
30
+ "@panomc/client-gen": "0.0.0-development",
31
+ "@rollup/plugin-node-resolve": "^16.0.0",
32
+ "@rollup/plugin-terser": "^0.4.4",
33
+ "magic-string": "^0.30.17",
34
+ "postcss": "^8.5.6",
35
+ "rollup": "^4.32.1",
36
+ "rollup-plugin-delete": "^2.1.0",
37
+ "rollup-plugin-svelte": "^7.2.2"
38
+ },
39
+ "peerDependencies": {
40
+ "svelte": "*"
41
+ },
42
+ "devDependencies": {
43
+ "bootstrap": "5.3.8",
44
+ "happy-dom": "^20.0.0",
45
+ "sass": "^1.99.0",
46
+ "typescript": "^5.9.0"
47
+ }
48
+ }
package/src/config.js ADDED
@@ -0,0 +1,191 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { pathToFileURL } from "node:url";
4
+
5
+ /**
6
+ * Plugin-level configuration of the kit (doc 01 section 1, doc 02 section 4).
7
+ *
8
+ * The plugin id comes from `gradle.properties`; everything else is optional and
9
+ * lives in `pano.plugin.js` beside it:
10
+ *
11
+ * export default { namespace: "market", viewDirs: ["src/theme/pages"], styles: {} };
12
+ */
13
+
14
+ /** Prefix stripped from a plugin id to get its default namespace (and nothing else is stripped). */
15
+ export const PLUGIN_ID_PREFIX = "pano-plugin-";
16
+
17
+ /** Namespaces no plugin may take: they are tokens of the view and route model. */
18
+ export const RESERVED_NAMESPACES = Object.freeze([
19
+ "theme",
20
+ "page",
21
+ "pano",
22
+ "core",
23
+ "route",
24
+ "home",
25
+ "block",
26
+ ]);
27
+
28
+ /** Default view folders when `pano.plugin.js` does not set `viewDirs`. */
29
+ export const DEFAULT_VIEW_DIRS = Object.freeze(["src/theme/views"]);
30
+
31
+ const NAMESPACE_PATTERN = /^[a-z0-9][a-z0-9-]*$/;
32
+
33
+ /**
34
+ * @typedef {object} PluginConfigFile
35
+ * @property {string} [namespace] overrides the namespace derived from the plugin id
36
+ * @property {string[]} [viewDirs] folders (relative to the plugin root) holding view files
37
+ * @property {Record<string, any>} [styles] doc 03 options (`safelist`, `styleAttrAllow`, ...)
38
+ */
39
+
40
+ /**
41
+ * @typedef {object} KitConfig
42
+ * @property {string} pluginId full plugin id, e.g. `pano-plugin-market`
43
+ * @property {string} namespace short namespace, e.g. `market`
44
+ * @property {string[]} viewDirs view folders relative to the plugin root
45
+ * @property {Record<string, any>} styles `styles` of `pano.plugin.js` (`{}` when absent)
46
+ * @property {string | null} sdkDir absolute `PANO_SDK_DIR` (local delivery), else `null`
47
+ */
48
+
49
+ /**
50
+ * The namespace of a plugin: `config.namespace` when set, else the plugin id minus a
51
+ * leading `pano-plugin-` (nothing else is stripped). Throws on a malformed or
52
+ * reserved namespace. The backend reads the value this function produced from
53
+ * `views.json` / `pano-plugin.json`, falling back to the same rule.
54
+ *
55
+ * @param {string} pluginId
56
+ * @param {PluginConfigFile | null | undefined} [config]
57
+ * @returns {string}
58
+ */
59
+ export function namespaceOf(pluginId, config) {
60
+ if (typeof pluginId !== "string" || pluginId.length === 0) {
61
+ throw new Error("[pano-plugin] pluginId is required to derive the namespace");
62
+ }
63
+
64
+ const explicit = config?.namespace;
65
+ const namespace =
66
+ explicit !== undefined && explicit !== null
67
+ ? explicit
68
+ : pluginId.startsWith(PLUGIN_ID_PREFIX) &&
69
+ pluginId.length > PLUGIN_ID_PREFIX.length
70
+ ? pluginId.slice(PLUGIN_ID_PREFIX.length)
71
+ : pluginId;
72
+
73
+ if (typeof namespace !== "string" || !NAMESPACE_PATTERN.test(namespace)) {
74
+ throw new Error(
75
+ `[pano-plugin] namespace "${namespace}" of ${pluginId} is invalid: use lowercase letters, digits and "-" (set namespace in pano.plugin.js)`,
76
+ );
77
+ }
78
+
79
+ if (RESERVED_NAMESPACES.includes(namespace)) {
80
+ throw new Error(
81
+ `[pano-plugin] namespace "${namespace}" of ${pluginId} is reserved (${RESERVED_NAMESPACES.join(", ")}): set another one with namespace in pano.plugin.js`,
82
+ );
83
+ }
84
+
85
+ return namespace;
86
+ }
87
+
88
+ /**
89
+ * Reads `key=value` from a `.properties` file (first match, `#` comments skipped).
90
+ *
91
+ * @param {string} file
92
+ * @param {string} key
93
+ * @returns {string | null}
94
+ */
95
+ export function readProperty(file, key) {
96
+ let text;
97
+
98
+ try {
99
+ text = fs.readFileSync(file, "utf8");
100
+ } catch {
101
+ return null;
102
+ }
103
+
104
+ for (const rawLine of text.split(/\r?\n/)) {
105
+ const line = rawLine.trim();
106
+
107
+ if (!line || line.startsWith("#") || line.startsWith("!")) continue;
108
+
109
+ const separator = line.search(/[=:]/);
110
+
111
+ if (separator < 0) continue;
112
+
113
+ if (line.slice(0, separator).trim() === key) {
114
+ return line.slice(separator + 1).trim();
115
+ }
116
+ }
117
+
118
+ return null;
119
+ }
120
+
121
+ /**
122
+ * @param {string} root
123
+ * @returns {Promise<PluginConfigFile>}
124
+ */
125
+ async function readPluginConfigFile(root) {
126
+ const file = path.join(root, "pano.plugin.js");
127
+
128
+ if (!fs.existsSync(file)) return {};
129
+
130
+ const module = await import(pathToFileURL(file).href);
131
+ const config = module.default ?? {};
132
+
133
+ if (typeof config !== "object" || config === null || Array.isArray(config)) {
134
+ throw new Error(
135
+ "[pano-plugin] pano.plugin.js must export default an object: { namespace?, viewDirs?, styles? }",
136
+ );
137
+ }
138
+
139
+ return config;
140
+ }
141
+
142
+ /**
143
+ * Loads the kit configuration of the plugin in `root`.
144
+ *
145
+ * @param {string} [root] plugin root, default the current directory
146
+ * @returns {Promise<KitConfig>}
147
+ */
148
+ export async function loadConfig(root = process.cwd()) {
149
+ const absoluteRoot = path.resolve(root);
150
+ const pluginId = readProperty(
151
+ path.join(absoluteRoot, "gradle.properties"),
152
+ "pluginId",
153
+ );
154
+
155
+ if (!pluginId) {
156
+ throw new Error(
157
+ `[pano-plugin] no pluginId in ${path.join(absoluteRoot, "gradle.properties")}: add a line "pluginId=pano-plugin-<name>"`,
158
+ );
159
+ }
160
+
161
+ const file = await readPluginConfigFile(absoluteRoot);
162
+
163
+ let viewDirs = [...DEFAULT_VIEW_DIRS];
164
+
165
+ if (file.viewDirs !== undefined) {
166
+ if (
167
+ !Array.isArray(file.viewDirs) ||
168
+ file.viewDirs.length === 0 ||
169
+ file.viewDirs.some((dir) => typeof dir !== "string" || dir.length === 0)
170
+ ) {
171
+ throw new Error(
172
+ '[pano-plugin] viewDirs in pano.plugin.js must be a non-empty array of folder paths, e.g. ["src/theme/views"]',
173
+ );
174
+ }
175
+
176
+ viewDirs = file.viewDirs.map((dir) => dir.replace(/\\/g, "/").replace(/\/+$/, ""));
177
+ }
178
+
179
+ const sdkEnv = process.env.PANO_SDK_DIR;
180
+
181
+ return {
182
+ pluginId,
183
+ namespace: namespaceOf(pluginId, file),
184
+ viewDirs,
185
+ styles:
186
+ file.styles && typeof file.styles === "object" && !Array.isArray(file.styles)
187
+ ? file.styles
188
+ : {},
189
+ sdkDir: sdkEnv ? path.resolve(absoluteRoot, sdkEnv) : null,
190
+ };
191
+ }