Skip to content

Commit fddd391

Browse files
committed
Add bin/console alias
1 parent 1e94883 commit fddd391

3 files changed

Lines changed: 64 additions & 1 deletion

File tree

bin/console

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../vendor/bin/console

bin/create_console_symlink.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
$binDir = __DIR__;
6+
$projectRoot = dirname($binDir);
7+
8+
$linkPath = $binDir . DIRECTORY_SEPARATOR . 'console';
9+
10+
$targetRelativeFromBin = '..' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'console';
11+
12+
function fail(string $message, int $code = 1): void {
13+
fwrite(STDERR, "[create-console-symlink] {$message}\n");
14+
exit($code);
15+
}
16+
17+
function info(string $message): void {
18+
fwrite(STDOUT, "[create-console-symlink] {$message}\n");
19+
}
20+
21+
$targetAbsolute = $projectRoot . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'console';
22+
23+
if (is_link($linkPath) || file_exists($linkPath)) {
24+
if (!@unlink($linkPath)) {
25+
fail("Unable to remove existing bin/console (check permissions).");
26+
}
27+
info("Removed existing: bin/console");
28+
}
29+
30+
$isWindows = (PHP_OS_FAMILY === 'Windows');
31+
32+
if ($isWindows) {
33+
$batPath = $linkPath . '.bat';
34+
$bat = "@echo off\r\n"
35+
. "php \"%~dp0..\\vendor\\bin\\console\" %*\r\n";
36+
37+
if (file_put_contents($batPath, $bat) === false) {
38+
fail("Unable to write: bin/console.bat");
39+
}
40+
info("Created launcher: bin/console.bat");
41+
exit(0);
42+
}
43+
44+
if (!file_exists($targetAbsolute)) {
45+
info("Warning: target not found yet: vendor/bin/console (will still create symlink).");
46+
}
47+
48+
if (!symlink($targetRelativeFromBin, $linkPath)) {
49+
fail("Unable to create symlink bin/console -> {$targetRelativeFromBin}");
50+
}
51+
52+
@chmod($linkPath, 0755);
53+
info("Created symlink: bin/console -> {$targetRelativeFromBin}");

composer.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@
127127
],
128128
"auto-scripts": {
129129
"security-checker security:check": "script"
130-
}
130+
},
131+
"post-install-cmd": [
132+
"@create-console-symlink"
133+
],
134+
"post-update-cmd": [
135+
"@create-console-symlink"
136+
],
137+
"create-console-symlink": [
138+
"@php bin/create_console_symlink.php"
139+
]
131140
}
132141
}

0 commit comments

Comments
 (0)