@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.
- 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 +48 -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 +67 -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,193 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import {
|
|
4
|
+
analyzeProject,
|
|
5
|
+
collectImports,
|
|
6
|
+
displayPath,
|
|
7
|
+
listFiles,
|
|
8
|
+
parsePrograms,
|
|
9
|
+
resolveProject,
|
|
10
|
+
resolveRelative,
|
|
11
|
+
toPosix,
|
|
12
|
+
} from "./rules.js";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* View helpers (doc 02 section 5.4): the relative `.js` files a view imports (and the ones
|
|
16
|
+
* those import) ship readable next to the views. The helper closure of each view is copied
|
|
17
|
+
* to `contract/src/_lib/` (path as under `src/theme/`), and the specifiers that point at a
|
|
18
|
+
* helper in the readable `contract/src` copies of the views are rewritten to the copy, so an
|
|
19
|
+
* ejected view finds its helpers.
|
|
20
|
+
*
|
|
21
|
+
* The plugin exposes `api` (rollup's plugin-to-plugin channel) for `pano-plugin.json`:
|
|
22
|
+
* `api.helpers` is a Map of view name -> helper paths relative to `src/theme/`
|
|
23
|
+
* (`['lib/sale.js']`, sorted), `api.allHelpers` the sorted union.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/** Folder of the readable helpers inside `contract/src`. */
|
|
27
|
+
export const LIB_DIR = "_lib";
|
|
28
|
+
|
|
29
|
+
/** Default package folder, relative to the plugin root (the build writes here in one pass). */
|
|
30
|
+
export const DEFAULT_OUT_DIR = "src/main/resources/plugin-ui";
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @typedef {object} HelpersOptions
|
|
34
|
+
* @property {string} [root] plugin root, default the current directory
|
|
35
|
+
* @property {string[]} [viewDirs] view folders relative to `root`
|
|
36
|
+
* @property {string} [themeDir] default `src/theme`
|
|
37
|
+
* @property {string} [controllersDir] default `<themeDir>/controllers`
|
|
38
|
+
* @property {string} [namespace]
|
|
39
|
+
* @property {string} [outDir] package folder that holds `contract/`, default `src/main/resources/plugin-ui`
|
|
40
|
+
* @property {Record<string, any>} [context] shared build context: gets `helpers` and `allHelpers`
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @param {string} file
|
|
45
|
+
* @param {string} content
|
|
46
|
+
* @returns {boolean} whether the file was written
|
|
47
|
+
*/
|
|
48
|
+
function writeIfChanged(file, content) {
|
|
49
|
+
try {
|
|
50
|
+
if (fs.readFileSync(file, "utf8") === content) return false;
|
|
51
|
+
} catch {
|
|
52
|
+
// not there yet
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
56
|
+
fs.writeFileSync(file, content);
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @param {string} dir
|
|
62
|
+
* @returns {string[]}
|
|
63
|
+
*/
|
|
64
|
+
function listSvelteCopies(dir) {
|
|
65
|
+
return listFiles([dir], (file) => file.endsWith(".svelte")).filter(
|
|
66
|
+
(file) => !toPosix(path.relative(dir, file)).startsWith(`${LIB_DIR}/`),
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Copies the helpers of every view to `<outDir>/contract/src/_lib/` and rewrites the helper
|
|
72
|
+
* specifiers in the view copies already present under `<outDir>/contract/src/`.
|
|
73
|
+
*
|
|
74
|
+
* A view copy is found by its file name (view names are unique). The specifiers are matched
|
|
75
|
+
* against the original view's folder, so only imports that resolved to a helper change.
|
|
76
|
+
*
|
|
77
|
+
* @param {import('./rules.js').KitProject} project
|
|
78
|
+
* @param {import('./rules.js').Analysis} analysis
|
|
79
|
+
* @param {string} outDir absolute package folder
|
|
80
|
+
* @returns {Promise<{ copied: string[], rewritten: string[] }>} copied helper paths (relative to src/theme) and rewritten view copies
|
|
81
|
+
*/
|
|
82
|
+
export async function writeViewHelpers(project, analysis, outDir) {
|
|
83
|
+
const contractSrc = path.join(outDir, "contract", "src");
|
|
84
|
+
const libDir = path.join(contractSrc, LIB_DIR);
|
|
85
|
+
const all = new Set(/** @type {string[]} */ ([]).concat(...analysis.helpers.values()));
|
|
86
|
+
const copied = [];
|
|
87
|
+
|
|
88
|
+
for (const helper of [...all].sort()) {
|
|
89
|
+
const relative = toPosix(path.relative(project.themeDir, helper));
|
|
90
|
+
writeIfChanged(path.join(libDir, relative), fs.readFileSync(helper, "utf8"));
|
|
91
|
+
copied.push(relative);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const rewritten = [];
|
|
95
|
+
|
|
96
|
+
if (all.size === 0 || !fs.existsSync(contractSrc)) return { copied, rewritten };
|
|
97
|
+
|
|
98
|
+
for (const copy of listSvelteCopies(contractSrc)) {
|
|
99
|
+
const name = path.basename(copy, ".svelte");
|
|
100
|
+
const original = analysis.views.get(name);
|
|
101
|
+
const closure = new Set(analysis.helpers.get(name) ?? []);
|
|
102
|
+
|
|
103
|
+
if (!original || closure.size === 0) continue;
|
|
104
|
+
|
|
105
|
+
const source = fs.readFileSync(copy, "utf8");
|
|
106
|
+
const imports = collectImports(await parsePrograms(copy, source), source);
|
|
107
|
+
let next = source;
|
|
108
|
+
|
|
109
|
+
for (const imp of [...imports].reverse()) {
|
|
110
|
+
if (!imp.spec.startsWith(".")) continue;
|
|
111
|
+
|
|
112
|
+
const target = resolveRelative(original, imp.spec);
|
|
113
|
+
|
|
114
|
+
if (!target || !closure.has(target)) continue;
|
|
115
|
+
|
|
116
|
+
let replacement = toPosix(
|
|
117
|
+
path.relative(
|
|
118
|
+
path.dirname(copy),
|
|
119
|
+
path.join(libDir, path.relative(project.themeDir, target)),
|
|
120
|
+
),
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
if (!replacement.startsWith(".")) replacement = `./${replacement}`;
|
|
124
|
+
|
|
125
|
+
next = next.slice(0, imp.start + 1) + replacement + next.slice(imp.end - 1);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (next !== source) {
|
|
129
|
+
writeIfChanged(copy, next);
|
|
130
|
+
rewritten.push(toPosix(path.relative(contractSrc, copy)));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return { copied, rewritten };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Helper closure of each view, copied readable to contract/src/_lib (doc 02 section 5.4).
|
|
139
|
+
*
|
|
140
|
+
* @param {HelpersOptions} [options]
|
|
141
|
+
* @returns {import('rollup').Plugin & { api: { readonly helpers: Map<string, string[]>, readonly allHelpers: string[] } }}
|
|
142
|
+
*/
|
|
143
|
+
export function panoHelpers(options = {}) {
|
|
144
|
+
/** @type {Map<string, string[]>} */
|
|
145
|
+
let helpers = new Map();
|
|
146
|
+
/** @type {string[]} */
|
|
147
|
+
let allHelpers = [];
|
|
148
|
+
/** @type {{ project: import('./rules.js').KitProject, analysis: import('./rules.js').Analysis } | null} */
|
|
149
|
+
let last = null;
|
|
150
|
+
|
|
151
|
+
const api = {
|
|
152
|
+
get helpers() {
|
|
153
|
+
return helpers;
|
|
154
|
+
},
|
|
155
|
+
get allHelpers() {
|
|
156
|
+
return allHelpers;
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
return {
|
|
161
|
+
name: "pano-helpers",
|
|
162
|
+
api,
|
|
163
|
+
|
|
164
|
+
async buildStart() {
|
|
165
|
+
const project = await resolveProject(options);
|
|
166
|
+
const analysis = await analyzeProject(project);
|
|
167
|
+
|
|
168
|
+
last = { project, analysis };
|
|
169
|
+
helpers = new Map(
|
|
170
|
+
[...analysis.helpers]
|
|
171
|
+
.map(([name, files]) => [name, files.map((file) => displayPath(project, file))])
|
|
172
|
+
.map(([name, files]) => [name, /** @type {string[]} */ (files).sort()]),
|
|
173
|
+
);
|
|
174
|
+
allHelpers = [...new Set(/** @type {string[]} */ ([]).concat(...helpers.values()))].sort();
|
|
175
|
+
|
|
176
|
+
if (options.context) {
|
|
177
|
+
options.context.helpers = helpers;
|
|
178
|
+
options.context.allHelpers = allHelpers;
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
|
|
182
|
+
writeBundle: {
|
|
183
|
+
order: "post",
|
|
184
|
+
sequential: true,
|
|
185
|
+
async handler() {
|
|
186
|
+
if (!last) return;
|
|
187
|
+
|
|
188
|
+
const outDir = path.resolve(last.project.root, options.outDir ?? DEFAULT_OUT_DIR);
|
|
189
|
+
await writeViewHelpers(last.project, last.analysis, outDir);
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
}
|