-
Notifications
You must be signed in to change notification settings - Fork 1
/
sky
82 lines (75 loc) · 2.21 KB
/
sky
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
#!/usr/bin/env php
<?php
define('START_TS', microtime(true));
if (1 == $argc)
$argv = [0, ''];
$d = 'dir' == $argv[1];
if ($d || 'php' == $argv[1]) { // 2do cut too long lists
require __DIR__ . '/w2/rare.php';
$dirs = Rare::walk_dirs('.');
if ($d) {
print_r($dirs);
} else foreach($dirs as $one) {
$files = Rare::list_path($one, 'is_file');
foreach($files as $one)
system("php -l $one");
}
echo "\n";
exit;
}
$dir_run = function ($cwd = false, &$found = null) {
static $dir_r, $ary;
if (null === $found) # is get "dir run"
return $dir_r;
$dir_r = $cwd;
$ary =& $found;
return function (&$m) use (&$ary) {
$ok = function ($fn, $d = '') {
$d and $d .= '/';
$has_dir = is_dir($d . 'mvc') || is_dir($d . 'w3');
if (!is_file($d . $fn) || !$has_dir)
return false;
$app = (bool)strpos(file_get_contents($d . $fn), '/sky.php');
return $d && $app || !$d && !$app;
};
if (is_dir('.git'))
$ary[2] = getcwd(); # git dir
if ($ok('config.yaml'))
$ary[1] = getcwd(); # ware
in_array($m, $list = ['main', 'blue']) or $m && array_unshift($list, $m);
foreach ($list as $main) {
if ($ok('../bootstrap.php', $main)) {
$m = $main;
return $ary[0] = true; # the coresky app
}
}
return false;
};
};
$found = [false, false, false];
$test = $dir_run($cwd = getcwd(), $found);
$dir_m = '';
do {
if ($test($dir_m))
break;
$dir_m = basename($cwd);
chdir('..'); # updir
if ($cwd == ($_cd = getcwd()))
break;
} while($cwd = $_cd);
if (!$found[0] && is_file(($cwd = $found[1] ?: __DIR__) . "/.coresky")) { # try find app
$cwd = trim(file_get_contents("$cwd/.coresky"));
if ($cwd && is_dir($cwd))
$found[0] = true; # attach app
}
if ($found[0] && 's' != $argv[1]) {
require "$cwd/bootstrap.php";
new SKY;
SKY::$debug = 1;
} else {
chdir($found[0] ? $cwd : ($found[1] ?: $found[2] ?: $dir_run()));
define('DIR_S', __DIR__);
require DIR_S . '/w2/console.php';
}
new Console($argv, $found);
echo "\n";