Skip to content

Commit

Permalink
feat(DtsGenerator): Added AllRoadizNodesSources Typescript type
Browse files Browse the repository at this point in the history
  • Loading branch information
ambroisemaupate committed Dec 2, 2023
1 parent a62c34f commit c249f37
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions lib/DtsGenerator/src/Generators/DeclarationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,24 @@ public function getContents(): string
$blocks[] = $this->generatorFactory->createForNodeType($nodeType)->getContents();
}

$blocks[] = $this->getAllTypesInterface();

return implode(PHP_EOL . PHP_EOL, $blocks);
}

private function getAllTypesInterface(): string
{
$nodeTypeNames = array_map(function (NodeTypeInterface $nodeType) {
return $nodeType->getSourceEntityClassName();
}, $this->nodeTypes);

$nodeTypeNames = implode(' | ', $nodeTypeNames);

return <<<EOT
export type AllRoadizNodesSources = {$nodeTypeNames};
EOT;
}

private function getHeader(): string
{
return <<<EOT
Expand Down
2 changes: 1 addition & 1 deletion lib/DtsGenerator/src/Generators/NodeTypeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function getContents(): string
protected function getInterfaceBody(): string
{
$lines = [
'interface ' . $this->nodeType->getSourceEntityClassName() . ' extends RoadizNodesSources {',
'export interface ' . $this->nodeType->getSourceEntityClassName() . ' extends RoadizNodesSources {',
$this->getFieldsContents(),
'}'
];
Expand Down

0 comments on commit c249f37

Please sign in to comment.