Skip to content

Commit

Permalink
添加文档导出目录
Browse files Browse the repository at this point in the history
  • Loading branch information
zong committed Apr 8, 2020
1 parent 342820e commit 4b9ee48
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
10 changes: 8 additions & 2 deletions src/Commands/Postman.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ class Postman extends Command
{--mode=api : 发布markdown文档}
{--path=docs/api : markdown文档存储位置}';

public $exportPath = '';
public $publishTo = 'docs/api';
public $publishPostmanTo = 'docs';
/**
* @inheritdoc
*/
public function handle()
{
$path = getcwd();
$collection = new Collection($path);
$this->exportPath = $this->exportPath ?:$path;
$collection = new Collection($path,$this->exportPath);
$collection->publishTo = $this->publishTo;
$collection->publishPostmanTo = $this->publishPostmanTo;
$collection->parser();
$this->asMarkdown($collection);
$this->asPostman($collection);
Expand All @@ -38,6 +44,6 @@ private function asMarkdown(Collection $collection)
private function asPostman(Collection $collection)
{
$contents = $collection->toPostman();
$collection->saveMarkdown($collection->basePath.'/'.$collection->publishPostmanTo, 'postman.json', $contents);
$collection->saveMarkdown($collection->exportPath.'/'.$collection->publishPostmanTo, 'postman.json', $contents);
}
}
9 changes: 7 additions & 2 deletions src/Parsers/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ class Collection extends Base
* @var string
*/
public $basePath;
/**
* @var string
*/
public $exportPath;
public $codeMap = null;
private $controllerPath = 'app/Controllers';
public $sdkx;
Expand All @@ -83,10 +87,11 @@ class Collection extends Base
* Controller constructor.
* @param string $path 项目路径
*/
public function __construct(string $path)
public function __construct(string $path,string $exportPath)
{
parent::__construct();
$this->basePath = $path;
$this->exportPath = $exportPath;
// 1. load config
$json = $this->initPostmanJson();
$this->name = $json->name;
Expand Down Expand Up @@ -178,7 +183,7 @@ public function toMarkdown()
$text .= $this->eol;
$text .= $this->getCodeMap();
// 6. save README.md
$this->saveMarkdown($this->basePath.'/'.$this->publishTo, 'README.md', $text);
$this->saveMarkdown($this->exportPath.'/'.$this->publishTo, 'README.md', $text);
// 7. trigger controllers
foreach ($this->controllers as $controller) {
$controller->toMarkdown();
Expand Down
2 changes: 1 addition & 1 deletion src/Parsers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function getIndex($curr = false)
public function toMarkdown()
{
$name = str_replace('\\', '/', substr($this->reflect->getName(), 16));
$path = $this->collection->basePath.'/'.$this->collection->publishTo.'/'.$name;
$path = $this->collection->exportPath.'/'.$this->collection->publishTo.'/'.$name;
$count = count($this->methods);
if ($count === 0) {
$this->console->warning("控制器{$this->reflect->getName()}无可导出动作, 忽略导出");
Expand Down
2 changes: 1 addition & 1 deletion src/Parsers/Method.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function toMarkdown()
$text .= $this->eol;
$text .= $this->collection->getCodeMap();
$name = str_replace('\\', '/', substr($this->controller->reflect->getName(), 16));
$path = $this->collection->basePath.'/'.$this->collection->publishTo.'/'.$name;
$path = $this->collection->exportPath.'/'.$this->collection->publishTo.'/'.$name;
$this->saveMarkdown($path, $this->reflect->getShortName().'.md', $text);
/**
* 添加到SDK列表
Expand Down
2 changes: 1 addition & 1 deletion src/Parsers/Sdkx.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function export()
{
$class = ucfirst($this->collection->sdk).'Sdk';
$template = $this->renderClass($class);
$this->saveMarkdown($this->collection->basePath.'/'.$this->collection->publishPostmanTo, $class.'.php', $template);
$this->saveMarkdown($this->collection->exportPath.'/'.$this->collection->publishPostmanTo, $class.'.php', $template);
}

/**
Expand Down

0 comments on commit 4b9ee48

Please sign in to comment.