Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

Commit

Permalink
Add templates support
Browse files Browse the repository at this point in the history
  • Loading branch information
arrilot committed Jan 22, 2021
1 parent eacc2fb commit 3a66623
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 53 deletions.
14 changes: 12 additions & 2 deletions config/openapi-client-generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@
/**
* Need generate nest js module, only for backend services
*/
'generate_nestjs_module' => false
'generate_nestjs_module' => false,

/**
* Directory where you can place templates to override default ones. . Used in -t
*/
'template_dir' => '',
],

/**
Expand All @@ -65,6 +70,11 @@
'invokerPackage' => '<paste_your_php_package_namespace>',
'modelPackage' => 'Dto',
'packageName' => '<paste_your_php_package_name>'
]
],

/**
* Directory where you can place templates to override default ones. . Used in -t
*/
'template_dir' => '',
]
];
21 changes: 10 additions & 11 deletions src/Commands/GenerateClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ abstract class GenerateClient extends Command {
*/
protected $params;

/**
* @var string
*/
protected $templateDir;

public function __construct()
{
parent::__construct();
Expand All @@ -60,6 +65,7 @@ public function __construct()
$this->gitHost = config('openapi-client-generator.git_host', '');

$this->params = config("openapi-client-generator.{$this->client}_args.params");
$this->templateDir = config("openapi-client-generator.{$this->client}_args.template_dir", '');
}

/**
Expand All @@ -72,7 +78,6 @@ public function handle()
$this->generateClientPackage();
$this->patchClientPackage();
$this->copyLicenseToClientPackage();
$this->copyGitIgnoreToPackage();
}

protected abstract function patchClientPackage(): void;
Expand Down Expand Up @@ -105,6 +110,10 @@ private function getGeneratorArguments(): string
if (Str::length($this->gitHost) > 0) {
$arguments .= " --git-host " . escapeshellarg($this->gitHost);
}

if (Str::length($this->templateDir) > 0) {
$arguments .= " -t " . escapeshellarg($this->templateDir);
}

$additionalParams = $this->getAdditionalParamsArgument();

Expand Down Expand Up @@ -135,16 +144,6 @@ private function copyLicenseToClientPackage(): void
}
}

private function copyGitIgnoreToPackage(): void
{
$source = $this->templatePath('template.gitignore');
$dest = $this->outputDir . DIRECTORY_SEPARATOR . '.gitignore';
if (!file_exists($dest)) {
copy($source, $dest);
$this->info("Template .gitignore copied to package");
}
}

protected function templatePath(string $path): string
{
return __DIR__ . '/../../templates/' . ltrim($path, '/');
Expand Down
40 changes: 0 additions & 40 deletions templates/template.gitignore

This file was deleted.

0 comments on commit 3a66623

Please sign in to comment.