Skip to content

Commit 344468f

Browse files
committed
Save choices to config for better awareness for auto upgrade
1 parent 587fcaf commit 344468f

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

scripts/rebrand.config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"owner": "react18-tools",
33
"repo": "turborepo-template",
44
"packageName": "react18-loaders",
5-
"title": "React 18 Loaders"
5+
"title": "React18 Loaders"
66
}

scripts/rebrand.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ const { execSync } = require("child_process");
66

77
const config = require("./rebrand.config.json");
88

9+
const isFirstRebrand = config.repo === "turborepo-template" && config.owner === "react18-tools";
10+
911
const [owner, repo] = execSync(
1012
'git remote get-url --push origin | sed "s/https:\\/\\/github.com\\///" | sed "s/https:\\/\\/[^@]*@github.com\\///" | sed "s/.git//"',
1113
)
1214
.toString()
1315
.trim()
1416
.split("/");
1517

16-
const packageName = repo;
18+
const packageName = isFirstRebrand ? repo : config.packageName || repo;
1719

1820
/** avoiding IIFE as formettter keeps misformettting IIFEs */
1921
const rebrandFn = async () => {
@@ -37,6 +39,10 @@ const rebrandFn = async () => {
3739
.forEach(cmd => execSync(cmd.trim()));
3840
}
3941

42+
const defaultInitialTitle = packageName
43+
.split("-")
44+
.map(w => w[0].toUpperCase() + w.slice(1))
45+
.join(" ");
4046
const { installExt, ...answers } = await prompt([
4147
{
4248
type: "input",
@@ -61,10 +67,7 @@ const rebrandFn = async () => {
6167
type: "input",
6268
name: "title",
6369
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,
6871
},
6972
{
7073
type: "confirm",
@@ -80,10 +83,11 @@ const rebrandFn = async () => {
8083
execSync("code --install-extension esbenp.prettier-vscode", { stdio: "inherit" });
8184
}
8285

86+
const newConfig = Object.assign({}, answers);
8387
console.log("\x1b[32m", "Creating rebrand.config.json...");
8488
fs.writeFileSync(
8589
path.resolve(process.cwd(), "scripts", "rebrand.config.json"),
86-
JSON.stringify(answers, null, 2),
90+
JSON.stringify(newConfig, null, 2),
8791
);
8892

8993
console.log("\x1b[32m", "rebranding...");
@@ -113,6 +117,8 @@ const rebrandFn = async () => {
113117
],
114118
});
115119

120+
Object.assign(newConfig, { removedPackages: pkgs });
121+
116122
pkgs.forEach(pkg => execSync(`rm -rf ${pkg}`));
117123

118124
if (pkgs.length) {
@@ -157,6 +163,8 @@ const rebrandFn = async () => {
157163
],
158164
});
159165

166+
Object.assign(newConfig, { removedFeatures: feats });
167+
160168
const rootPackageJSON = require("../package.json");
161169

162170
if (feats.includes("Rebrander")) {
@@ -236,6 +244,12 @@ const rebrandFn = async () => {
236244
console.error(e);
237245
}
238246

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+
239253
execSync(
240254
'git add . && git commit -m "Cleaned up features 💖 <a href="https://mayank-chaudhari.vercel.app" target="_blank">Mayank Kumar Chaudhari</a> [skip ci]"',
241255
);

0 commit comments

Comments
 (0)