Get child nodes' info of groups

How can i get the information about the child nodes of a group, if a group is having any child node.
If there are no child nodes, then delete that group from diagram.
Also, what difference it will make if a group is made “invisible” rather than deleted?

Group.memberParts provides an Iterator over the Parts that are the immediate members if the Group.

I suppose you could implement Group.memberAdded and Group.memberRemoved event handlers:

{
  memberAdded: updateGroup,
  memberRemoved: updateGroup
}

Where

function updateGroup(group, part) {
  group.visible = group.memberParts.count > 0;
}

If something is not visible it is still present in the diagram but takes no space. Non visible nodes cause connected links to disappear. Non visible groups cause all members to disappear. (Not an issue for your case?)

Whereas there is no way for a deleted object to be seen again other than by re-adding and thus re-creating it again.