-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlx-install
executable file
·169 lines (143 loc) · 5.1 KB
/
lx-install
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/env php
<?php
/**
* This script creates directory 'lx' in the project root directory. This is a heart of the platform
* The directory contains:
* 1. Directory 'config' - configuration for the platform
* 2. File 'lx' for launch platform CLI
* 3. Directory '.system' for caches, temp files etc
*/
// fcgi doesn't have STDIN and STDOUT defined by default
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
defined('STDOUT') or define('STDOUT', fopen('php://stdout', 'w'));
require_once(__DIR__ . '/main.php');
$site = new lx\Directory(lx::$conductor->sitePath);
$config = defineConfig($site);
new lx\ConsoleApplication($config);
actualizeGitignore($site);
genFileStructure($site);
genConfig($site);
refreshMaps();
lx\Console::outln('Done');
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Functions
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
function defineConfig(lx\Directory $site): array
{
return $site->contains('lx/config/__map__.php')
? []
: [
'serviceCategories' => [
'project' => [
'services',
],
'dependencies' => [
'vendor',
],
],
];
}
function actualizeGitignore(lx\Directory $siteDirectory): void
{
$gitignore = $siteDirectory->makeFile('.gitignore');
$text = $gitignore->exists() ? $gitignore->get() : '';
$map = [
'/vendor' => 'composer vendor dir',
'/lx/.system' => 'lx local system dir',
'/web/auto' => 'symlinks directory for assets',
'/web/lx' => 'platform autogenerated web files',
];
$newText = $text;
foreach ($map as $path => $comment) {
addGitignoreLine($path, $comment, $newText);
}
if ($newText != $text) {
$gitignore->put($newText);
}
}
function addGitignoreLine(string $path, string $comment, string &$text): void
{
$reg = '/' . addcslashes($path, './') . '\b/';
if (!preg_match($reg, $text)) {
$text .= '# ' . $comment . PHP_EOL . $path . PHP_EOL . PHP_EOL;
}
}
function genFileStructure(lx\Directory $siteDirectory): void
{
if (!$siteDirectory->contains('services')) {
$services = $siteDirectory->makeDirectory('services');
$gitkeep = $services->makeFile('.gitkeep');
$gitkeep->put('');
}
$lx = $siteDirectory->getOrMakeDirectory('lx');
$system = $lx->getOrMakeDirectory('.system');
$system->getOrMakeDirectory('temp');
if (!$lx->contains('lx')) {
require(__DIR__ . '/install-src/lxConsole.php');
/**
* @var $lxConsoleCode
*/
$lxConsole = $lx->makeFile('lx');
$lxConsole->put($lxConsoleCode);
}
$data = $lx->getOrMakeDirectory('data');
if (!$data->contains('languages.php')) {
$languages = $data->makeFile('languages.php');
$languages->put(require(__DIR__ . '/install-src/data/languages.php'));
}
$webLx = $siteDirectory->getOrMakeDirectory('web/lx');
$icon = new lx\File(__DIR__ . '/install-src/icon.png');
(new lx\File($webLx->getPath() . '/icon.png'))->copy($icon);
}
function genConfig(lx\Directory $siteDirectory): void
{
$lx = $siteDirectory->get('lx');
if ($lx->contains('config')) {
return;
}
$config = $lx->makeDirectory('config');
/**
* @var $__map__
* @var $local
* @var $common
* @var $console
* @var $web
* @var $common_components
* @var $common_diMap
* @var $common_plugin
* @var $common_service
* @var $console_components
* @var $console_commands
* @var $web_components
* @var $web_routes
*/
require(__DIR__ . '/install-src/configTpl.php');
($config->makeFile('__map__.php'))->put($__map__);
($config->makeFile('_local.example.php'))->put($local);
($config->makeFile('common.php'))->put($common);
($config->makeFile('console.php'))->put($console);
($config->makeFile('web.php'))->put($web);
$commonDir = $config->makeDirectory('common');
($commonDir->makeFile('components.php'))->put($common_components);
($commonDir->makeFile('diMap.php'))->put($common_diMap);
($commonDir->makeFile('plugin.php'))->put($common_plugin);
($commonDir->makeFile('service.php'))->put($common_service);
$consoleDir = $config->makeDirectory('console');
($consoleDir->makeFile('components.php'))->put($console_components);
($consoleDir->makeFile('commands.php'))->put($console_commands);
$webDir = $config->makeDirectory('web');
($webDir->makeFile('components.php'))->put($web_components);
($webDir->makeFile('routes.php'))->put($web_routes);
}
function refreshMaps(): void
{
(new lx\AutoloadMapBuilder())->createCommonAutoloadMap();
lx::$autoloader->map->reset();
(new lx\JsModulesActualizer())->renewHead();
//TODO module css
$compiler = new lx\AppAssetCompiler();
$compiler->compileJsCore();
$compiler->compileAppCss();
//TODO plugin css
lx\PluginAssetProvider::makePluginsAssetLinks();
}