@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,111 @@
|
|
|
1
|
+
import { afterAll, describe, expect, test } from 'bun:test';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { spawnSync } from 'node:child_process';
|
|
5
|
+
import { PACKAGE, bin, capture, cleanup, filesBelow, makePluginsDir, sdkDir, themeCore } from './helpers.js';
|
|
6
|
+
|
|
7
|
+
afterAll(cleanup);
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {string} cwd
|
|
11
|
+
* @param {string[]} args
|
|
12
|
+
*/
|
|
13
|
+
function cli(cwd, args) {
|
|
14
|
+
const result = spawnSync(process.execPath, [bin, ...args], {
|
|
15
|
+
cwd,
|
|
16
|
+
encoding: 'utf8',
|
|
17
|
+
env: { ...process.env, PANO_SDK_DIR: sdkDir },
|
|
18
|
+
timeout: 120000,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
return { code: result.status ?? -1, stdout: result.stdout, stderr: result.stderr };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
describe('pano-plugin new, then check and the UI build, with no edit in between', () => {
|
|
25
|
+
const plugins = makePluginsDir();
|
|
26
|
+
const root = path.join(plugins, 'my-plugin');
|
|
27
|
+
const scaffolded = cli(plugins, ['new', 'my-plugin', '--local', themeCore, '--no-install']);
|
|
28
|
+
|
|
29
|
+
test('the CLI scaffolds the folder (and the help lists the command)', () => {
|
|
30
|
+
expect(scaffolded.stderr).toBe('');
|
|
31
|
+
expect(scaffolded.code).toBe(0);
|
|
32
|
+
expect(fs.existsSync(path.join(root, 'src/theme/views/HelloPage.svelte'))).toBe(true);
|
|
33
|
+
expect(cli(plugins, ['--help']).stdout).toContain('new [<id>]');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// a real install is not run here: the workspace node_modules stands in for it, like the other kit tests
|
|
37
|
+
fs.symlinkSync(path.join(themeCore, 'node_modules'), path.join(root, 'node_modules'));
|
|
38
|
+
|
|
39
|
+
const before = fs.existsSync(root) ? filesBelow(root).filter((name) => !name.startsWith('node_modules/')) : [];
|
|
40
|
+
const checked = cli(root, ['check']);
|
|
41
|
+
const built = cli(root, ['build']);
|
|
42
|
+
|
|
43
|
+
test('pano-plugin check passes on the untouched scaffold', () => {
|
|
44
|
+
expect(checked.stderr).toBe('');
|
|
45
|
+
expect(checked.code).toBe(0);
|
|
46
|
+
expect(checked.stdout).toContain('check passed (0 warnings)');
|
|
47
|
+
expect(checked.stdout).toContain('public (readable): 1 view, 0 helpers · closed: 0 controllers');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('the UI build writes the package: one page /my-plugin, contract 1', () => {
|
|
51
|
+
expect(built.stderr).toBe('');
|
|
52
|
+
expect(built.code).toBe(0);
|
|
53
|
+
|
|
54
|
+
const views = JSON.parse(fs.readFileSync(path.join(root, PACKAGE, 'contract/views.json'), 'utf8'));
|
|
55
|
+
|
|
56
|
+
expect(views.pluginId).toBe('my-plugin');
|
|
57
|
+
expect(Object.keys(views.views)).toEqual(['my-plugin:HelloPage']);
|
|
58
|
+
expect(views.views['my-plugin:HelloPage']).toMatchObject({ kind: 'page', contract: 1, page: { path: '/my-plugin' } });
|
|
59
|
+
|
|
60
|
+
for (const side of ['client', 'server']) {
|
|
61
|
+
const bundle = filesBelow(path.join(root, PACKAGE, side))
|
|
62
|
+
.filter((name) => name.endsWith('.js') || name.endsWith('.mjs'))
|
|
63
|
+
.map((name) => fs.readFileSync(path.join(root, PACKAGE, side, name), 'utf8'))
|
|
64
|
+
.join('\n');
|
|
65
|
+
|
|
66
|
+
// the page calls the plugin's own API through the virtual @panomc/sdk/plugin-api module
|
|
67
|
+
expect(bundle, side).toContain('createPluginApi');
|
|
68
|
+
expect(bundle, side).toContain('"my-plugin"');
|
|
69
|
+
expect(bundle, side).toContain('/hello');
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('the build wrote only build output and the lock: no source file of the scaffold changed', () => {
|
|
74
|
+
const after = filesBelow(root).filter((name) => !name.startsWith('node_modules/') && !name.startsWith(PACKAGE));
|
|
75
|
+
|
|
76
|
+
// pano-plugin.lock.json is the view / controller promise the build records; the author commits it
|
|
77
|
+
expect(after).toEqual([...before, 'pano-plugin.lock.json'].sort());
|
|
78
|
+
expect(fs.readFileSync(path.join(root, 'src/main/resources/frontend-targets.json'), 'utf8')).toBe('{}\n');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('step count', () => {
|
|
82
|
+
const next = scaffolded.stdout.split('\n').filter((line) => /^\s+\d+\.\s/.test(line));
|
|
83
|
+
// the command itself is step 1; the printed list holds the steps after it, the install is part of the scaffold
|
|
84
|
+
const steps = 1 + next.length;
|
|
85
|
+
const written = 0; // check and build passed above without a single edit after the scaffold
|
|
86
|
+
|
|
87
|
+
console.log(`pano-plugin new: steps to first result = ${steps} (scaffold, dev, restart Pano), files written by hand = ${written}`);
|
|
88
|
+
|
|
89
|
+
expect(steps).toBe(3);
|
|
90
|
+
expect(scaffolded.stdout).toContain(`Steps to first result: ${steps} (scaffold, dev, restart Pano), ${written} files written`);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe('scaffold errors through the CLI', () => {
|
|
95
|
+
test('an existing folder is refused with exit code 1', () => {
|
|
96
|
+
const plugins = makePluginsDir();
|
|
97
|
+
|
|
98
|
+
fs.mkdirSync(path.join(plugins, 'taken'));
|
|
99
|
+
|
|
100
|
+
const result = cli(plugins, ['new', 'taken', '--no-install']);
|
|
101
|
+
|
|
102
|
+
expect(result.code).toBe(1);
|
|
103
|
+
expect(result.stderr).toContain('pano-plugin new: ');
|
|
104
|
+
expect(result.stderr).toContain('already exists');
|
|
105
|
+
expect(fs.readdirSync(path.join(plugins, 'taken'))).toEqual([]);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('capture helper stays quiet when nothing ran', () => {
|
|
109
|
+
expect(capture().stdout()).toBe('');
|
|
110
|
+
});
|
|
111
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
|
|
6
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
|
|
8
|
+
export const kitDir = path.resolve(here, '../../..');
|
|
9
|
+
export const themeCore = path.resolve(kitDir, '../..');
|
|
10
|
+
export const sdkDir = path.join(themeCore, 'packages/sdk');
|
|
11
|
+
export const bin = path.join(kitDir, 'bin/pano-plugin.js');
|
|
12
|
+
export const PACKAGE = 'src/main/resources/plugin-ui';
|
|
13
|
+
|
|
14
|
+
/** @type {string[]} */
|
|
15
|
+
const created = [];
|
|
16
|
+
|
|
17
|
+
export function cleanup() {
|
|
18
|
+
for (const folder of created.splice(0)) fs.rmSync(folder, { recursive: true, force: true });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A throw-away `plugins` folder to run `new` in.
|
|
23
|
+
*
|
|
24
|
+
* @returns {string}
|
|
25
|
+
*/
|
|
26
|
+
export function makePluginsDir() {
|
|
27
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'pano-kit-new-'));
|
|
28
|
+
const plugins = path.join(root, 'plugins');
|
|
29
|
+
|
|
30
|
+
fs.mkdirSync(plugins);
|
|
31
|
+
created.push(root);
|
|
32
|
+
|
|
33
|
+
return plugins;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Output collector for `runNew`.
|
|
38
|
+
*
|
|
39
|
+
* @returns {{ out: (line: string) => void, err: (line: string) => void, stdout: () => string, stderr: () => string }}
|
|
40
|
+
*/
|
|
41
|
+
export function capture() {
|
|
42
|
+
/** @type {string[]} */
|
|
43
|
+
const stdout = [];
|
|
44
|
+
/** @type {string[]} */
|
|
45
|
+
const stderr = [];
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
out: (line) => stdout.push(line),
|
|
49
|
+
err: (line) => stderr.push(line),
|
|
50
|
+
stdout: () => stdout.join('\n'),
|
|
51
|
+
stderr: () => stderr.join('\n'),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Relative names of every file below `dir`, sorted.
|
|
57
|
+
*
|
|
58
|
+
* @param {string} dir
|
|
59
|
+
* @returns {string[]}
|
|
60
|
+
*/
|
|
61
|
+
export function filesBelow(dir) {
|
|
62
|
+
/** @type {string[]} */
|
|
63
|
+
const found = [];
|
|
64
|
+
const visit = (current) => {
|
|
65
|
+
for (const entry of fs.readdirSync(current, { withFileTypes: true })) {
|
|
66
|
+
const full = path.join(current, entry.name);
|
|
67
|
+
|
|
68
|
+
if (entry.isDirectory()) visit(full);
|
|
69
|
+
else found.push(path.relative(dir, full).split(path.sep).join('/'));
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
visit(dir);
|
|
74
|
+
|
|
75
|
+
return found.sort();
|
|
76
|
+
}
|
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
import { afterAll, describe, expect, test } from 'bun:test';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import {
|
|
5
|
+
checkId,
|
|
6
|
+
checkPackage,
|
|
7
|
+
checkText,
|
|
8
|
+
classNameOf,
|
|
9
|
+
defaultPackage,
|
|
10
|
+
parseNewArgs,
|
|
11
|
+
runNew,
|
|
12
|
+
targetPath,
|
|
13
|
+
templateValues,
|
|
14
|
+
titleFrom,
|
|
15
|
+
} from '../../new.js';
|
|
16
|
+
import { capture, cleanup, filesBelow, kitDir, makePluginsDir, themeCore } from './helpers.js';
|
|
17
|
+
|
|
18
|
+
afterAll(cleanup);
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Runs `new` with `--no-install --local <this checkout>`.
|
|
22
|
+
*
|
|
23
|
+
* @param {string} cwd
|
|
24
|
+
* @param {string[]} args
|
|
25
|
+
* @param {Record<string, any>} [options]
|
|
26
|
+
*/
|
|
27
|
+
async function scaffold(cwd, args, options = {}) {
|
|
28
|
+
const io = capture();
|
|
29
|
+
const code = await runNew([...args, '--no-install', '--local', themeCore], { cwd, interactive: false, out: io.out, err: io.err, ...options });
|
|
30
|
+
|
|
31
|
+
return { code, stdout: io.stdout(), stderr: io.stderr() };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
describe('template text: the Gradle files compile and the version gate lets a fresh plugin in', () => {
|
|
35
|
+
const template = path.join(kitDir, 'bin/templates/plugin');
|
|
36
|
+
const gradle = fs.readFileSync(path.join(template, 'build.gradle.kts'), 'utf8');
|
|
37
|
+
const properties = fs.readFileSync(path.join(template, 'gradle.properties'), 'utf8');
|
|
38
|
+
|
|
39
|
+
test('java.util classes are imported, never written out (inside a Gradle script `java.` is the java {} extension)', () => {
|
|
40
|
+
const lines = gradle.split('\n').filter((line) => line.includes('java.util.'));
|
|
41
|
+
|
|
42
|
+
expect(lines).toEqual(['import java.util.Properties', 'import java.util.zip.ZipFile']);
|
|
43
|
+
expect(gradle).toContain('ZipFile(jar)');
|
|
44
|
+
expect(gradle).toContain('Properties()');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('apiLevel=1 is an active line with the comment that says when to delete it', () => {
|
|
48
|
+
expect(properties).toMatch(/^apiLevel=1$/m);
|
|
49
|
+
expect(properties).toContain('Delete this line once the Pano');
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('names derived from the id', () => {
|
|
54
|
+
test('title, class and package', () => {
|
|
55
|
+
expect(titleFrom('my-plugin')).toBe('My Plugin');
|
|
56
|
+
expect(classNameOf('shop')).toBe('Shop');
|
|
57
|
+
expect(classNameOf('my-shop')).toBe('MyShop');
|
|
58
|
+
// the scaffold adds `Plugin` itself, so a trailing "plugin" and the official prefix are dropped
|
|
59
|
+
expect(classNameOf('my-plugin')).toBe('My');
|
|
60
|
+
expect(classNameOf('pano-plugin-market')).toBe('Market');
|
|
61
|
+
expect(classNameOf('plugin')).toBe('Plugin');
|
|
62
|
+
expect(classNameOf('pano-plugin-3d')).toBe('P3d');
|
|
63
|
+
expect(defaultPackage('my-shop')).toBe('com.example.myshop');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('every placeholder of the templates has a value (writeScaffold would throw otherwise)', () => {
|
|
67
|
+
const values = templateValues({ id: 'pano-plugin-market', name: 'Market', author: 'Pano', pkg: 'com.panomc.market', local: null, install: false }, '1.2.3');
|
|
68
|
+
|
|
69
|
+
expect(values).toMatchObject({
|
|
70
|
+
ID: 'pano-plugin-market',
|
|
71
|
+
NS: 'market',
|
|
72
|
+
CLASS: 'Market',
|
|
73
|
+
PKGPATH: 'com/panomc/market',
|
|
74
|
+
KIT_DEP: '^1.2.3',
|
|
75
|
+
SDK_DEP: '^1.2.3',
|
|
76
|
+
ORG: 'pano',
|
|
77
|
+
});
|
|
78
|
+
expect(targetPath('src/main/kotlin/__PKGPATH__/__CLASS__Plugin.kt', values)).toBe('src/main/kotlin/com/panomc/market/MarketPlugin.kt');
|
|
79
|
+
expect(targetPath('_gitignore', values)).toBe('.gitignore');
|
|
80
|
+
expect(targetPath('package.json.tpl', values)).toBe('package.json');
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe('input checks', () => {
|
|
85
|
+
const plugins = makePluginsDir();
|
|
86
|
+
|
|
87
|
+
test('ids', () => {
|
|
88
|
+
expect(checkId('my-plugin', plugins)).toBeNull();
|
|
89
|
+
expect(checkId('My-Plugin', plugins)).toContain('kebab-case');
|
|
90
|
+
expect(checkId('1plugin', plugins)).toContain('kebab-case');
|
|
91
|
+
expect(checkId('a--b', plugins)).toContain('kebab-case');
|
|
92
|
+
expect(checkId('trailing-', plugins)).toContain('kebab-case');
|
|
93
|
+
expect(checkId('core', plugins)).toContain('reserved');
|
|
94
|
+
expect(checkId('page', plugins)).toContain('reserved');
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('an existing folder is refused, even an empty one', () => {
|
|
98
|
+
fs.mkdirSync(path.join(plugins, 'taken'));
|
|
99
|
+
|
|
100
|
+
expect(checkId('taken', plugins)).toContain('already exists');
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test('Kotlin packages', () => {
|
|
104
|
+
expect(checkPackage('com.example.shop')).toBeNull();
|
|
105
|
+
expect(checkPackage('shop')).toBeNull();
|
|
106
|
+
expect(checkPackage('Com.Example')).toContain('not a Kotlin package');
|
|
107
|
+
expect(checkPackage('com..example')).toContain('not a Kotlin package');
|
|
108
|
+
expect(checkPackage('com.example.new')).toContain('reserved word');
|
|
109
|
+
expect(checkPackage('com.1example')).toContain('not a Kotlin package');
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test('names and authors that would break a file are refused', () => {
|
|
113
|
+
expect(checkText('Ahmet Düruer', 'the author')).toBeNull();
|
|
114
|
+
for (const bad of ['a"b', 'a\\b', 'a<b', 'a{b', 'a$b', 'a@@b', 'a\nb', '']) {
|
|
115
|
+
expect(checkText(bad, 'the name'), JSON.stringify(bad)).toContain('the name');
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test('argument parsing', () => {
|
|
120
|
+
expect(parseNewArgs(['shop', '--package', 'a.b', '--local', '/x', '--no-install'])).toEqual({
|
|
121
|
+
id: 'shop',
|
|
122
|
+
flags: { package: 'a.b', local: '/x', install: false },
|
|
123
|
+
});
|
|
124
|
+
expect(parseNewArgs(['--local']).flags.local).toBe(true);
|
|
125
|
+
expect(parseNewArgs(['shop', '--local', '--no-install']).flags).toEqual({ local: true, install: false });
|
|
126
|
+
expect(parseNewArgs(['shop', '--package=a.b']).flags.package).toBe('a.b');
|
|
127
|
+
expect(() => parseNewArgs(['a', 'b'])).toThrow('one plugin id');
|
|
128
|
+
expect(() => parseNewArgs(['--nope'])).toThrow('unknown option --nope');
|
|
129
|
+
expect(() => parseNewArgs(['a', '--package'])).toThrow('--package needs a value');
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe('the scaffold', () => {
|
|
134
|
+
const plugins = makePluginsDir();
|
|
135
|
+
/** @type {Awaited<ReturnType<typeof scaffold>>} */
|
|
136
|
+
let result;
|
|
137
|
+
const root = path.join(plugins, 'my-shop');
|
|
138
|
+
const read = (relative) => fs.readFileSync(path.join(root, relative), 'utf8');
|
|
139
|
+
|
|
140
|
+
test('runs without questions, exits 0 and tells the three steps', async () => {
|
|
141
|
+
result = await scaffold(plugins, ['my-shop']);
|
|
142
|
+
|
|
143
|
+
expect(result.stderr).toBe('');
|
|
144
|
+
expect(result.code).toBe(0);
|
|
145
|
+
expect(result.stdout).toContain('scaffolded my-shop/ (21 files, local workspace links)');
|
|
146
|
+
expect(result.stdout).toContain('1. cd my-shop && bun install && bun run dev');
|
|
147
|
+
expect(result.stdout).toContain('2. restart Pano once, then open /my-shop');
|
|
148
|
+
expect(result.stdout).toContain('Steps to first result: 3 (scaffold, dev, restart Pano), 0 files written');
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test('writes exactly the files of doc 02 section 8', () => {
|
|
152
|
+
expect(filesBelow(root)).toEqual([
|
|
153
|
+
'.gitignore',
|
|
154
|
+
'README.md',
|
|
155
|
+
'build.gradle.kts',
|
|
156
|
+
'gradle.properties',
|
|
157
|
+
'gradle/wrapper/gradle-wrapper.jar',
|
|
158
|
+
'gradle/wrapper/gradle-wrapper.properties',
|
|
159
|
+
'gradlew',
|
|
160
|
+
'gradlew.bat',
|
|
161
|
+
'package.json',
|
|
162
|
+
'rollup.config.js',
|
|
163
|
+
'settings.gradle.kts',
|
|
164
|
+
'src/main/kotlin/com/example/myshop/MyShopPlugin.kt',
|
|
165
|
+
'src/main/kotlin/com/example/myshop/frontend/ExampleFallbackPage.kt',
|
|
166
|
+
'src/main/kotlin/com/example/myshop/routes/GetHelloAPI.kt',
|
|
167
|
+
'src/main/kotlin/com/panomc/plugins/license/LicenseGuard.kt',
|
|
168
|
+
'src/main/kotlin/com/panomc/plugins/license/PluginLicenseClient.kt',
|
|
169
|
+
'src/main/resources/config.conf',
|
|
170
|
+
'src/main/resources/frontend-targets.json',
|
|
171
|
+
'src/main/resources/locales/en-US.json',
|
|
172
|
+
'src/main/resources/logo.png',
|
|
173
|
+
'src/theme/views/HelloPage.svelte',
|
|
174
|
+
]);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test('no placeholder is left in a text file and no template suffix survives', () => {
|
|
178
|
+
for (const file of filesBelow(root)) {
|
|
179
|
+
if (/\.(jar|png)$/.test(file)) continue;
|
|
180
|
+
|
|
181
|
+
expect(read(file), file).not.toMatch(/@@[A-Z_]+@@/);
|
|
182
|
+
expect(file.endsWith('.tpl'), file).toBe(false);
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
test('package.json: two devDependencies, file: links, kit scripts', () => {
|
|
187
|
+
const pkg = JSON.parse(read('package.json'));
|
|
188
|
+
|
|
189
|
+
expect(pkg.name).toBe('my-shop');
|
|
190
|
+
expect(pkg.devDependencies).toEqual({
|
|
191
|
+
'@panomc/plugin-kit': `file:${path.join(themeCore, 'packages/plugin-kit')}`,
|
|
192
|
+
'@panomc/sdk': `file:${path.join(themeCore, 'packages/sdk')}`,
|
|
193
|
+
});
|
|
194
|
+
expect(pkg.scripts).toEqual({ dev: 'pano-plugin dev', build: 'pano-plugin build', check: 'pano-plugin check' });
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
test('rollup.config.js is the two lines of the preset', () => {
|
|
198
|
+
expect(read('rollup.config.js')).toBe("import { panoPlugin } from '@panomc/plugin-kit/rollup';\nexport default panoPlugin();\n");
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
test('gradle.properties and Gradle files carry the id, class, api-level helper and copyJar fallback', () => {
|
|
202
|
+
const properties = read('gradle.properties');
|
|
203
|
+
|
|
204
|
+
expect(properties).toContain('pluginId=my-shop\n');
|
|
205
|
+
expect(properties).toContain('pluginName=My Shop\n');
|
|
206
|
+
expect(properties).toContain('pluginClass=com.example.myshop.MyShopPlugin\n');
|
|
207
|
+
expect(properties).toContain('pluginDeveloper=CHANGE-ME\n');
|
|
208
|
+
expect(properties).toContain('panoPluginsDir=..\n');
|
|
209
|
+
|
|
210
|
+
const gradle = read('build.gradle.kts');
|
|
211
|
+
|
|
212
|
+
expect(gradle).toContain('group = "com.example.myshop"');
|
|
213
|
+
expect(gradle).toContain('rootProject.findProperty("panoApiLevel")');
|
|
214
|
+
expect(gradle).toContain('pano-api-level.properties');
|
|
215
|
+
expect(gradle).toContain('attributes["api-level"] = it');
|
|
216
|
+
expect(gradle).toContain('rootProject.extra.has("pluginsDir")');
|
|
217
|
+
expect(gradle).toContain('findProperty("panoPluginsDir")');
|
|
218
|
+
expect(fs.statSync(path.join(root, 'gradlew')).mode & 0o111).not.toBe(0);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test('Kotlin: plugin class, hello endpoint with a relative path, commented fallback page', () => {
|
|
222
|
+
const plugin = read('src/main/kotlin/com/example/myshop/MyShopPlugin.kt');
|
|
223
|
+
|
|
224
|
+
expect(plugin).toContain('package com.example.myshop\n');
|
|
225
|
+
expect(plugin).toContain('class MyShopPlugin : PanoPlugin()');
|
|
226
|
+
|
|
227
|
+
const hello = read('src/main/kotlin/com/example/myshop/routes/GetHelloAPI.kt');
|
|
228
|
+
|
|
229
|
+
expect(hello).toContain('package com.example.myshop.routes');
|
|
230
|
+
expect(hello).toContain('Path("/hello", RouteType.GET)');
|
|
231
|
+
expect(hello).toContain('"message" to "hi"');
|
|
232
|
+
expect(hello).not.toContain('Path("/api');
|
|
233
|
+
// declared, so the class compiles against the pinned Pano tag (abstract member) and against the new one (open)
|
|
234
|
+
expect(hello).toContain('override fun getValidationHandler(schemaRepository: SchemaRepository): ValidationHandler? = null');
|
|
235
|
+
expect(hello).toContain('import io.vertx.json.schema.SchemaRepository');
|
|
236
|
+
expect(hello).toContain('import io.vertx.ext.web.validation.ValidationHandler');
|
|
237
|
+
|
|
238
|
+
const fallback = read('src/main/kotlin/com/example/myshop/frontend/ExampleFallbackPage.kt').split('\n');
|
|
239
|
+
const code = fallback.filter((line) => line.trim() && !line.trim().startsWith('//'));
|
|
240
|
+
|
|
241
|
+
// a package line and nothing else: the example is entirely commented out
|
|
242
|
+
expect(code).toEqual(['package com.example.myshop.frontend']);
|
|
243
|
+
expect(fallback.join('\n')).toContain('"my-shop.order"');
|
|
244
|
+
expect(fallback.join('\n')).not.toContain('/*');
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
test('resources: empty targets file, one locale, config', () => {
|
|
248
|
+
expect(JSON.parse(read('src/main/resources/frontend-targets.json'))).toEqual({});
|
|
249
|
+
expect(fs.readdirSync(path.join(root, 'src/main/resources/locales'))).toEqual(['en-US.json']);
|
|
250
|
+
expect(JSON.parse(read('src/main/resources/locales/en-US.json'))).toEqual({ 'hello-title': 'Hello from My Shop' });
|
|
251
|
+
expect(read('src/main/resources/config.conf')).toBe('logo-file=logo.png\n');
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
test('HelloPage: path /<id>, shows api.get({ path: "/hello" })', () => {
|
|
255
|
+
const page = read('src/theme/views/HelloPage.svelte');
|
|
256
|
+
|
|
257
|
+
expect(page).toContain("export const view = { path: '/my-shop' };");
|
|
258
|
+
expect(page).toContain("import { api } from '@panomc/sdk/plugin-api';");
|
|
259
|
+
expect(page).toContain("api.get({ path: '/hello', request: event })");
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
test('README carries the quick-start box of QUICKSTART-PLUGIN.md', () => {
|
|
263
|
+
const readme = read('README.md');
|
|
264
|
+
const quickstart = fs.readFileSync(path.join(themeCore, 'docs/QUICKSTART-PLUGIN.md'), 'utf8');
|
|
265
|
+
const box = /```\n(Needs: JDK 17\+[\s\S]*?)```/.exec(quickstart)?.[1];
|
|
266
|
+
|
|
267
|
+
expect(box).toBeTruthy();
|
|
268
|
+
expect(readme).toContain(/** @type {string} */ (box));
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
test('a second run into the same id is refused and leaves the folder untouched', async () => {
|
|
272
|
+
fs.writeFileSync(path.join(root, 'mine.txt'), 'keep');
|
|
273
|
+
|
|
274
|
+
const again = await scaffold(plugins, ['my-shop']);
|
|
275
|
+
|
|
276
|
+
expect(again.code).toBe(1);
|
|
277
|
+
expect(again.stderr).toContain('already exists');
|
|
278
|
+
expect(fs.readFileSync(path.join(root, 'mine.txt'), 'utf8')).toBe('keep');
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
describe('options', () => {
|
|
283
|
+
test('--package, --name and --author are honoured and non-ASCII goes into gradle.properties escaped', async () => {
|
|
284
|
+
const plugins = makePluginsDir();
|
|
285
|
+
const result = await scaffold(plugins, ['pano-plugin-market', '--package', 'com.panomc.market', '--name', 'Mağaza', '--author', 'Ahmet Düruer']);
|
|
286
|
+
const root = path.join(plugins, 'pano-plugin-market');
|
|
287
|
+
|
|
288
|
+
expect(result.stderr).toBe('');
|
|
289
|
+
expect(fs.existsSync(path.join(root, 'src/main/kotlin/com/panomc/market/MarketPlugin.kt'))).toBe(true);
|
|
290
|
+
|
|
291
|
+
const properties = fs.readFileSync(path.join(root, 'gradle.properties'), 'utf8');
|
|
292
|
+
|
|
293
|
+
expect(properties).toContain('pluginName=Ma\\u011faza');
|
|
294
|
+
expect(properties).toContain('pluginDeveloper=Ahmet D\\u00fcruer');
|
|
295
|
+
expect(properties).toContain('organization=ahmet-d-ruer');
|
|
296
|
+
expect(fs.readFileSync(path.join(root, 'src/main/resources/locales/en-US.json'), 'utf8')).toContain('Hello from Mağaza');
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
test('refusals print the fix and write nothing', async () => {
|
|
300
|
+
const plugins = makePluginsDir();
|
|
301
|
+
|
|
302
|
+
for (const [args, message] of /** @type {[string[], string][]} */ ([
|
|
303
|
+
[['Bad_Id'], 'kebab-case'],
|
|
304
|
+
[['core'], 'reserved'],
|
|
305
|
+
[['shop', '--package', 'com.example.class'], 'reserved word'],
|
|
306
|
+
[['shop', '--name', 'a"b'], 'the name'],
|
|
307
|
+
])) {
|
|
308
|
+
const result = await scaffold(plugins, args);
|
|
309
|
+
|
|
310
|
+
expect(result.code, args.join(' ')).toBe(1);
|
|
311
|
+
expect(result.stderr, args.join(' ')).toContain(message);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
expect(fs.readdirSync(plugins)).toEqual([]);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
test('--local must point at a theme-core checkout', async () => {
|
|
318
|
+
const plugins = makePluginsDir();
|
|
319
|
+
const io = capture();
|
|
320
|
+
const code = await runNew(['shop', '--no-install', '--local', plugins], { cwd: plugins, interactive: false, out: io.out, err: io.err });
|
|
321
|
+
|
|
322
|
+
expect(code).toBe(1);
|
|
323
|
+
expect(io.stderr()).toContain('is not a theme-core checkout');
|
|
324
|
+
expect(fs.readdirSync(plugins)).toEqual([]);
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
test('while the kit is unpublished a plain run links the checkout the kit sits in', async () => {
|
|
328
|
+
const plugins = makePluginsDir();
|
|
329
|
+
const io = capture();
|
|
330
|
+
const code = await runNew(['shop', '--no-install'], { cwd: plugins, interactive: false, out: io.out, err: io.err });
|
|
331
|
+
|
|
332
|
+
expect(code).toBe(0);
|
|
333
|
+
expect(JSON.parse(fs.readFileSync(path.join(plugins, 'shop/package.json'), 'utf8')).devDependencies['@panomc/plugin-kit']).toBe(
|
|
334
|
+
`file:${path.join(themeCore, 'packages/plugin-kit')}`,
|
|
335
|
+
);
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
test('outside a folder called plugins it says where the plugin has to live', async () => {
|
|
339
|
+
const plugins = makePluginsDir();
|
|
340
|
+
const elsewhere = path.join(path.dirname(plugins), 'elsewhere');
|
|
341
|
+
|
|
342
|
+
fs.mkdirSync(elsewhere);
|
|
343
|
+
|
|
344
|
+
const result = await scaffold(elsewhere, ['shop']);
|
|
345
|
+
|
|
346
|
+
expect(result.stdout).toContain('Pano finds a plugin\'s dev sources at <pano>/plugins/shop');
|
|
347
|
+
expect((await scaffold(plugins, ['shop'])).stdout).not.toContain('Pano finds');
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
test('without an id and without a terminal it asks for one', async () => {
|
|
351
|
+
const plugins = makePluginsDir();
|
|
352
|
+
const io = capture();
|
|
353
|
+
const code = await runNew(['--no-install'], { cwd: plugins, interactive: false, out: io.out, err: io.err });
|
|
354
|
+
|
|
355
|
+
expect(code).toBe(1);
|
|
356
|
+
expect(io.stderr()).toContain('a plugin id is required');
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
test('new --help prints the usage', async () => {
|
|
360
|
+
const io = capture();
|
|
361
|
+
|
|
362
|
+
expect(await runNew(['--help'], { out: io.out, err: io.err })).toBe(0);
|
|
363
|
+
expect(io.stdout()).toContain('Usage: pano-plugin new [<id>]');
|
|
364
|
+
});
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
describe('questions and install', () => {
|
|
368
|
+
/**
|
|
369
|
+
* @param {string[]} answers text answers in the order asked
|
|
370
|
+
* @param {boolean} [install]
|
|
371
|
+
*/
|
|
372
|
+
function fakePrompts(answers, install = true) {
|
|
373
|
+
/** @type {string[]} */
|
|
374
|
+
const asked = [];
|
|
375
|
+
const queue = [...answers];
|
|
376
|
+
|
|
377
|
+
return {
|
|
378
|
+
asked,
|
|
379
|
+
prompts: {
|
|
380
|
+
text: async ({ message, initial, validate }) => {
|
|
381
|
+
asked.push(message);
|
|
382
|
+
|
|
383
|
+
const answer = queue.shift() || initial || '';
|
|
384
|
+
const problem = validate?.(answer);
|
|
385
|
+
|
|
386
|
+
if (problem) throw new Error(problem);
|
|
387
|
+
|
|
388
|
+
return answer;
|
|
389
|
+
},
|
|
390
|
+
confirm: async ({ message }) => {
|
|
391
|
+
asked.push(message);
|
|
392
|
+
|
|
393
|
+
return install;
|
|
394
|
+
},
|
|
395
|
+
},
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
test('five questions: id, name, author, Kotlin package, install now', async () => {
|
|
400
|
+
const plugins = makePluginsDir();
|
|
401
|
+
const { asked, prompts } = fakePrompts(['quest-log', '', 'Me', '']);
|
|
402
|
+
const io = capture();
|
|
403
|
+
/** @type {string[]} */
|
|
404
|
+
const installed = [];
|
|
405
|
+
const code = await runNew(['--local', themeCore], {
|
|
406
|
+
cwd: plugins,
|
|
407
|
+
interactive: true,
|
|
408
|
+
prompts,
|
|
409
|
+
install: (dir) => (installed.push(dir), 0),
|
|
410
|
+
out: io.out,
|
|
411
|
+
err: io.err,
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
expect(io.stderr()).toBe('');
|
|
415
|
+
expect(code).toBe(0);
|
|
416
|
+
expect(asked).toHaveLength(5);
|
|
417
|
+
expect(asked.map((q) => q.split(' ')[0])).toEqual(['Plugin', 'Display', 'Author?', 'Kotlin', 'Install']);
|
|
418
|
+
expect(installed).toEqual([path.join(plugins, 'quest-log')]);
|
|
419
|
+
|
|
420
|
+
const properties = fs.readFileSync(path.join(plugins, 'quest-log/gradle.properties'), 'utf8');
|
|
421
|
+
|
|
422
|
+
expect(properties).toContain('pluginName=Quest Log\n');
|
|
423
|
+
expect(properties).toContain('pluginDeveloper=Me\n');
|
|
424
|
+
expect(properties).toContain('pluginClass=com.example.questlog.QuestLogPlugin\n');
|
|
425
|
+
// installed: the next step is just dev
|
|
426
|
+
expect(io.stdout()).toContain('1. cd quest-log && bun run dev');
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
test('answering no to "install now" runs nothing; an id given up front skips the id question', async () => {
|
|
430
|
+
const plugins = makePluginsDir();
|
|
431
|
+
const { asked, prompts } = fakePrompts(['quest-log', '', '', ''], false);
|
|
432
|
+
/** @type {string[]} */
|
|
433
|
+
const installed = [];
|
|
434
|
+
const io = capture();
|
|
435
|
+
|
|
436
|
+
await runNew(['--local', themeCore], { cwd: plugins, interactive: true, prompts, install: (dir) => (installed.push(dir), 0), out: io.out, err: io.err });
|
|
437
|
+
|
|
438
|
+
expect(asked).toHaveLength(5);
|
|
439
|
+
expect(installed).toEqual([]);
|
|
440
|
+
expect(io.stdout()).toContain('1. cd quest-log && bun install && bun run dev');
|
|
441
|
+
|
|
442
|
+
// with an id: no questions at all, installs by default
|
|
443
|
+
const second = capture();
|
|
444
|
+
|
|
445
|
+
await runNew(['other', '--local', themeCore], { cwd: plugins, interactive: true, prompts, install: (dir) => (installed.push(dir), 0), out: second.out, err: second.err });
|
|
446
|
+
|
|
447
|
+
expect(asked).toHaveLength(5);
|
|
448
|
+
expect(installed).toEqual([path.join(plugins, 'other')]);
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
test('a failed install keeps the scaffold and says how to finish', async () => {
|
|
452
|
+
const plugins = makePluginsDir();
|
|
453
|
+
const io = capture();
|
|
454
|
+
const code = await runNew(['shop', '--local', themeCore], { cwd: plugins, interactive: false, install: () => 1, out: io.out, err: io.err });
|
|
455
|
+
|
|
456
|
+
expect(code).toBe(0);
|
|
457
|
+
expect(fs.existsSync(path.join(plugins, 'shop/package.json'))).toBe(true);
|
|
458
|
+
expect(io.stdout()).toContain('bun install did not complete');
|
|
459
|
+
expect(io.stdout()).toContain('1. cd shop && bun install && bun run dev');
|
|
460
|
+
});
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
describe('bin/ui.js', () => {
|
|
464
|
+
test('exports what the engine copy exports and has no import of the engine', async () => {
|
|
465
|
+
const kit = await import('../../ui.js');
|
|
466
|
+
const engine = await import('../../../../theme-core/bin/ui.js');
|
|
467
|
+
const source = fs.readFileSync(path.join(import.meta.dir, '../../ui.js'), 'utf8');
|
|
468
|
+
|
|
469
|
+
expect(Object.keys(kit).sort()).toEqual(Object.keys(engine).sort());
|
|
470
|
+
expect(source).not.toMatch(/from ["']\.\.\/\.\.\/theme-core|@panomc\/theme-core/);
|
|
471
|
+
});
|
|
472
|
+
});
|