Skip to content

Commit 48f9d91

Browse files
ibolton336github-actions[bot]
authored andcommitted
✨ Add MTA branding scripts for downstream repo
1 parent d4df3b6 commit 48f9d91

File tree

4 files changed

+301
-0
lines changed

4 files changed

+301
-0
lines changed
Lines changed: 99 additions & 0 deletions
Loading
8.52 KB
Loading

scripts/postbuild.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env node
2+
3+
import fs from "fs";
4+
import path from "path";
5+
import { fileURLToPath } from "url";
6+
7+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
8+
9+
console.log("🔄 Running MTA postbuild script...");
10+
11+
// Optional: Copy MTA-specific assets
12+
const assetsDir = path.join(__dirname, "../assets/mta");
13+
const resourcesDir = path.join(__dirname, "../vscode/resources");
14+
15+
if (fs.existsSync(assetsDir)) {
16+
// Copy MTA icon if it exists
17+
const mtaIcon = path.join(assetsDir, "mta-icon-color.png");
18+
const targetIcon = path.join(resourcesDir, "mta-icon-color.png");
19+
20+
if (fs.existsSync(mtaIcon)) {
21+
fs.copyFileSync(mtaIcon, targetIcon);
22+
console.log("✅ Copied MTA icon assets");
23+
}
24+
}
25+
26+
// Optional: Generate MTA-specific documentation
27+
const docsDir = path.join(__dirname, "../docs/mta");
28+
if (fs.existsSync(docsDir)) {
29+
console.log("✅ MTA documentation ready");
30+
}
31+
32+
// Optional: Package validation
33+
const packagePath = path.join(__dirname, "../vscode/package.json");
34+
const packageJson = JSON.parse(fs.readFileSync(packagePath, "utf8"));
35+
36+
if (packageJson.publisher === "mta" && packageJson.name === "mta") {
37+
console.log("✅ MTA package configuration validated");
38+
} else {
39+
console.error("❌ Package configuration validation failed");
40+
process.exit(1);
41+
}
42+
43+
console.log("✅ MTA postbuild complete");

