-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.php
193 lines (143 loc) · 4.51 KB
/
install.php
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
/*
* vast-n3 installation script
* GPL v3
*
* Developers: set dependencies & version
*
* */
$installerVersion = 'master';
// vast-n3 components
$vastComponents = ['home', 'header', 'register', 'login', 'modal', 'email', 'animation', 'introduction'];
// npm packages
$npmPackages = ['vue', 'axios', 'tailwindcss', 'postcss', 'postcss-cli', 'autoprefixer', 'postcss-import'];
// frame && user-model
$neoanComponents = [
'vast-n3/vastn3' => ['frame'],
'neoan3-model/user' => ['model']
];
// _template files
foreach (['ce.html', 'ce.js', 'route.php', 'ce.php'] as $file) {
$placedFiles[] = [
'src' => 'https://raw.githubusercontent.com/vast-n3/start/' . $installerVersion . '/templates/' . $file,
'target' => '_template/' . $file
];
}
/**
* --------------- End of setup part ----------------
* */
foreach ($vastComponents as $vastComponent) {
$neoanComponents['vast-n3/' . $vastComponent] = ['component'];
// $neoanComponents['vast-n3/' . $vastComponent] = ['component' , 'https://github.com/vast-n3/component-' . $vastComponent . '.git'];
}
foreach (['package.json', 'postcss.config.js', 'tailwind.config.js', 'setup.php'] as $file) {
$placedFiles[] = [
'src' => 'https://raw.githubusercontent.com/vast-n3/start/' . $installerVersion . '/configs/' . $file,
'target' => $file
];
}
$iv3 = new InstallVastn3();
// availability npm & neoan3
echo "NPM check: ";
$npmAvailable = $iv3->io('npm -v', "npm is either not installed or not available to the PHP user.\n");
$fatal = "neoan3-cli is not available to PHP. Please check PATH & permissions!";
if (!$iv3->io('neoan3 -v', $fatal)) {
exit(1);
}
/**
* Installations
* */
// add files
$iv3->writeFiles($placedFiles);
// set home
$iv3->setDefaultRoute('home');
// install dependencies
echo "Installing dependencies...\n";
foreach ($neoanComponents as $name => $typeLocation) {
$execStr = 'neoan3 add ' . $typeLocation[0] . ' ' . $name . (isset($typeLocation[1]) ? ' ' . $typeLocation[1] : '');
echo "Retrieving " . $typeLocation[0] . " " . $name . "\n";
$iv3->io($execStr);
}
// install npm dependencies
foreach ($npmPackages as $package) {
echo "\ninstalling " . $package . "\n";
$iv3->io('npm install ' . $package);
}
// compile css
echo "Compiling ...\n";
$iv3->io('npm run build');
// fund us:
// bobby's awesome fundme page
// done
echo "
*************************************************************
*
* Installation complete
*
* IMPORTANT: The file 'setup.php' should never be deployed.
* Run 'php setup.php' now and delete the file afterwards.
* You can always create/edit your credentials with 'neoan3 credentials'
*
* Leave us a star at https://github.com/vast-n3/vastn3
*
* If you are in a directory outside your local host, you can develop using the command:
* 'php -S localhost:8080 _neoan/server.php'
*
**************************************************************
";
/**
* Installation class
*/
class InstallVastn3
{
private $output;
function __construct()
{
$this->output = [];
}
function clearOutput()
{
$this->output = [];
}
function printOutput()
{
foreach ($this->output as $line) {
echo $line . "\n";
}
$this->clearOutput();
}
function writeFiles($fileArray)
{
foreach ($fileArray as $file) {
$folder = explode('/', $file['target']);
array_pop($folder);
$folder = (count($folder) > 0 ? implode('/', $folder) : '/');
if (!is_dir($folder)) {
mkdir($folder, 0777, true);
}
try {
$content = file_get_contents($file['src']);
file_put_contents($file['target'], $content);
} catch (Exception $e) {
echo "\n" . $file['src'] . " not found.\n";
}
}
}
function setDefaultRoute($component)
{
$default = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'default.php');
$newContent = preg_replace('/\'default_ctrl\',[\w\']+\)/', "'default_ctrl', '$component')", $default);
file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . 'default.php', $newContent);
}
function io($execString, $warning = "Warning: Command did not return\n")
{
exec($execString, $this->output, $return);
if (empty($this->output)) {
$this->clearOutput();
echo $warning;
return false;
}
$this->printOutput();
return true;
}
}