@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.
- package/assets/pano-bootstrap.css +17903 -0
- package/bin/__tests__/new/e2e.test.js +111 -0
- package/bin/__tests__/new/helpers.js +76 -0
- package/bin/__tests__/new/new.test.js +472 -0
- package/bin/new.js +530 -0
- package/bin/pano-plugin.js +162 -0
- package/bin/templates/plugin/README.md +30 -0
- package/bin/templates/plugin/_gitignore +15 -0
- package/bin/templates/plugin/build.gradle.kts +389 -0
- package/bin/templates/plugin/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/bin/templates/plugin/gradle/wrapper/gradle-wrapper.properties +7 -0
- package/bin/templates/plugin/gradle.properties +55 -0
- package/bin/templates/plugin/gradlew +249 -0
- package/bin/templates/plugin/gradlew.bat +92 -0
- package/bin/templates/plugin/package.json.tpl +14 -0
- package/bin/templates/plugin/rollup.config.js +2 -0
- package/bin/templates/plugin/settings.gradle.kts +5 -0
- package/bin/templates/plugin/src/main/kotlin/__PKGPATH__/__CLASS__Plugin.kt +50 -0
- package/bin/templates/plugin/src/main/kotlin/__PKGPATH__/frontend/ExampleFallbackPage.kt +28 -0
- package/bin/templates/plugin/src/main/kotlin/__PKGPATH__/routes/GetHelloAPI.kt +19 -0
- package/bin/templates/plugin/src/main/kotlin/com/panomc/plugins/license/LicenseGuard.kt +30 -0
- package/bin/templates/plugin/src/main/kotlin/com/panomc/plugins/license/PluginLicenseClient.kt +144 -0
- package/bin/templates/plugin/src/main/resources/config.conf +1 -0
- package/bin/templates/plugin/src/main/resources/frontend-targets.json +1 -0
- package/bin/templates/plugin/src/main/resources/locales/en-US.json +3 -0
- package/bin/templates/plugin/src/main/resources/logo.png +0 -0
- package/bin/templates/plugin/src/theme/views/HelloPage.svelte +26 -0
- package/bin/ui.js +96 -0
- package/package.json +46 -4
- package/src/config.js +191 -0
- package/src/controller/__tests__/controller.test.js +647 -0
- package/src/controller/index.js +604 -0
- package/src/dev.js +208 -0
- package/src/index.js +22 -0
- package/src/rollup/__tests__/controllers/controllers.test.js +418 -0
- package/src/rollup/__tests__/controllers/fixture.js +143 -0
- package/src/rollup/__tests__/controllers/golden/controllers.json +34 -0
- package/src/rollup/__tests__/controllers/golden/controllers.types.js +69 -0
- package/src/rollup/__tests__/controllers/golden/pano-plugin.json +16 -0
- package/src/rollup/__tests__/controllers/golden/pano-plugin.lock.json +27 -0
- package/src/rollup/__tests__/controllers/golden/pano-plugin.with-views.json +54 -0
- package/src/rollup/__tests__/preset/preset.test.js +418 -0
- package/src/rollup/__tests__/rules/_build.js +39 -0
- package/src/rollup/__tests__/rules/_fixture.js +83 -0
- package/src/rollup/__tests__/rules/helpers.test.js +148 -0
- package/src/rollup/__tests__/rules/rules.test.js +259 -0
- package/src/rollup/__tests__/rules/stamp.test.js +113 -0
- package/src/rollup/__tests__/samples/samples.test.js +481 -0
- package/src/rollup/__tests__/seams/config.test.js +78 -0
- package/src/rollup/__tests__/seams/lock.test.js +124 -0
- package/src/rollup/__tests__/seams/sdk-seams.test.js +93 -0
- package/src/rollup/__tests__/seams/stubs.test.js +52 -0
- package/src/rollup/__tests__/views/helpers.js +82 -0
- package/src/rollup/__tests__/views/views.test.js +522 -0
- package/src/rollup/__tests__/widgets/helpers.js +117 -0
- package/src/rollup/__tests__/widgets/widgets.test.js +422 -0
- package/src/rollup/cli-build.js +90 -0
- package/src/rollup/cli-check.js +280 -0
- package/src/rollup/cli-classes.js +75 -0
- package/src/rollup/client-gen.js +72 -0
- package/src/rollup/controllers.js +434 -0
- package/src/rollup/entry.js +250 -0
- package/src/rollup/helpers.js +193 -0
- package/src/rollup/index.js +601 -0
- package/src/rollup/integrate.js +205 -0
- package/src/rollup/lock.js +230 -0
- package/src/rollup/meta.js +479 -0
- package/src/rollup/rules.js +950 -0
- package/src/rollup/samples.js +667 -0
- package/src/rollup/stamp.js +410 -0
- package/src/rollup/types.js +248 -0
- package/src/rollup/views.js +1205 -0
- package/src/rollup/widgets.js +1000 -0
- package/src/styles/__tests__/fallback/__snapshots__/build-fallback-css.test.js.snap +173 -0
- package/src/styles/__tests__/fallback/build-fallback-css.test.js +526 -0
- package/src/styles/__tests__/fallback/fixtures/base.css +247 -0
- package/src/styles/__tests__/fallback/plugins.test.js +301 -0
- package/src/styles/__tests__/lint/check-styles.test.js +423 -0
- package/src/styles/__tests__/lint/fixtures/ProductCard.golden.svelte +13 -0
- package/src/styles/__tests__/lint/fixtures/ProductCard.in.svelte +13 -0
- package/src/styles/__tests__/lint/semantic-classes.test.js +364 -0
- package/src/styles/bootstrap-classes.js +155 -0
- package/src/styles/check-styles.js +626 -0
- package/src/styles/fallback-css.js +1182 -0
- package/src/styles/plugin-css.js +237 -0
- package/src/styles/scan.js +206 -0
- package/src/styles/semantic-classes.js +436 -0
- package/src/styles/tokens.map.js +53 -0
- package/README.md +0 -3
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { afterEach, describe, expect, test } from "bun:test";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { createViewProxy } from "../../../../../sdk/src/views.js";
|
|
5
|
+
import { route } from "../../../../../sdk/src/utils/route.js";
|
|
6
|
+
import { RUNTIME_SPECIFIERS } from "../../../../../theme-core/src/kit/specifiers.js";
|
|
7
|
+
|
|
8
|
+
const packages = path.resolve(import.meta.dir, "../../../../..");
|
|
9
|
+
const NEW_SPECIFIERS = {
|
|
10
|
+
"@panomc/sdk/views": "sdk/views.js",
|
|
11
|
+
"@panomc/sdk/controllers": "sdk/controllers.js",
|
|
12
|
+
"@panomc/sdk/utils/route": "sdk/utils-route.js",
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
function setContext(context) {
|
|
16
|
+
globalThis.__PANO_CONTEXT__ = { context, listeners: [] };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
delete globalThis.__PANO_CONTEXT__;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe("createViewProxy", () => {
|
|
24
|
+
const Default = (anchor, props) => ["default", anchor, props];
|
|
25
|
+
const Override = (anchor, props) => ["override", anchor, props];
|
|
26
|
+
|
|
27
|
+
test("without a views context the default view renders", () => {
|
|
28
|
+
setContext({});
|
|
29
|
+
expect(createViewProxy("market:ProductCard", Default)("a", { p: 1 })).toEqual(["default", "a", { p: 1 }]);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("an override wins and goes through views.wrap with its source", () => {
|
|
33
|
+
const calls = [];
|
|
34
|
+
setContext({
|
|
35
|
+
views: {
|
|
36
|
+
getOverride: (name) => (name === "market:ProductCard" ? Override : null),
|
|
37
|
+
wrap: (name, C, source) => {
|
|
38
|
+
calls.push([name, source]);
|
|
39
|
+
return C;
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
expect(createViewProxy("market:ProductCard", Default)("a", {})[0]).toBe("override");
|
|
44
|
+
expect(createViewProxy("market:Other", Default)("a", {})[0]).toBe("default");
|
|
45
|
+
expect(calls).toEqual([
|
|
46
|
+
["market:ProductCard", "override"],
|
|
47
|
+
["market:Other", "default"],
|
|
48
|
+
]);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("a wrap that returns nothing falls back to the component", () => {
|
|
52
|
+
setContext({ views: { getOverride: () => null, wrap: () => undefined } });
|
|
53
|
+
expect(createViewProxy("x:Y", Default)("a", {})[0]).toBe("default");
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe("route", () => {
|
|
58
|
+
test("returns the path unchanged without a route map", () => {
|
|
59
|
+
setContext({});
|
|
60
|
+
expect(route("/profile")).toBe("/profile");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("uses routes.resolve of the pano context", () => {
|
|
64
|
+
setContext({ routes: { resolve: (p) => `/en${p}` } });
|
|
65
|
+
expect(route("/profile")).toBe("/en/profile");
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe("runtime specifiers", () => {
|
|
70
|
+
test("the three new specifiers are listed with their shim files", () => {
|
|
71
|
+
for (const [spec, file] of Object.entries(NEW_SPECIFIERS)) {
|
|
72
|
+
expect(RUNTIME_SPECIFIERS[spec]).toBe(file);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("hooks-client.js keeps one literal import() per specifier", () => {
|
|
77
|
+
const source = fs.readFileSync(path.join(packages, "theme-core/src/kit/hooks-client.js"), "utf8");
|
|
78
|
+
const mapped = [...source.matchAll(/^\s*"([^"]+)":\s*\(\)\s*=>\s*(?:\n\s*)?import\("([^"]+)"\)/gm)];
|
|
79
|
+
expect(mapped.every(([, key, target]) => key === target)).toBe(true);
|
|
80
|
+
expect(mapped.map(([, key]) => key).sort()).toEqual(Object.keys(RUNTIME_SPECIFIERS).sort());
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("the sdk package.json exports the new subpaths and the pano-api bin", () => {
|
|
84
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(packages, "sdk/package.json"), "utf8"));
|
|
85
|
+
for (const subpath of ["./views", "./controllers", "./utils/route"]) {
|
|
86
|
+
expect(pkg.exports[subpath]?.default, subpath).toBeTruthy();
|
|
87
|
+
}
|
|
88
|
+
expect(pkg.bin["pano-api"]).toBe("./bin/pano-api.js");
|
|
89
|
+
for (const subpath of ["./views", "./utils/route"]) {
|
|
90
|
+
expect(fs.existsSync(path.join(packages, "sdk", pkg.exports[subpath].default)), subpath).toBe(true);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import * as kit from "../../index.js";
|
|
3
|
+
import { panoFallbackCss } from "../../../styles/fallback-css.js";
|
|
4
|
+
import { panoSemanticClasses } from "../../../styles/semantic-classes.js";
|
|
5
|
+
import { panoPluginCss } from "../../../styles/plugin-css.js";
|
|
6
|
+
import * as root from "../../../index.js";
|
|
7
|
+
|
|
8
|
+
// The seams of unit TC-01. Most stubs have an owner by now, so this test only pins what must stay true
|
|
9
|
+
// for the rest of the kit: every name of doc 02's file map is exported, is callable with its documented
|
|
10
|
+
// options, and gives back an object with a name (a rollup plugin, or a svelte preprocessor). What each
|
|
11
|
+
// plugin does is tested by the unit that owns it and by __tests__/e2e.
|
|
12
|
+
describe("kit seams", () => {
|
|
13
|
+
test("every rollup export is a function and returns a named plugin", () => {
|
|
14
|
+
const options = {
|
|
15
|
+
panoEntry: {},
|
|
16
|
+
panoControllersModule: {},
|
|
17
|
+
panoViews: { dirs: [], namespace: "x", pluginId: "pano-plugin-x" },
|
|
18
|
+
panoRules: {},
|
|
19
|
+
panoHelpers: {},
|
|
20
|
+
panoStamp: {},
|
|
21
|
+
panoControllers: {},
|
|
22
|
+
panoMeta: { pluginId: "pano-plugin-x", namespace: "x" },
|
|
23
|
+
panoTypes: {},
|
|
24
|
+
panoSamples: {},
|
|
25
|
+
panoWidgets: { pluginId: "pano-plugin-x", namespace: "x" },
|
|
26
|
+
panoClientGen: { pluginId: "pano-plugin-x", namespace: "x" },
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
for (const [name, given] of Object.entries(options)) {
|
|
30
|
+
expect(typeof kit[name], name).toBe("function");
|
|
31
|
+
|
|
32
|
+
const plugin = kit[name](given);
|
|
33
|
+
|
|
34
|
+
expect(typeof plugin.name, name).toBe("string");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
for (const plugin of [panoFallbackCss({ ns: "x" }), panoPluginCss({ ns: "x" }), panoSemanticClasses({ ns: "x" })]) {
|
|
38
|
+
expect(typeof plugin.name).toBe("string");
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("panoPlugin returns a promise of config objects and refuses an unknown side", async () => {
|
|
43
|
+
expect(typeof kit.panoPlugin).toBe("function");
|
|
44
|
+
await expect(kit.panoPlugin({ side: "panel" })).rejects.toThrow(/side/);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("the root entry re-exports config and lock without loading rollup", () => {
|
|
48
|
+
for (const name of ["loadConfig", "namespaceOf", "readLock", "writeLockSection", "diffSection"]) {
|
|
49
|
+
expect(typeof root[name], name).toBe("function");
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
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 svelte from "rollup-plugin-svelte";
|
|
6
|
+
import { panoViews } from "../../views.js";
|
|
7
|
+
|
|
8
|
+
const made = [];
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Makes a throwaway plugin folder: gradle.properties plus the given files.
|
|
12
|
+
*
|
|
13
|
+
* @param {Record<string, string>} files path (relative to the plugin root) -> content
|
|
14
|
+
* @param {string} [pluginId]
|
|
15
|
+
* @returns {string} the plugin root
|
|
16
|
+
*/
|
|
17
|
+
export function makePlugin(files, pluginId = "pano-plugin-demo") {
|
|
18
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "kit-views-"));
|
|
19
|
+
|
|
20
|
+
made.push(root);
|
|
21
|
+
fs.writeFileSync(path.join(root, "gradle.properties"), `pluginId=${pluginId}\nversion=1.2.3\n`);
|
|
22
|
+
|
|
23
|
+
for (const [file, content] of Object.entries(files)) {
|
|
24
|
+
fs.mkdirSync(path.dirname(path.join(root, file)), { recursive: true });
|
|
25
|
+
fs.writeFileSync(path.join(root, file), content);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return root;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function cleanup() {
|
|
32
|
+
while (made.length) fs.rmSync(made.pop(), { recursive: true, force: true });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Builds `src/main.js` of the fixture with panoViews (and the svelte compiler) and writes
|
|
37
|
+
* the bundle plus the contract files into the plugin folder.
|
|
38
|
+
*
|
|
39
|
+
* @param {string} root
|
|
40
|
+
* @param {Partial<import('../../views.js').PanoViewsOptions>} [options]
|
|
41
|
+
* @param {{ write?: boolean }} [run]
|
|
42
|
+
*/
|
|
43
|
+
export async function build(root, options = {}, run = { write: true }) {
|
|
44
|
+
const views = panoViews({
|
|
45
|
+
dirs: ["src/theme/views"],
|
|
46
|
+
namespace: "demo",
|
|
47
|
+
pluginId: "pano-plugin-demo",
|
|
48
|
+
root,
|
|
49
|
+
outDir: path.join(root, "out"),
|
|
50
|
+
...options,
|
|
51
|
+
});
|
|
52
|
+
const logs = [];
|
|
53
|
+
const bundle = await rollup({
|
|
54
|
+
input: path.join(root, "src/main.js"),
|
|
55
|
+
external: [/^@panomc\/sdk/, /^svelte/],
|
|
56
|
+
onwarn: (warning) => logs.push(String(warning.message).replace(/^\[plugin pano-views\] /, "")),
|
|
57
|
+
plugins: [views, svelte({ compilerOptions: { generate: "server" } })],
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const result = run.write === false ? await bundle.generate({ format: "es" }) : await bundle.write({ dir: path.join(root, "out/server"), format: "es" });
|
|
61
|
+
|
|
62
|
+
await bundle.close();
|
|
63
|
+
|
|
64
|
+
return { views, logs, output: result.output, code: result.output.map((o) => o.code ?? "").join("\n") };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Builds and returns the error, or fails the test when the build passes. */
|
|
68
|
+
export async function buildError(root, options) {
|
|
69
|
+
try {
|
|
70
|
+
await build(root, options);
|
|
71
|
+
} catch (error) {
|
|
72
|
+
error.message = String(error.message).replace(/^\[plugin pano-views\] /, "");
|
|
73
|
+
|
|
74
|
+
return error;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
throw new Error("expected the build to fail");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export const read = (root, file) => fs.readFileSync(path.join(root, file), "utf8");
|
|
81
|
+
export const exists = (root, file) => fs.existsSync(path.join(root, file));
|
|
82
|
+
export const MAIN = `import views from "pano:views";\nexport default views;\n`;
|