-
Notifications
You must be signed in to change notification settings - Fork 92
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
refactor(cli): split cli in actions files #889
Conversation
Co-authored-by: Loris Moulin <45130584+l0r1s@users.noreply.github.com>
parachains && | ||
parachains.forEach((parachain: any) => { | ||
collators = []; | ||
parachain.nodes.forEach((n: any) => { | ||
collators.push({ | ||
name: n.name, | ||
command: "adder-collator", | ||
...DEFAULT_NODE_VALUES, | ||
}); | ||
}); | ||
paras.push({ | ||
id: parachain.id, | ||
collators, | ||
}); | ||
}); |
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.
parachains && | |
parachains.forEach((parachain: any) => { | |
collators = []; | |
parachain.nodes.forEach((n: any) => { | |
collators.push({ | |
name: n.name, | |
command: "adder-collator", | |
...DEFAULT_NODE_VALUES, | |
}); | |
}); | |
paras.push({ | |
id: parachain.id, | |
collators, | |
}); | |
}); | |
paras = paras.concat( | |
parachains.map(({ id, nodes }) => ({ | |
id, | |
collators: (nodes || []).map(({ name }) => ({ | |
name, | |
command: "adder-collator", | |
...DEFAULT_NODE_VALUES, | |
})), | |
})), | |
); |
What do you think, using destructuring and functionnal programming ?
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.
Sounds good 👍
simpleParachains && | ||
simpleParachains.forEach((sp: any) => { | ||
collators.push({ | ||
name: sp.name, | ||
command: "adder-collator", | ||
...DEFAULT_NODE_VALUES, | ||
}); | ||
paras.push({ | ||
id: sp.id, | ||
collators, | ||
}); | ||
}); |
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.
simpleParachains && | |
simpleParachains.forEach((sp: any) => { | |
collators.push({ | |
name: sp.name, | |
command: "adder-collator", | |
...DEFAULT_NODE_VALUES, | |
}); | |
paras.push({ | |
id: sp.id, | |
collators, | |
}); | |
}); | |
paras = paras.concat( | |
simpleParachains.map(({ id, name }) => ({ | |
id, | |
collators: [{ name, command: "adder-collator", ...DEFAULT_NODE_VALUES }], | |
})), | |
); |
Destructuring and functionnal programming part 2
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.
My question here is, because we don't reset the collators array in the old code, do we really want to have a parachain B to have the previous collator of parachain A ?
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.
No, we don't want. This is a bug and the suggested code is ok.
Thanks!
fs.writeFile( | ||
`${fullPath}/${fileName}-zombienet.json`, | ||
JSON.stringify(jsonOutput), | ||
(error: any) => { | ||
if (error) throw error; | ||
}, | ||
); |
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 use fs/promises instead of fs, you can simplify to:
fs.writeFile( | |
`${fullPath}/${fileName}-zombienet.json`, | |
JSON.stringify(jsonOutput), | |
(error: any) => { | |
if (error) throw error; | |
}, | |
); | |
await fs.writeFile( | |
`${fullPath}/${fileName}-zombienet.json`, | |
JSON.stringify(jsonOutput) | |
); |
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 should change the import
to use fs.promises here.
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.
Yes, the exact import is import {...} from "fs/promises
export async function setup(params: any) { | ||
const POSSIBLE_BINARIES = ["polkadot", "polkadot-parachain"]; | ||
|
||
console.log(decorators.green("\n\n🧟🧟🧟 ZombieNet Setup 🧟🧟🧟\n\n")); |
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.
Have you heard about the colors library ?
It could enable to simplify the code like this (it extends the String.constructor):
console.log(decorators.green("\n\n🧟🧟🧟 ZombieNet Setup 🧟🧟🧟\n\n")); | |
console.log("\n\n🧟🧟🧟 ZombieNet Setup 🧟🧟🧟\n\n".green); |
Simpler and better because we don't have to manage our own "colors" system in utils.
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.
Yes, I remember to look at colors
but I just went to make an small library for a few colors we use. We can iterate over this decision.
Thanks!
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.
Have you heard about the colors library ?
It could enable to simplify the code like this (it extends the String.constructor):
Simpler and better because we don't have to manage our own "colors" system in utils.
I think we should reduce npm dependencies as much as possible
Co-authored-by: Loris Moulin <45130584+l0r1s@users.noreply.github.com>
Co-authored-by: Loris Moulin <45130584+l0r1s@users.noreply.github.com>
Co-authored-by: Loris Moulin <45130584+l0r1s@users.noreply.github.com>
Co-authored-by: Loris Moulin <45130584+l0r1s@users.noreply.github.com>
Co-authored-by: Loris Moulin <45130584+l0r1s@users.noreply.github.com>
Co-authored-by: Loris Moulin <45130584+l0r1s@users.noreply.github.com>
Co-authored-by: Loris Moulin <45130584+l0r1s@users.noreply.github.com>
Co-authored-by: Loris Moulin <45130584+l0r1s@users.noreply.github.com>
Co-authored-by: Loris Moulin <45130584+l0r1s@users.noreply.github.com>
Co-authored-by: Loris Moulin <45130584+l0r1s@users.noreply.github.com>
Co-authored-by: Loris Moulin <45130584+l0r1s@users.noreply.github.com>
export async function setup(params: any) { | ||
const POSSIBLE_BINARIES = ["polkadot", "polkadot-parachain"]; | ||
|
||
console.log(decorators.green("\n\n🧟🧟🧟 ZombieNet Setup 🧟🧟🧟\n\n")); |
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.
Have you heard about the colors library ?
It could enable to simplify the code like this (it extends the String.constructor):
Simpler and better because we don't have to manage our own "colors" system in utils.
I think we should reduce npm dependencies as much as possible
Split the
cli
in diffaction
s files.