-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ Combine label files in new combined.json #44
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a good start, but the code might be fragile as we expand what data is saved to the filesystem
scripts/combine.ts
Outdated
files.forEach((file) => { | ||
if ( | ||
file.endsWith(".json") && | ||
(file === "tokens.json" || file === "accounts.json") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make this agnostic for all files in the directory. If we ever add support for blocks or txs, this method will not combine:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i will replace with endswith(".json") and file!=="combine.json"
scripts/combine.ts
Outdated
(file === "tokens.json" || file === "accounts.json") | ||
) { | ||
const filePath: string = path.join(dataDir, file); | ||
const data: Buffer = fs.readFileSync(filePath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you change this to instead use the FileSystem
class we have in the codebase, you don't need to use fs
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will work on that now
scripts/combine.ts
Outdated
) { | ||
const filePath: string = path.join(dataDir, file); | ||
const data: Buffer = fs.readFileSync(filePath); | ||
const jsonData: Array<{ address: string }> = JSON.parse( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can any of these Array
s be replaced with ReadonlyArray
?
scripts/combine.ts
Outdated
} | ||
|
||
function runCombine() { | ||
fs.readdir(dataFolderPath, (err, files) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be done Sync
and the fs logic also moved into the FileSystem class
…up typing and merged with new optimism code
55cfe83
to
4a6dd20
Compare
… a combination of all other combined.json which shows missing records in optimism
scripts/combine.ts
Outdated
import path from "path"; | ||
import { FileUtilities } from "./FileSystem/FileSystem"; | ||
|
||
const fs = new FileUtilities(import.meta.url); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you instantiate a class called FileUtilities
, it's best practice to call it fileUtilities
.
By calling it "fs
", it is difficult to know as a future developer if we're using the fs
module from node.js
scripts/combine.ts
Outdated
const providers = fs.readDir(dataFolderPath); | ||
providers.forEach((provider) => { | ||
const providerPath: string = path.join(dataFolderPath, provider); | ||
if (!provider.includes(".")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When does a provider
include a ".
"? What is a "provider
"? I'm not sure if we want to ship this with that variable name. Maybe a comment could help here
scripts/combine.ts
Outdated
const fs = new FileUtilities(import.meta.url); | ||
|
||
function combineFiles(dataDir: string) { | ||
const files: ReadonlyArray<string> = fs.readDir(dataDir); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of a type-assertion here, what I might prefer here is for fs.readDir
to return a ReadonlyArray<string>
. Is that possible instead or in-addition?
Closes #27