Hello Polarion¶
| Aspect | Details |
|---|---|
| Folder | examples/hello-polarion |
| Identifier | com.example.hello |
| View | form extension hello |
| Placement | <applicationView id="com.example.hello.hello" label="Hello Polarion" height="320px"/> in a form layout |
| Uses | nothing from Polarion: no SDK, no REST API |
Download com.example.hello · version 0.2.0
This is the application built step by step in Your first application. It contains only what every application needs: a manifest, a page and the packaging script. It does not use the SDK and does not talk to Polarion; the Application context example adds that.
Files¶
- hello-polarion/
- manifest.json
- package.json
- vite.config.ts
- tsconfig.json
- index.html
- src/
- main.tsx
- App.tsx
- styles.css
- scripts/
- package.mjs
manifest.json¶
{
"manifestVersion": "1.0",
"identifier": "com.example.hello",
"title": "Hello Polarion",
"description": "The smallest possible Polarion Application: one form extension that says hello.",
"publisherName": "Example Publisher",
"applicationVersion": "0.2.0",
"views": {
"formExtensions": [
{
"identifier": "hello",
"title": "Hello Polarion",
"rootDirectory": "hello",
"document": "index.html"
}
]
}
}
src/App.tsx¶
An ordinary React component. Nothing in it is specific to Polarion.
export default function App() {
return (
<main>
<h1>Hello, Polarion</h1>
<p>This panel is a Polarion Application.</p>
</main>
);
}
src/styles.css¶
body {
margin: 0;
padding: 12px;
font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
font-size: 14px;
color: #1f2933;
}
h1 {
font-size: 1.4rem;
margin: 0 0 8px;
}
src/main.tsx¶
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import App from "./App";
import "./styles.css";
createRoot(document.getElementById("root")!).render(
<StrictMode>
<App />
</StrictMode>,
);
scripts/package.mjs¶
This script turns the build into the ZIP you upload to Polarion: one top-level folder named after the identifier, with manifest.json and each view's content under its rootDirectory. It stages the files under package/<identifier>/ and creates <identifier>.zip in the project root. Expand it to see how the packaging works, or read Application package for the format.scripts/package.mjs
// Builds the upload-ready ZIP for Polarion.
//
// Layout inside the ZIP: one top-level folder named after the application
// identifier, with manifest.json, view content under each view's
// rootDirectory (which multiple views may share), and optional server-scripts/.
// Polarion rejects a ZIP that has manifest.json directly at its root
// ("Application's zip structure is incorrect").
//
// <identifier>/
// manifest.json
// <rootDirectory of each view>/ (index.html + assets)
// server-scripts/ (if present)
//
// Single-view projects build into dist/. Multi-view projects build one Vite
// mode per view into dist/<rootDirectory>/ (see "Set up the project" in the
// guide); this script copies whichever exists.
//
// Run with `npm run package` (which builds first).
import { cpSync, existsSync, mkdirSync, readFileSync, rmSync } from "node:fs";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import AdmZip from "adm-zip";
const projectRootPath = fileURLToPath(new URL("..", import.meta.url));
const distributionPath = join(projectRootPath, "dist");
function stageViews(appStagePath, manifest) {
const views = Object.values(manifest.views ?? {}).flat();
if (views.length === 0) {
throw new Error("manifest.json declares no views.");
}
for (const view of views) {
const viewDist = join(distributionPath, view.rootDirectory);
const source = existsSync(viewDist) ? viewDist : distributionPath;
const documentPath = join(source, view.document);
if (!existsSync(documentPath)) {
throw new Error(`Build output for view "${view.identifier}" not found: ${documentPath}`);
}
cpSync(source, join(appStagePath, view.rootDirectory), { recursive: true });
}
}
function stageServerScripts(appStagePath) {
const serverScripts = join(projectRootPath, "server-scripts");
if (existsSync(serverScripts)) {
cpSync(serverScripts, join(appStagePath, "server-scripts"), { recursive: true });
}
}
function writePackageZip(stageRoot, zipPath) {
const zip = new AdmZip();
zip.addLocalFolder(stageRoot);
zip.writeZip(zipPath);
}
function packageApplication() {
const manifest = JSON.parse(readFileSync(join(projectRootPath, "manifest.json"), "utf8"));
const stageRootPath = join(projectRootPath, "package");
const zipPath = join(projectRootPath, `${manifest.identifier}.zip`);
rmSync(stageRootPath, { recursive: true, force: true });
try {
const appStagePath = join(stageRootPath, manifest.identifier);
mkdirSync(appStagePath, { recursive: true });
cpSync(join(projectRootPath, "manifest.json"), join(appStagePath, "manifest.json"));
stageViews(appStagePath, manifest);
stageServerScripts(appStagePath);
writePackageZip(stageRootPath, zipPath);
} finally {
rmSync(stageRootPath, { recursive: true, force: true });
}
console.log(`Packaged ${manifest.identifier} ${manifest.applicationVersion} -> ${zipPath}`);
}
packageApplication();
Build and deploy¶
cd examples/hello-polarion
npm install
npm run package # → com.example.hello.zip
Upload the ZIP in Global Administration → Applications, then add the applicationView element to a form layout as described in Form extensions.
Things to try¶
- Change
heightin the layout and watch the panel resize. - Remove the
labelattribute: the heading falls back to Polarion Application. - Open
https://<host>/polarion/apps/com.example.hello/views/hellodirectly. The page renders there too, because it does not depend on Polarion; a view that callsfetchContext()does not (see Application context).
