Files
openidea/scripts/theme/import-intellij-theme.ts
Lee Dong Geon 6dec1252db feat(plugins): import IntelliJ theme plugins (#1184)
Settings › Plugins (gear menu) gets Import Theme from IntelliJ IDE… (theme plugins of the JetBrains IDEs on this machine, the one each IDE uses first) and Import IntelliJ Theme from File… (a Marketplace .jar / .zip or a .theme.json). The host reads the plugin with size limits; the UI converts it with the IntelliJ mapping (moved from scripts/theme to src/features/plugins/intellijTheme.ts, still used by pnpm theme:import-intellij) into one OpenIDEA theme plugin (engines.openidea ^1.0) with all of its themes, installed through the usual install page, and applies the chosen theme.

Theme pickers separate each plugin's themes, and Quick Switch Scheme › Theme previews the theme under the pointer or keyboard after 500 ms and restores the selected one when closed without a choice.

Co-authored-by: ldg030201 <100822592+ldg030201@users.noreply.github.com>
2026-11-04 15:28:00 +08:00

64 lines
2.5 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Converts an IntelliJ theme into an OpenIDEA theme plugin package.
*
* pnpm theme:import-intellij <file.theme.json> [file.icls] --out <dir> [--id <id>] [--author <name>]
*
* Writes <dir>/plugin.toml and <dir>/themes/<id>.theme.json (+ .scheme.json),
* ready for Settings › Plugins › Install Plugin from Disk…. Only port themes
* whose licence allows it, and credit the original author.
*/
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { basename, join } from "node:path";
import { parseArgs } from "node:util";
import { convertIntellijTheme, pluginManifest } from "../../src/features/plugins/intellijTheme.ts";
import { stripJsonComments } from "./tokens.ts";
const { values, positionals } = parseArgs({
allowPositionals: true,
options: { out: { type: "string" }, id: { type: "string" }, author: { type: "string" } },
});
const [themePath, iclsPath] = positionals;
if (!themePath || !values.out) {
console.error(
"usage: pnpm theme:import-intellij <file.theme.json> [file.icls] --out <dir> [--id <id>] [--author <name>]",
);
process.exit(2);
}
const converted = convertIntellijTheme(
stripJsonComments(readFileSync(themePath, "utf8")),
iclsPath ? readFileSync(iclsPath, "utf8") : undefined,
values.id,
);
const { theme, scheme } = converted;
const source = [basename(themePath), iclsPath && basename(iclsPath)].filter(Boolean).join(" + ");
const header = (what: string) => `// ${theme.name}: ${what}, converted from ${source}.\n`;
mkdirSync(join(values.out, "themes"), { recursive: true });
const info = {
id: `theme-${theme.id}`,
name: `${theme.name} Theme`,
version: "1.0.0",
description: `${theme.name}, converted from an IntelliJ theme.`,
authors: [values.author ?? "Unknown"],
};
writeFileSync(
join(values.out, "plugin.toml"),
pluginManifest(info, [converted], `Converted from ${source} by scripts/theme/import-intellij-theme.ts.`),
);
writeFileSync(
join(values.out, "themes", `${theme.id}.theme.json`),
header("UI theme") + JSON.stringify(theme, null, 2) + "\n",
);
if (scheme) {
writeFileSync(
join(values.out, "themes", `${theme.id}.scheme.json`),
header("editor colour scheme") + JSON.stringify(scheme, null, 2) + "\n",
);
}
console.log(
`${theme.name} (${theme.kind}): ${Object.keys(theme.tokens).length} UI tokens` +
(scheme ? `, ${Object.keys(scheme.tokens).length} editor tokens` : "") +
` → ${values.out}\nUnmapped tokens keep the built-in ${theme.kind} values; see docs/plugins/themes.md to fill them in.`,
);