Files
openidea/scripts/theme/import-intellij-theme.ts
T
l0ng-ai 1d4c0e1cd4 docs: remove docs/ and keep plugin docs in plugins/ (#2503)
* docs: remove unreferenced user guides

Drop docs/command-line.md, databases.md, java.md, unity-external-editor.md
and docs/media/debug.jpg. Nothing in the repository links to them.
Plugin, theme and README assets under docs/ stay.

* docs: keep only plugin docs under docs/

Remove docs/themes.md and docs/data-directories.md. Move the upstream
Atom One source revisions into THIRD_PARTY_LICENSES.md, drop the links
to the removed page, and move the README's WeChat QR code to
.github/assets/.

* docs: move plugin docs next to plugins/README.md

docs/plugins/themes.md and indexing.md move to plugins/. Update the
theme doc generator, its test, the plugin template, AGENTS.md and every
link to the new paths.
2026-11-10 16:16:32 +08:00

64 lines
2.5 KiB
TypeScript
Raw 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 plugins/themes.md to fill them in.`,
);