forked from easychen/stack-roadmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RoboFile.php
65 lines (64 loc) · 2.16 KB
/
RoboFile.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
* This is project's console commands configuration for Robo task runner.
*
* @see https://robo.li/
*/
class RoboFile extends \Robo\Tasks
{
// define public methods as commands
public function copyImages( $file_path = null )
{
if( !$file_path ) $file_path = $this->ask('请输入要复制图片的md文档路径');
if( !file_exists($file_path) )
{
$this->say('文件不存在');
return;
}
// get image path from markdown file
$content = file_get_contents($file_path);
if(preg_match_all('/!\[.*\]\((.*)\)/', $content, $matches))
{
$image_path = $matches[1];
// if not start with http, then copy it to current path
foreach($image_path as $path)
{
if( !preg_match('/^http/', $path) )
{
$from_path = dirname($file_path).'/'.$path;
$to_path = __DIR__.'/src/'.$path;
$this->_copy($from_path,$to_path);
echo basename( $path )." ⭕️ \r\n";
}
}
}
$this->say('🎉 Done');
}
public function copyImage2( $file_path = null )
{
if( !$file_path ) $file_path = $this->ask('请输入要复制图片的md文档路径');
if( !file_exists($file_path) )
{
$this->say('文件不存在');
return;
}
// get image path from markdown file
$content = file_get_contents($file_path);
if(preg_match_all('/!\[.*\]\((.*)\)/', $content, $matches))
{
$image_path = $matches[1];
// if not start with http, then copy it to current path
foreach($image_path as $path)
{
if( !preg_match('/^http/', $path) )
{
$from_path = '/Users/easy/Code/gitcode/lean-side-bussiness/src/'.$path;
$to_path = __DIR__.'/src/'.$path;
$this->_copy($from_path,$to_path);
echo basename( $path )." ⭕️ \r\n";
}
}
}
$this->say('🎉 Done');
}
}