scripts/prebuild.js

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#!/usr/bin/env node
2+
3+
import fs from "fs";
4+
import path from "path";
5+
import { fileURLToPath } from "url";
6+
7+
const __filename = fileURLToPath(import.meta.url);
8+
const __dirname = path.dirname(__filename);
9+
10+
// Read package.json to determine which brand we're building
11+
const packagePath = path.join(__dirname, "../vscode/package.json");
12+
const packageJson = JSON.parse(fs.readFileSync(packagePath, "utf8"));
13+
14+
// Use the package name to determine branding
15+
const extensionName = packageJson.name;
16+
const displayName = extensionName.toUpperCase();
17+
18+
console.log(`🔄 Running prebuild for ${extensionName}...`);
19+
console.log(`📦 Transforming package.json...`);
20+
21+
// Define the list of known brands
22+
const knownBrands = ["konveyor", "mta"];
23+
24+
// Build regex patterns from the brand list
25+
const brandPattern = knownBrands.join("|");
26+
const brandRegex = new RegExp(brandPattern, "gi");
27+
const brandPrefixRegex = new RegExp(`\\b(${brandPattern})\\.`, "gi");
28+
const brandWordRegex = new RegExp(`\\b(${brandPattern})(?=\\s|$)`, "gi");
29+
30+
// Apply branding transformations
31+
Object.assign(packageJson, {
32+
displayName: `${displayName} Extension for VSCode`,
33+
description:
34+
extensionName === "mta"
35+
? "Migration Toolkit for Applications - Enterprise migration and modernization tool"
36+
: "Open-source migration and modernization tool",
37+
publisher: extensionName,
38+
author: extensionName === "mta" ? "Red Hat" : "Konveyor",
39+
icon: packageJson.icon, // Keep existing icon path - assets will be copied later
40+
});
41+
42+
// Transform configuration properties
43+
if (packageJson.contributes?.configuration?.properties) {
44+
const props = packageJson.contributes.configuration.properties;
45+
const newProps = {};
46+
47+
Object.keys(props).forEach((key) => {
48+
const newKey = key.replace(/^[^.]+\./, `${extensionName}.`);
49+
newProps[newKey] = props[key];
50+
});
51+
52+
packageJson.contributes.configuration.properties = newProps;
53+
packageJson.contributes.configuration.title = displayName;
54+
}
55+
56+
// Transform commands
57+
if (packageJson.contributes?.commands) {
58+
// Categories that should not be transformed by branding
59+
const preservedCategories = ["diffEditor"];
60+
61+
packageJson.contributes.commands = packageJson.contributes.commands.map((cmd) => ({
62+
...cmd,
63+
command: cmd.command.replace(/^[^.]+\./, `${extensionName}.`),
64+
// Only transform category if it's not in the preserved list
65+
category: preservedCategories.includes(cmd.category) ? cmd.category : displayName,
66+
title: cmd.title?.replace(brandRegex, displayName) || cmd.title,
67+
}));
68+
}
69+
70+
// Transform views and containers
71+
if (packageJson.contributes?.viewsContainers?.activitybar) {
72+
packageJson.contributes.viewsContainers.activitybar =
73+
packageJson.contributes.viewsContainers.activitybar.map((container) => ({
74+
...container,
75+
id: extensionName,
76+
title: displayName,
77+
icon: container.icon, // Keep existing icon path - assets will be copied later
78+
}));
79+
}
80+
81+
if (packageJson.contributes?.views) {
82+
const newViews = {};
83+
Object.keys(packageJson.contributes.views).forEach((viewKey) => {
84+
newViews[extensionName] = packageJson.contributes.views[viewKey].map((view) => ({
85+
...view,
86+
id: view.id.replace(/^[^.]+\./, `${extensionName}.`),
87+
name: view.name.replace(brandRegex, displayName),
88+
}));
89+
});
90+
packageJson.contributes.views = newViews;
91+
}
92+
93+
// Transform menus
94+
if (packageJson.contributes?.menus) {
95+
const transformMenuCommands = (menuItems) => {
96+
return menuItems.map((item) => ({
97+
...item,
98+
command: item.command?.replace(/^[^.]+\./, `${extensionName}.`),
99+
when: item.when
100+
?.replace(brandPrefixRegex, `${extensionName}.`)
101+
.replace(brandWordRegex, extensionName),
102+
submenu: item.submenu?.replace(/^[^.]+\./, `${extensionName}.`),
103+
}));
104+
};
105+
106+
const newMenus = {};
107+
Object.keys(packageJson.contributes.menus).forEach((menuKey) => {
108+
const newMenuKey = new RegExp(`^(${brandPattern})`, "i").test(menuKey)
109+
? menuKey.replace(/^[^.]+/, extensionName)
110+
: menuKey;
111+
newMenus[newMenuKey] = transformMenuCommands(packageJson.contributes.menus[menuKey]);
112+
});
113+
packageJson.contributes.menus = newMenus;
114+
}
115+
116+
// Transform submenus
117+
if (packageJson.contributes?.submenus) {
118+
packageJson.contributes.submenus = packageJson.contributes.submenus.map((submenu) => ({
119+
...submenu,
120+
id: submenu.id.replace(/^[^.]+/, extensionName),
121+
label: `${displayName} Actions`,
122+
}));
123+
}
124+
125+
// Write the transformed package.json
126+
fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2));
127+
console.log(`✅ ${displayName} branding transformations complete`);
128+
129+
// Copy assets - whatever exists in the directories gets used
130+
console.log(`🖼️ Copying assets...`);
131+
132+
// 1. Copy VSCode sidebar icon (whatever icon exists in sidebar-icons/)
133+
const iconSource = path.join(__dirname, "..", "assets/branding/sidebar-icons/icon.png");
134+
const iconTarget = path.join(__dirname, "..", "vscode/resources/icon.png");
135+
136+
if (fs.existsSync(iconSource)) {
137+
fs.copyFileSync(iconSource, iconTarget);
138+
console.log(` ✅ VSCode sidebar icon copied`);
139+
} else {
140+
console.warn(` ⚠️ No sidebar icon found at: assets/branding/sidebar-icons/icon.png`);
141+
}
142+
143+
// 2. Copy webview avatar (whatever avatar exists in avatar-icons/)
144+
const avatarSource = path.join(__dirname, "..", "assets/branding/avatar-icons/avatar.svg");
145+
const avatarTarget = path.join(__dirname, "..", "webview-ui/public/avatarIcons/avatar.svg");
146+
147+
if (fs.existsSync(avatarSource)) {
148+
// Ensure target directory exists
149+
const avatarDir = path.dirname(avatarTarget);
150+
if (!fs.existsSync(avatarDir)) {
151+
fs.mkdirSync(avatarDir, { recursive: true });
152+
}
153+
fs.copyFileSync(avatarSource, avatarTarget);
154+
console.log(` ✅ Webview avatar copied`);
155+
} else {
156+
console.warn(` ⚠️ No avatar found at: assets/branding/avatar-icons/avatar.svg`);
157+
}
158+
159+
console.log(`✅ Prebuild complete for ${extensionName}`);

0 commit comments

Comments
 (0)