forked from codeceptjs/CodeceptJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RoboFile.php
177 lines (151 loc) · 5.92 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php
/**
* This is project's console commands configuration for Robo task runner.
*
* @see http://robo.li/
*/
class RoboFile extends \Robo\Tasks
{
function docs() {
$this->docsHelpers();
$this->docsPlugins();
}
function docsPlugins() {
$this->_exec("npx documentation build lib/plugin/*.js -o docs/plugins.md -f md --shallow --markdown-toc=false --sort-order=alpha ");
$this->taskWriteToFile("docs/plugins.md")
->line('---')
->line("id: plugins")
->line("title: Plugins")
->line('---')
->line('')
->textFromFile("docs/plugins.md")
->run();
}
function docsHelpers()
{
$files = scandir('lib/helper');
$partials = array_slice(scandir('docs/webapi'), 2);
$placeholders = array_map(function($p) { $p = str_replace('.mustache', '', $p); return "{{> $p }}"; }, $partials);
$templates = array_map(function($p) { return trim(substr(preg_replace('~^~m', " * " , file_get_contents("docs/webapi/$p")), 5)) . "\n * {--end--}"; }, $partials);
$sharedPartials = array_slice(scandir('docs/shared'), 2);
$sharedPlaceholders = array_map(function($p) { $p = str_replace('.mustache', '', $p); return "{{ $p }}"; }, $sharedPartials);
$sharedTemplates = array_map(function($p) { return "\n\n\n" . file_get_contents("docs/shared/$p"); }, $sharedPartials);
foreach ($files as $file) {
$info = pathinfo($file);
if (!isset($info['extension'])) continue;
if ($info['extension'] !== 'js') continue;
$this->_copy("lib/helper/$file", "docs/build/$file");
$this->taskReplaceInFile("docs/build/$file")
->from($placeholders)
->to($templates)
->run();
$this->_exec("npx documentation build docs/build/{$info['basename']} -o docs/helpers/{$info['filename']}.md -f md --shallow --markdown-toc=false --sort-order=alpha ");
// removing badly formatted documentation.js shit
$this->taskReplaceInFile("docs/helpers/{$info['filename']}.md")
->regex(['{{--end--}}','~\(optional, default.*?\)~','~\\*~'])
->to(["\n",'',''])
->run();
$this->taskReplaceInFile("docs/helpers/{$info['filename']}.md")
->from($sharedPlaceholders)
->to($sharedTemplates)
->run();
$this->taskWriteToFile("docs/helpers/{$info['filename']}.md")
->line('---')
->line("id: {$info['filename']}")
->line("title: {$info['filename']}")
->line('---')
->line('')
->textFromFile("docs/helpers/{$info['filename']}.md")
->run();
}
}
function publishSite()
{
$this->stopOnFail();
$this->_copy('CHANGELOG.md', 'docs/changelog.md');
$this->_copy('docker/README.md', 'docs/docker.md');
$this->wiki();
$this->taskExec('npm install')
->dir('website')
->run();
$this
->taskExec('USE_SSH=true GIT_USER=davertmik npm run publish-gh-pages')
->dir('website')
->run();
}
/**
* Synchronizes CodeceptJS wiki pages with docs
*/
function wiki()
{
if (!file_exists('website/wiki/Home.md')) {
$this->taskGitStack()
->cloneShallow('[email protected]:Codeception/CodeceptJS.wiki.git', 'website/wiki')
->run();
}
$this->taskGitStack()
->dir('website/wiki')
->pull()
->run();
$this->taskWriteToFile('docs/community-helpers.md')
->line('---')
->line('id: community-helpers')
->line('title: Community Helpers')
->line('---')
->line('')
->line('> Share your helpers at our [Wiki Page](https://github.com/Codeception/CodeceptJS/wiki/Community-Helpers)')
->line('')
->textFromFile('website/wiki/Community-Helpers.md')
->run();
$this->taskWriteToFile('docs/examples.md')
->line('---')
->line('id: examples')
->line('title: Examples')
->line('---')
->line('')
->line('> Add your own examples to our [Wiki Page](https://github.com/Codeception/CodeceptJS/wiki/Examples)')
->textFromFile('website/wiki/Examples.md')
->run();
$this->taskWriteToFile('docs/books.md')
->line('---')
->line('id: books')
->line('title: Books & Posts')
->line('---')
->line('')
->line('> Add your own books or posts to our [Wiki Page](https://github.com/Codeception/CodeceptJS/wiki/Books-&-Posts)')
->textFromFile('website/wiki/Books-&-Posts.md')
->run();
$this->taskWriteToFile('docs/videos.md')
->line('---')
->line('id: videos')
->line('title: Videos')
->line('---')
->line('')
->line('> Add your own videos to our [Wiki Page](https://github.com/Codeception/CodeceptJS/wiki/Videos)')
->textFromFile('website/wiki/Videos.md')
->run();
}
function testServer()
{
$this->taskExec('npm run json-server')
->background()
->run();
$this->taskServer(8000)
->dir('test/data/app')
->run();
}
function release()
{
$package = json_decode(file_get_contents('package.json'), true);
$version = $package['version'];
$this->docs();
$this->stopOnFail();
$this->publishSite();
$this->taskGitStack()
->tag($version)
->push('origin master --tags')
->run();
$this->_exec('npm publish');
$this->yell('It is released!');
}
}