-
Notifications
You must be signed in to change notification settings - Fork 0
Interactive discovery #123
base: main
Are you sure you want to change the base?
Conversation
|
219e06f
to
68af17f
Compare
chore: improve menu pages docs: make comment more precise feat: use raw config instead of VO
1e3c243
to
ad9dd09
Compare
"@l2beat/backend-tools": "^0.5.1", | ||
"@l2beat/discovery-types": "^0.8.0", | ||
"chalk": "^4.1.2", | ||
"comment-json": "^4.2.3", |
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.
We already import jsonc-parser
, either don't use comment-json
or replace jsonc-parser
with it
@@ -70,6 +72,11 @@ export async function dryRunDiscovery( | |||
config.chain, | |||
) | |||
|
|||
const rawConfigWitComments = await configReader.readRawConfigWithComments( |
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.
This is read here, but not used unless the interactive mode is enabled. We can just move the reading of this config into block where interactive mode is enabled.
|
||
async readRawConfigWithComments( | ||
name: string, | ||
chain: string, | ||
): Promise<RawDiscoveryConfig> { | ||
assert( | ||
fileExistsCaseSensitive(`discovery/${name}`), | ||
'Project not found, check if case matches', | ||
) | ||
assert( | ||
fileExistsCaseSensitive(`discovery/${name}/${chain}`), | ||
'Chain not found in project, check if case matches', | ||
) | ||
|
||
const contents = await readFile( | ||
`discovery/${name}/${chain}/config.jsonc`, | ||
'utf-8', | ||
) | ||
const parsed: unknown = parseWithComments(contents) | ||
|
||
// Parsing via Zod would effectively remove symbols and thus comments | ||
assertDiscoveryConfig(parsed) | ||
|
||
assert(parsed.chain === chain, 'Chain mismatch in config.jsonc') | ||
|
||
return parsed | ||
} | ||
} |
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.
There is duplication of reading the config in here now. We should extract the common part, just call readRawConfigWithComments
in readConfig
and drop the comments there.
constructor(private readonly dob: DiscoveryOverridesBuilder) {} | ||
|
||
async runForDiffs(discoveryDiffs: DiscoveryDiff[]): Promise<void> { | ||
console.log(chalk.green('Starting interactive mode...')) |
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.
use Logger
here.
// Filter-out diffs without changes | ||
const changesWithDiffs: Change[] = discoveryDiffs.flatMap( | ||
(discoveryDiff) => { | ||
const contract = discoveryDiff.name |
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.
The name extraction should happen only after the diff actually exists - so after the if below.
} | ||
|
||
getContracts(): ContractParameters[] { | ||
return [...this.output.contracts] |
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.
Why do we need to spread it and later create a new array if the .contracts
already is an array
* Do not replace whole file, just read most-recent raw, replace and save overrides | ||
*/ | ||
async flushOverrides(): Promise<void> { | ||
const path = `discovery/${this.output.name}/${this.output.chain}/config.jsonc` |
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.
Why are we not using ConfigReader
here? We implemented reading a config with comments there and just casually reimplemented this inline here
} | ||
|
||
console.log(chalk.green('Flushing overrides...')) | ||
await this.dob.flushOverrides() |
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.
Couple of things
- we should save inside the UI
dob
shouldn't callwriteFileSync
, change the name fromflushOverrides
tobuildConfig
which returns a new config with overrides that you can later save manually inside therunDiscovery
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 be easily tested
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 be easily tested
i'd love this <33333 |
Resolves L2B-3055
What's changed
Added interactive mode where you can manage overrides (watch mode, relative, methods, etc) over the CLI.
Notes
How to test it?
@l2beat/discovery
- go to/packages/discovery
and useyarn link
in the terminalyarn link @l2beat/discovery
yarn install --force
dist
as a dependency location:6. Go to
/package/backend/
in the main l2beat repo7. Run
yarn discover <chain> <project> --dry-run --interactive
8. Mess around