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
77const replacements = [
88 {
9- files : [ ' ci/build/nfpm.yaml' ] ,
9+ files : [ " ci/build/nfpm.yaml" ] ,
1010 from : [ / v e n d o r : " C o d e r " / g, / h o m e p a g e : " h t t p s : \/ \/ g i t h u b .c o m \/ c o d e r \/ c o d e - s e r v e r " / g, / m a i n t a i n e r : " .* " / 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 : [ / " h o m e p a g e " : " h t t p s : \/ \/ g i t h u b .c o m \/ c o d e r \/ c o d e - s e r v e r " / g, / " u r l " : " h t t p s : \/ \/ g i t h u b .c o m \/ c o d e r \/ c o d e - s e r v e r \/ i s s u e s " / g, / " r e p o s i t o r y " : " h t t p s : \/ \/ g i t h u b .c o m \/ c o d e r \/ c o d e - s e r v e r " / g] ,
16- to : [ `"homepage": "https://${ branding . companyDomain } "` , `"url": "https://${ branding . companyDomain } /issues"` , `"repository": "https://${ branding . companyDomain } "` ] ,
18+ files : [ "package.json" ] ,
19+ from : [
20+ / " h o m e p a g e " : " h t t p s : \/ \/ g i t h u b .c o m \/ c o d e r \/ c o d e - s e r v e r " / g,
21+ / " u r l " : " h t t p s : \/ \/ g i t h u b .c o m \/ c o d e r \/ c o d e - s e r v e r \/ i s s u e s " / g,
22+ / " r e p o s i t o r y " : " h t t p s : \/ \/ g i t h u b .c o m \/ c o d e r \/ c o d e - s e r v e r " / 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 : [ / < t i t l e > c o d e - s e r v e r < \/ t i t l e > / g, / < m e t a i d = " c o d e r - o p t i o n s " / g] ,
2133 to : [ `<title>${ branding . productName } </title>` , `<meta id="product-options"` ] ,
2234 } ,
2335 {
24- files : [ 'install.sh' ] ,
25- from : [ / h t t p s : \/ \/ c o d e r .c o m \/ d o c s \/ c o d e - s e r v e r \/ l a t e s t \/ i n s t a l l / g, / h t t p s : \/ \/ g i t h u b .c o m \/ c o d e r \/ c o d e - s e r v e r / g, / e c h o _ c o d e r _ p o s t i n s t a l l / g] ,
26- to : [ `https://${ branding . companyDomain } /docs` , `https://github.com/${ branding . companyName } /${ branding . productName } ` , 'echo_postinstall' ] ,
36+ files : [ "install.sh" ] ,
37+ from : [
38+ / h t t p s : \/ \/ c o d e r .c o m \/ d o c s \/ c o d e - s e r v e r \/ l a t e s t \/ i n s t a l l / g,
39+ / h t t p s : \/ \/ g i t h u b .c o m \/ c o d e r \/ c o d e - s e r v e r / g,
40+ / e c h o _ c o d e r _ p o s t i n s t a l l / 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 : [ / n e w U p d a t e P r o v i d e r \( " h t t p s : \/ \/ a p i .g i t h u b .c o m \/ r e p o s \/ c o d e r \/ c o d e - s e r v e r \/ r e l e a s e s \/ l a t e s t " , s e t t i n g s \) / 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
3557const 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 - z 0 - 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
43112function 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