Skip to content

Commit e849bd0

Browse files
Merge pull request #3 from qBraid/kh_branding-changes
Kh branding changes
2 parents 5b33f07 + b149106 commit e849bd0

7 files changed

Lines changed: 107 additions & 36 deletions

File tree

branding.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
"faviconIco": "branding/favicon.ico",
88
"pwaIcon192": "branding/pwa-icon-192.png",
99
"pwaIcon512": "branding/pwa-icon-512.png"
10-
}
10+
}

branding/favicon.ico

-461 KB
Binary file not shown.

branding/favicon.svg

Lines changed: 1 addition & 0 deletions
Loading

branding/logo.svg

Lines changed: 1 addition & 2 deletions
Loading

branding/pwa-icon-192.png

-17.9 KB
Loading

branding/pwa-icon-512.png

-75.2 KB
Loading

ci/dev/apply-branding.js

Lines changed: 104 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,137 @@
1-
const fs = require('fs');
2-
const path = require('path');
1+
const fs = require("fs")
2+
const path = require("path")
33

4-
const branding = require('../../branding.json');
5-
const root = path.resolve(__dirname, '../..');
4+
const branding = require("../../branding.json")
5+
const root = path.resolve(__dirname, "../..")
66

77
const replacements = [
88
{
9-
files: ['ci/build/nfpm.yaml'],
9+
files: ["ci/build/nfpm.yaml"],
1010
from: [/vendor: "Coder"/g, /homepage: "https:\/\/github.com\/coder\/code-server"/g, /maintainer: ".*"/g],
11-
to: [`vendor: "${branding.companyName}"`, `homepage: "https://${branding.companyDomain}"`, `maintainer: "community@${branding.companyDomain}"`],
11+
to: [
12+
`vendor: "${branding.companyName}"`,
13+
`homepage: "https://${branding.companyDomain}"`,
14+
`maintainer: "community@${branding.companyDomain}"`,
15+
],
1216
},
1317
{
14-
files: ['package.json'],
15-
from: [/"homepage": "https:\/\/github.com\/coder\/code-server"/g, /"url": "https:\/\/github.com\/coder\/code-server\/issues"/g, /"repository": "https:\/\/github.com\/coder\/code-server"/g],
16-
to: [`"homepage": "https://${branding.companyDomain}"`, `"url": "https://${branding.companyDomain}/issues"`, `"repository": "https://${branding.companyDomain}"`],
18+
files: ["package.json"],
19+
from: [
20+
/"homepage": "https:\/\/github.com\/coder\/code-server"/g,
21+
/"url": "https:\/\/github.com\/coder\/code-server\/issues"/g,
22+
/"repository": "https:\/\/github.com\/coder\/code-server"/g,
23+
],
24+
to: [
25+
`"homepage": "https://${branding.companyDomain}"`,
26+
`"url": "https://${branding.companyDomain}/issues"`,
27+
`"repository": "https://${branding.companyDomain}"`,
28+
],
1729
},
1830
{
19-
files: ['src/browser/pages/login.html', 'src/browser/pages/error.html'],
31+
files: ["src/browser/pages/login.html", "src/browser/pages/error.html"],
2032
from: [/<title>code-server<\/title>/g, /<meta id="coder-options"/g],
2133
to: [`<title>${branding.productName}</title>`, `<meta id="product-options"`],
2234
},
2335
{
24-
files: ['install.sh'],
25-
from: [/https:\/\/coder.com\/docs\/code-server\/latest\/install/g, /https:\/\/github.com\/coder\/code-server/g, /echo_coder_postinstall/g],
26-
to: [`https://${branding.companyDomain}/docs`, `https://github.com/${branding.companyName}/${branding.productName}`, 'echo_postinstall'],
36+
files: ["install.sh"],
37+
from: [
38+
/https:\/\/coder.com\/docs\/code-server\/latest\/install/g,
39+
/https:\/\/github.com\/coder\/code-server/g,
40+
/echo_coder_postinstall/g,
41+
],
42+
to: [
43+
`https://${branding.companyDomain}/docs`,
44+
`https://github.com/${branding.companyName}/${branding.productName}`,
45+
"echo_postinstall",
46+
],
2747
},
2848
{
29-
files: ['src/node/routes/index.ts'],
49+
files: ["src/node/routes/index.ts"],
3050
from: [/new UpdateProvider\("https:\/\/api.github.com\/repos\/coder\/code-server\/releases\/latest", settings\)/g],
31-
to: [`new UpdateProvider("https://api.github.com/repos/${branding.companyName}/${branding.productName}/releases/latest", settings)`],
51+
to: [
52+
`new UpdateProvider("https://api.github.com/repos/${branding.companyName}/${branding.productName}/releases/latest", settings)`,
53+
],
3254
},
33-
];
55+
]
3456

