forked from Rarst/fragment-cache
/
RoboFile.php
92 lines (70 loc) · 2.09 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
<?php
require __DIR__ . '/vendor/autoload.php';
/**
* This is project's console commands configuration for Robo task runner.
*
* @see http://robo.li/
*/
class RoboFile extends \Robo\Tasks {
/**
* @return string
*/
private function versionGet() {
$content = file_get_contents( __DIR__ . '/fragment-cache.php' );
if ( false !== preg_match( '|^Version: (?P<version>.+)$|m', $content, $matches ) ) {
return trim( $matches['version'] );
}
return '';
}
/**
* Sets the plugin version in header.
*
* @param string $version Version string.
*/
public function versionSet( $version ) {
$this->taskReplaceInFile( 'fragment-cache.php' )
->regex( '|^Version:.*$|m' )
->to( 'Version: ' . $version )
->run();
}
/**
* Creates release zip
*
* @param string $version
*/
public function makeRelease( $version = '' ) {
if ( empty( $version ) ) {
$version = $this->versionGet();
}
$name = basename( __DIR__ );
$this->taskFileSystemStack()
->mkdir( 'release' )
->run();
$this->taskCleanDir( 'release' )->run();
$this->taskExec( 'composer' )
->dir( __DIR__ . '/release' )
->arg( "create-project rarst/{$name} {$name} " . $version )
->arg( '--prefer-dist --no-dev' )
->run();
$this->taskExec( 'composer' )
->dir( __DIR__ . "/release/{$name}" )
->arg( 'dump-autoload --optimize' )
->run();
$zipFile = "release/{$name}-{$version}.zip";
$zipArchive = new ZipArchive();
if ( ! $zipArchive->open( $zipFile, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE ) ) {
die( "Failed to create archive\n" );
}
$finder = new Symfony\Component\Finder\Finder();
$finder->files()->in( "release/{$name}" )->ignoreDotFiles( false );
/** @var \Symfony\Component\Finder\SplFileInfo $file */
foreach ( $finder as $file ) {
$zipArchive->addFile( $file->getRealPath(), "{$name}/" . $file->getRelativePathname() );
}
if ( ! $zipArchive->status === ZIPARCHIVE::ER_OK ) {
echo "Failed to write files to zip\n";
}
$zipArchive->close();
$this->taskDeleteDir( "release/{$name}" )->run();
}
}