@@ -6,14 +6,16 @@ const { execSync } = require("child_process");
6
6
7
7
const config = require ( "./rebrand.config.json" ) ;
8
8
9
+ const isFirstRebrand = config . repo === "turborepo-template" && config . owner === "react18-tools" ;
10
+
9
11
const [ owner , repo ] = execSync (
10
12
'git remote get-url --push origin | sed "s/https:\\/\\/github.com\\///" | sed "s/https:\\/\\/[^@]*@github.com\\///" | sed "s/.git//"' ,
11
13
)
12
14
. toString ( )
13
15
. trim ( )
14
16
. split ( "/" ) ;
15
17
16
- const packageName = repo ;
18
+ const packageName = isFirstRebrand ? repo : config . packageName || repo ;
17
19
18
20
/** avoiding IIFE as formettter keeps misformettting IIFEs */
19
21
const rebrandFn = async ( ) => {
@@ -37,6 +39,10 @@ const rebrandFn = async () => {
37
39
. forEach ( cmd => execSync ( cmd . trim ( ) ) ) ;
38
40
}
39
41
42
+ const defaultInitialTitle = packageName
43
+ . split ( "-" )
44
+ . map ( w => w [ 0 ] . toUpperCase ( ) + w . slice ( 1 ) )
45
+ . join ( " " ) ;
40
46
const { installExt, ...answers } = await prompt ( [
41
47
{
42
48
type : "input" ,
@@ -61,10 +67,7 @@ const rebrandFn = async () => {
61
67
type : "input" ,
62
68
name : "title" ,
63
69
message : "What is the title of your project?" ,
64
- initial : packageName
65
- . split ( "-" )
66
- . map ( w => w [ 0 ] . toUpperCase ( ) + w . slice ( 1 ) )
67
- . join ( " " ) ,
70
+ initial : isFirstRebrand ? defaultInitialTitle : config . title || defaultInitialTitle ,
68
71
} ,
69
72
{
70
73
type : "confirm" ,
@@ -80,10 +83,11 @@ const rebrandFn = async () => {
80
83
execSync ( "code --install-extension esbenp.prettier-vscode" , { stdio : "inherit" } ) ;
81
84
}
82
85
86
+ const newConfig = Object . assign ( { } , answers ) ;
83
87
console . log ( "\x1b[32m" , "Creating rebrand.config.json..." ) ;
84
88
fs . writeFileSync (
85
89
path . resolve ( process . cwd ( ) , "scripts" , "rebrand.config.json" ) ,
86
- JSON . stringify ( answers , null , 2 ) ,
90
+ JSON . stringify ( newConfig , null , 2 ) ,
87
91
) ;
88
92
89
93
console . log ( "\x1b[32m" , "rebranding..." ) ;
@@ -113,6 +117,8 @@ const rebrandFn = async () => {
113
117
] ,
114
118
} ) ;
115
119
120
+ Object . assign ( newConfig , { removedPackages : pkgs } ) ;
121
+
116
122
pkgs . forEach ( pkg => execSync ( `rm -rf ${ pkg } ` ) ) ;
117
123
118
124
if ( pkgs . length ) {
@@ -157,6 +163,8 @@ const rebrandFn = async () => {
157
163
] ,
158
164
} ) ;
159
165
166
+ Object . assign ( newConfig , { removedFeatures : feats } ) ;
167
+
160
168
const rootPackageJSON = require ( "../package.json" ) ;
161
169
162
170
if ( feats . includes ( "Rebrander" ) ) {
@@ -236,6 +244,12 @@ const rebrandFn = async () => {
236
244
console . error ( e ) ;
237
245
}
238
246
247
+ console . log ( "\x1b[32m" , "Updating rebrand.config.json..." ) ;
248
+ fs . writeFileSync (
249
+ path . resolve ( process . cwd ( ) , "scripts" , "rebrand.config.json" ) ,
250
+ JSON . stringify ( newConfig , null , 2 ) ,
251
+ ) ;
252
+
239
253
execSync (
240
254
'git add . && git commit -m "Cleaned up features 💖 <a href="https://mayank-chaudhari.vercel.app" target="_blank">Mayank Kumar Chaudhari</a> [skip ci]"' ,
241
255
) ;
0 commit comments