-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask.php
More file actions
99 lines (89 loc) · 2.92 KB
/
Copy pathtask.php
File metadata and controls
99 lines (89 loc) · 2.92 KB
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
<?php
/**
* @author Candison November <www.kandisheng.com>
*/
require_once(__DIR__ . '/vendor/autoload.php');
use CodeMommy\TaskPHP\Task;
use Symfony\Component\Filesystem\Filesystem;
use Core\Path;
/**
* Task Update
*/
function taskUpdate()
{
system('git pull');
Task::line();
system('composer self-update');
Task::line();
system('composer update');
}
Task::add('update', 'Update Composer', 'taskUpdate');
/**
* Task Update Version
*/
function taskUpdateVersion()
{
$file = __DIR__ . '/composer.json';
$composer = file_get_contents($file);
$composer = json_decode($composer, true);
$version = $composer['version'];
$version = explode('.', $version);
$version[2] = intval($version[2]) + 1;
$version = implode('.', $version);
$composer['version'] = $version;
$composer = json_encode($composer, JSON_PRETTY_PRINT);
$composer = str_replace('\\/', '/', $composer);
file_put_contents($file, $composer);
echo(sprintf('Updated version to %s.', $version));
}
Task::add('update-version', 'Update Version', 'taskUpdateVersion');
/**
* Task Publish
*/
function taskPublish()
{
// Composer
$composerFile = Path::application('composer.json');
$composerContent = file_get_contents($composerFile);
$composer = json_decode($composerContent, true);
$applicationName = isset($composer['title']) ? $composer['title'] : '';
$applicationVersion = isset($composer['version']) ? $composer['version'] : '';
// Config
$pharTarget = Path::application('.publish');
$pharSource = Path::application('.temporary');
$pharIndex = 'application.php';
$pharWebIndex = 'application.php';
$pharName = sprintf('%s.phar', $applicationName);
$pharFileName = sprintf('%s_%s.phar', $applicationName, $applicationVersion);
$pharFilePath = sprintf('%s/%s', $pharTarget, $pharFileName);
// Prepare
$fileSystem = new Filesystem();
$fileSystem->remove($pharSource);
$fileSystem->mkdir($pharSource);
$fileSystem->mkdir($pharTarget);
$copyList = array('command', 'core', 'vendor', 'application.php', 'composer.json');
foreach ($copyList as $value) {
$sourceFile = sprintf('%s/%s', __DIR__, $value);
$targetFile = sprintf('%s/%s', $pharSource, $value);
if (is_dir($sourceFile)) {
Path::copyDirectory($sourceFile, $targetFile);
}
if (is_file($sourceFile)) {
$fileSystem->copy($sourceFile, $targetFile);
}
}
// Run
$phar = new Phar($pharFilePath, 0, $pharName);
$phar->buildFromDirectory($pharSource);
$phar->setStub($phar->createDefaultStub($pharIndex, $pharWebIndex));
$phar->compressFiles(Phar::GZ);
// Clean
$fileSystem->copy(sprintf('%s/%s', $pharTarget, $pharFileName), sprintf('%s/%s', $pharTarget, $pharName));
$fileSystem->remove($pharSource);
}
Task::add('publish', 'Publish', 'taskPublish');
/**
* Start
*/
Task::config('NotePHP Task', '');
Task::run();