|
0
|
1 |
#!/usr/bin/env php
|
|
|
2 |
<?php
|
|
|
3 |
|
|
|
4 |
/*
|
|
|
5 |
* This file is part of the Symfony Standard Edition.
|
|
|
6 |
*
|
|
|
7 |
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
8 |
*
|
|
|
9 |
* For the full copyright and license information, please view the LICENSE
|
|
|
10 |
* file that was distributed with this source code.
|
|
|
11 |
*/
|
|
|
12 |
|
|
|
13 |
$rootDir = dirname(__DIR__);
|
|
|
14 |
$vendorDir = $rootDir.'/vendor';
|
|
|
15 |
|
|
|
16 |
array_shift($argv);
|
|
|
17 |
if (!isset($argv[0])) {
|
|
|
18 |
exit(<<<EOF
|
|
|
19 |
Symfony2 vendors script management.
|
|
|
20 |
|
|
|
21 |
Specify a command to run:
|
|
|
22 |
|
|
|
23 |
install: install vendors as specified in deps or deps.lock (recommended)
|
|
|
24 |
update: update vendors to their latest versions (as specified in deps)
|
|
|
25 |
|
|
|
26 |
|
|
|
27 |
EOF
|
|
|
28 |
);
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
if (!in_array($command = array_shift($argv), array('install', 'update'))) {
|
|
|
32 |
exit(sprintf("Command \"%s\" does not exist.\n", $command));
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
/*
|
|
|
36 |
* Check wether this project is based on the Standard Edition that was
|
|
|
37 |
* shipped with vendors or not.
|
|
|
38 |
*/
|
|
|
39 |
if (is_dir($vendorDir.'/symfony') && !is_dir($vendorDir.'/symfony/.git') && !in_array('--reinstall', $argv)) {
|
|
|
40 |
exit(<<<EOF
|
|
|
41 |
Your project seems to be based on a Standard Edition that includes vendors.
|
|
|
42 |
|
|
|
43 |
Try to run ./bin/vendors install --reinstall
|
|
|
44 |
|
|
|
45 |
|
|
|
46 |
EOF
|
|
|
47 |
);
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
if (!is_dir($vendorDir)) {
|
|
|
51 |
mkdir($vendorDir, 0777, true);
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
// versions
|
|
|
55 |
$versions = array();
|
|
|
56 |
if ('install' === $command && file_exists($rootDir.'/deps.lock')) {
|
|
|
57 |
foreach (file($rootDir.'/deps.lock', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) {
|
|
|
58 |
$parts = array_values(array_filter(explode(' ', $line)));
|
|
|
59 |
if (2 !== count($parts)) {
|
|
|
60 |
exit(sprintf('The deps version file is not valid (near "%s")', $line));
|
|
|
61 |
}
|
|
|
62 |
$versions[$parts[0]] = $parts[1];
|
|
|
63 |
}
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
$newversions = array();
|
|
|
67 |
$deps = parse_ini_file($rootDir.'/deps', true, INI_SCANNER_RAW);
|
|
|
68 |
if (false === $deps) {
|
|
|
69 |
exit("The deps file is not valid ini syntax. Perhaps missing a trailing newline?\n");
|
|
|
70 |
}
|
|
|
71 |
foreach ($deps as $name => $dep) {
|
|
|
72 |
$dep = array_map('trim', $dep);
|
|
|
73 |
|
|
|
74 |
// revision
|
|
|
75 |
if (isset($versions[$name])) {
|
|
|
76 |
$rev = $versions[$name];
|
|
|
77 |
} else {
|
|
|
78 |
$rev = isset($dep['version']) ? $dep['version'] : 'origin/HEAD';
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
// install dir
|
|
|
82 |
$installDir = isset($dep['target']) ? $vendorDir.'/'.$dep['target'] : $vendorDir.'/'.$name;
|
|
|
83 |
if (in_array('--reinstall', $argv)) {
|
|
|
84 |
if (PHP_OS == 'WINNT') {
|
|
|
85 |
system(sprintf('rmdir /S /Q %s', escapeshellarg(realpath($installDir))));
|
|
|
86 |
} else {
|
|
|
87 |
system(sprintf('rm -rf %s', escapeshellarg($installDir)));
|
|
|
88 |
}
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
echo "> Installing/Updating $name\n";
|
|
|
92 |
|
|
|
93 |
// url
|
|
|
94 |
if (!isset($dep['git'])) {
|
|
|
95 |
exit(sprintf('The "git" value for the "%s" dependency must be set.', $name));
|
|
|
96 |
}
|
|
|
97 |
$url = $dep['git'];
|
|
|
98 |
|
|
|
99 |
if (!is_dir($installDir)) {
|
|
|
100 |
system(sprintf('git clone %s %s', escapeshellarg($url), escapeshellarg($installDir)));
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
system(sprintf('cd %s && git fetch origin && git reset --hard %s', escapeshellarg($installDir), escapeshellarg($rev)));
|
|
|
104 |
|
|
|
105 |
if ('update' === $command) {
|
|
|
106 |
ob_start();
|
|
|
107 |
system(sprintf('cd %s && git log -n 1 --format=%%H', escapeshellarg($installDir)));
|
|
|
108 |
$newversions[] = trim($name.' '.ob_get_clean());
|
|
|
109 |
}
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
// update?
|
|
|
113 |
if ('update' === $command) {
|
|
|
114 |
file_put_contents($rootDir.'/deps.lock', implode("\n", $newversions));
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
// php on windows can't use the shebang line from system()
|
|
|
118 |
$interpreter = PHP_OS == 'WINNT' ? 'php.exe' : '';
|
|
|
119 |
|
|
|
120 |
// Update the bootstrap files
|
|
|
121 |
system(sprintf('%s %s', $interpreter, escapeshellarg($rootDir.'/vendor/bundles/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php')));
|
|
|
122 |
|
|
|
123 |
// Update assets
|
|
|
124 |
system(sprintf('%s %s assets:install %s', $interpreter, escapeshellarg($rootDir.'/app/console'), escapeshellarg($rootDir.'/web/')));
|
|
|
125 |
|
|
|
126 |
// Remove the cache
|
|
|
127 |
system(sprintf('%s %s cache:clear --no-warmup', $interpreter, escapeshellarg($rootDir.'/app/console')));
|