Skip to content

Commit ab0ac74

Browse files
Simplify README update logic by reordering content comparison and removing redundant conditions.
1 parent ee21af3 commit ab0ac74

2 files changed

Lines changed: 18 additions & 20 deletions

File tree

dist/index.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34408,19 +34408,17 @@ const previewUpdater = async () => {
3440834408
// Read file
3440934409
const content = (0, filesystem_1.readFile)(config, config.path.readme);
3441034410
const preview = (0, preview_1.setPreview)(content, config);
34411-
if (content !== preview) {
34412-
// Checkout branch
34413-
const branchExists = await repo.branchExists();
34414-
(0, core_1.info)(`Checkout ${branchExists ? 'existing' : 'new'} branch named "${repo.branchName()}"`);
34415-
await repo.checkoutBranch(!branchExists);
34416-
// Write a file
34417-
(0, core_1.info)(`Update readme in "${config.path.readme}" file`);
34418-
(0, filesystem_1.writeFile)(config, config.path.readme, preview);
34419-
}
34420-
else {
34411+
if (content === preview) {
3442134412
(0, core_1.info)(`File "${config.path.readme}" is up to date`);
3442234413
return;
3442334414
}
34415+
// Checkout branch
34416+
const branchExists = await repo.branchExists();
34417+
(0, core_1.info)(`Checkout ${branchExists ? 'existing' : 'new'} branch named "${repo.branchName()}"`);
34418+
await repo.checkoutBranch(!branchExists);
34419+
// Write a file
34420+
(0, core_1.info)(`Update readme in "${config.path.readme}" file`);
34421+
(0, filesystem_1.writeFile)(config, config.path.readme, preview);
3442434422
// Stage and commit changes
3442534423
await repo.stage();
3442634424
await repo.commit();

src/main.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,21 @@ const previewUpdater = async () => {
4545
const content = readFile(config, config.path.readme)
4646
const preview = setPreview(content, config)
4747

48-
if (content !== preview) {
49-
// Checkout branch
50-
const branchExists = await repo.branchExists()
51-
info(`Checkout ${ branchExists ? 'existing' : 'new' } branch named "${ repo.branchName() }"`)
52-
await repo.checkoutBranch(! branchExists)
53-
54-
// Write a file
55-
info(`Update readme in "${ config.path.readme }" file`)
56-
writeFile(config, config.path.readme, preview)
57-
} else {
48+
if (content === preview) {
5849
info(`File "${ config.path.readme }" is up to date`)
5950

6051
return
6152
}
6253

54+
// Checkout branch
55+
const branchExists = await repo.branchExists()
56+
info(`Checkout ${ branchExists ? 'existing' : 'new' } branch named "${ repo.branchName() }"`)
57+
await repo.checkoutBranch(! branchExists)
58+
59+
// Write a file
60+
info(`Update readme in "${ config.path.readme }" file`)
61+
writeFile(config, config.path.readme, preview)
62+
6363
// Stage and commit changes
6464
await repo.stage()
6565
await repo.commit()

0 commit comments

Comments
 (0)