3557
const assetReplacements = [
36-
{ from: branding.faviconIco, to: 'src/browser/media/favicon.ico' },
37-
{ from: branding.faviconSvg, to: 'src/browser/media/favicon.svg' },
38-
{ from: branding.logoSvg, to: 'src/browser/media/logo.svg' },
39-
{ from: branding.pwaIcon192, to: 'src/browser/media/pwa-icon-192.png' },
40-
{ from: branding.pwaIcon512, to: 'src/browser/media/pwa-icon-512.png' },
41-
];
58+
{ from: branding.faviconIco, to: "src/browser/media/favicon.ico" },
59+
{ from: branding.faviconSvg, to: "src/browser/media/favicon.svg" },
60+
{ from: branding.logoSvg, to: "src/browser/media/logo.svg" },
61+
{ from: branding.pwaIcon192, to: "src/browser/media/pwa-icon-192.png" },
62+
{ from: branding.pwaIcon512, to: "src/browser/media/pwa-icon-512.png" },
63+
]
64+
65+
// Directories that might contain prebuilt release artifacts we need to patch in-place.
66+
const releaseDirs = [path.join(root, "release"), path.join(root, "release-standalone")]
67+
68+
// Helper to safely patch a JSON file by reading, merging, and writing.
69+
function patchJson(file, mutateFn) {
70+
if (!fs.existsSync(file)) return
71+
const json = JSON.parse(fs.readFileSync(file, "utf8"))
72+
const updated = mutateFn(json) || json
73+
fs.writeFileSync(file, JSON.stringify(updated, null, 2))
74+
}
75+
76+
function applyBrandingToReleaseArtifacts() {
77+
for (const dir of releaseDirs) {
78+
if (!fs.existsSync(dir)) continue
79+
80+
// Copy assets into release dir structure if present.
81+
const relAssetTargets = [
82+
{ from: branding.faviconIco, to: "src/browser/media/favicon.ico" },
83+
{ from: branding.faviconSvg, to: "src/browser/media/favicon.svg" },
84+
{ from: branding.logoSvg, to: "src/browser/media/logo.svg" },
85+
{ from: branding.pwaIcon192, to: "src/browser/media/pwa-icon-192.png" },
86+
{ from: branding.pwaIcon512, to: "src/browser/media/pwa-icon-512.png" },
87+
]
88+
89+
for (const asset of relAssetTargets) {
90+
const fromPath = path.join(root, asset.from)
91+
const toPath = path.join(dir, asset.to)
92+
if (fs.existsSync(fromPath) && fs.existsSync(path.dirname(toPath))) {
93+
fs.copyFileSync(fromPath, toPath)
94+
}
95+
}
96+
97+
// Patch VS Code product.json if it exists.
98+
const productJsonPath = path.join(dir, "lib", "vscode", "product.json")
99+
patchJson(productJsonPath, (json) => {
100+
json.shortName = branding.productName
101+
json.longName = branding.productName
102+
json.applicationName = branding.productName.toLowerCase().replace(/[^a-z0-9-]/g, "-")
103+
json.dataFolderName = `${branding.productName}-data`
104+
json.urlProtocol = branding.productName.toLowerCase()
105+
json.reportIssueUrl = `https://${branding.companyDomain}/support`
106+
json.documentationUrl = `https://${branding.companyDomain}`
107+
json.vendor = branding.companyName
108+
})
109+
}
110+
}
42111

43112
function applyReplacements() {
44-
console.log('Applying branding...');
113+
console.log("Applying branding…")
45114
for (const { files, from, to } of replacements) {
46115
for (const file of files) {
47-
const filePath = path.join(root, file);
48-
let content = fs.readFileSync(filePath, 'utf8');
49-
for (let i = 0; i < from.length; i++) {
50-
content = content.replace(from[i], to[i]);
116+
const filePath = path.join(root, file)
117+
let content = fs.readFileSync(filePath, "utf8")
118+
for (let i = 0; i < from.length; i += 1) {
119+
content = content.replace(from[i], to[i])
51120
}
52-
fs.writeFileSync(filePath, content, 'utf8');
121+
fs.writeFileSync(filePath, content, "utf8")
53122
}
54123
}
55124

56125
for (const asset of assetReplacements) {
57-
const fromPath = path.join(root, asset.from);
58-
const toPath = path.join(root, asset.to);
126+
const fromPath = path.join(root, asset.from)
127+
const toPath = path.join(root, asset.to)
59128
if (fs.existsSync(fromPath)) {
60-
fs.copyFileSync(fromPath, toPath);
129+
fs.copyFileSync(fromPath, toPath)
61130
}
62131
}
63-
console.log('Branding applied successfully.');
132+
133+
applyBrandingToReleaseArtifacts()
134+
console.log("Branding applied successfully.")
64135
}
65136

66-
applyReplacements();
137+
applyReplacements()

0 commit comments

Comments
 (0)