Skip to content

Commit 15482b3

Browse files
committed
feat: #53 old command save markdown
1 parent bf7a7d7 commit 15482b3

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

app/Commands/WikiImportCommand.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class WikiImportCommand extends Command
3333
{--coding_token= : CODING 令牌}
3434
{--coding_team_domain= : CODING 团队域名,如 xxx.coding.net 即填写 xxx}
3535
{--coding_project_uri= : CODING 项目标识,如 xxx.coding.net/p/yyy 即填写 yyy}
36+
{--save-markdown : 本地保留生成的 Markdown 文件}
3637
';
3738

3839
/**
@@ -188,6 +189,9 @@ private function uploadConfluencePages(string $dataPath, array $tree, array $tit
188189
);
189190
$markdown = $this->codingWiki->replaceAttachments($markdown, $codingAttachments);
190191
$mdFilename = substr($page, 0, -5) . '.md';
192+
if ($this->option('save-markdown')) {
193+
file_put_contents($dataPath . $mdFilename, $markdown . "\n");
194+
}
191195
$zipFilePath = $this->codingWiki->createMarkdownZip($markdown, $dataPath, $mdFilename);
192196
$result = $this->codingWiki->createWikiByUploadZip(
193197
$this->codingToken,

tests/Feature/WikiImportCommandTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public function testHandleConfluenceHtmlSuccess()
174174
$this->instance(Disk::class, $mockDisk);
175175
$mockDisk->shouldReceive('uploadAttachments')->times(4)->andReturn([]);
176176

177-
$this->artisan('wiki:import')
177+
$this->artisan('wiki:import', ['--save-markdown' => true])
178178
->expectsQuestion('数据来源?', 'Confluence')
179179
->expectsQuestion('数据类型?', 'HTML')
180180
->expectsQuestion('空间导出的 HTML zip 文件路径', $this->dataDir . 'confluence/space1/')
@@ -192,6 +192,12 @@ public function testHandleConfluenceHtmlSuccess()
192192
->expectsOutput('标题:Text Demo')
193193
->expectsOutput('上传成功,正在处理,任务 ID:a12353fa-f45b-4af2-83db-666bf9f66615')
194194
->assertExitCode(0);
195+
$this->assertFileExists($this->dataDir . 'confluence/space1/65591.md');
196+
$this->assertFileExists($this->dataDir . 'confluence/space1/attachment-demo_65615.md');
197+
$this->assertFileExists($this->dataDir . 'confluence/space1/text-demo_65601.md');
198+
unlink($this->dataDir . 'confluence/space1/65591.md');
199+
unlink($this->dataDir . 'confluence/space1/attachment-demo_65615.md');
200+
unlink($this->dataDir . 'confluence/space1/text-demo_65601.md');
195201
}
196202

197203
public function testAskNothing()

tests/data/confluence/space1/image-demo_65619.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ It is a long established fact that a reader will be distracted by the readable c
2020

2121
world
2222

23-
![](attachments/65619/65623.png)![](attachments/65619/65624.png)
23+
![](attachments/65619/65623.png)![](attachments/65619/65624.png)

0 commit comments

Comments
 (0)