Skip to content
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

Merged
merged 18 commits into from
Apr 5, 2023
Merged

refactor(cli): split cli in actions files #889

merged 18 commits into from
Apr 5, 2023

Conversation

pepoviola
Copy link
Collaborator

Split the cli in diff actions files.

pepoviola and others added 2 commits April 3, 2023 10:30
Co-authored-by: Loris Moulin <45130584+l0r1s@users.noreply.github.com>
@pepoviola pepoviola marked this pull request as ready for review April 3, 2023 13:59
@pepoviola pepoviola requested a review from l0r1s April 5, 2023 11:47
Comment on lines 66 to 80
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,
});
});
Copy link
Contributor

@l0r1s l0r1s Apr 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good 👍

Comment on lines 84 to 95
simpleParachains &&
simpleParachains.forEach((sp: any) => {
collators.push({
name: sp.name,
command: "adder-collator",
...DEFAULT_NODE_VALUES,
});
paras.push({
id: sp.id,
collators,
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Contributor

@l0r1s l0r1s Apr 5, 2023

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 ?

Copy link
Collaborator Author

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!

Comment on lines +120 to +126
fs.writeFile(
`${fullPath}/${fileName}-zombienet.json`,
JSON.stringify(jsonOutput),
(error: any) => {
if (error) throw error;
},
);
Copy link
Contributor

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:

Suggested change
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)
);

Copy link
Collaborator Author

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.

Copy link
Contributor

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"));
Copy link
Contributor

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):

Suggested change
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.

Copy link
Collaborator Author

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!

Copy link
Contributor

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>
pepoviola and others added 3 commits April 5, 2023 09:51
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>
pepoviola and others added 9 commits April 5, 2023 09:52
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>
@pepoviola pepoviola requested a review from l0r1s April 5, 2023 14:29
export async function setup(params: any) {
const POSSIBLE_BINARIES = ["polkadot", "polkadot-parachain"];

console.log(decorators.green("\n\n🧟🧟🧟 ZombieNet Setup 🧟🧟🧟\n\n"));
Copy link
Contributor

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

@pepoviola pepoviola merged commit b7e15b7 into main Apr 5, 2023
@pepoviola pepoviola deleted the refactor-cli branch April 5, 2023 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants