Skip to content

Commit

Permalink
chore(sync): fix sync to use try catch (#3)
Browse files Browse the repository at this point in the history
#### What this PR does / why we need it:

As per title.
  • Loading branch information
fuxingloh authored Nov 7, 2023
1 parent 1a14741 commit 012648b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
11 changes: 0 additions & 11 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
<!-- Thanks for sending a pull request! -->

#### What this PR does / why we need it:

#### Which issue(s) will this PR fix?:

<!--
(Optional) Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->

Fixes #

#### Additional comments?:
19 changes: 13 additions & 6 deletions workspace/sync-trustwallet-assets/src/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ export abstract class Sync {

async shouldWrite(dir: string, info: Partial<Info>): Promise<boolean> {
// Make sure logo.png and info.json exists
const fromLogoStats = await stat(`${this.from}/${dir}/logo.png`);
const fromInfoStats = await stat(`${this.from}/${dir}/info.json`);
if (!fromLogoStats.isFile() || !fromInfoStats.isFile()) return false;
const hasFromLogo = await hasFile(`${this.from}/${dir}/logo.png`);
const hasFromInfo = await hasFile(`${this.from}/${dir}/info.json`);
if (!hasFromLogo || !hasFromInfo) return false;

// If README.md and logo.png do not exist on the other side, write it
const namespace = this.getNamespace(info);
const toLogoStats = await stat(`${this.to}/${namespace}/logo.png`);
const toReadmeStats = await stat(`${this.to}/${namespace}/README.md`);
if (!toLogoStats.isFile() || !toReadmeStats.isFile()) return true;
const hasToLogo = await hasFile(`${this.to}/${namespace}/logo.png`);
const hasToReadme = await hasFile(`${this.to}/${namespace}/README.md`);
if (!hasToLogo || !hasToReadme) return true;

// Otherwise, allow overwriting if the author is Frontmatter Bot
const name = await getAuthorName(`${this.to}/${namespace}/README.md`);
Expand Down Expand Up @@ -80,6 +80,13 @@ export abstract class Sync {
}
}

function hasFile(filepath: string): Promise<boolean> {
return stat(filepath).then(
() => true,
() => false,
);
}

export class Eip155Sync extends Sync {
async write(dir: string, info: Partial<Info>): Promise<void> {
const namespace = this.getNamespace(info);
Expand Down

0 comments on commit 012648b

Please sign in to comment.