lwazi 1.2.2 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/uninstall.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const { execSync
|
|
3
|
+
const { execSync } = require('child_process');
|
|
4
4
|
const fs = require('fs');
|
|
5
5
|
const path = require('path');
|
|
6
6
|
|
|
@@ -50,28 +50,45 @@ console.log();
|
|
|
50
50
|
|
|
51
51
|
// Run the appropriate uninstallation script
|
|
52
52
|
const platform = process.platform;
|
|
53
|
+
const scriptPath = platform === 'win32'
|
|
54
|
+
? (fs.existsSync(path.join(lwaziDir, 'uninstall.ps1')) ? path.join(lwaziDir, 'uninstall.ps1') : path.join(lwaziDir, 'uninstall.bat'))
|
|
55
|
+
: path.join(lwaziDir, 'uninstall');
|
|
56
|
+
|
|
57
|
+
if (!fs.existsSync(scriptPath)) {
|
|
58
|
+
console.log(colors.yellow('⚠️ No uninstall script found in lwazi directory.'));
|
|
59
|
+
console.log('Attempting manual cleanup...');
|
|
60
|
+
manualCleanup();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
53
63
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
64
|
+
// Make executable on Unix
|
|
65
|
+
if (platform !== 'win32') {
|
|
66
|
+
fs.chmodSync(scriptPath, '755');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
console.log(colors.blue('Running uninstallation script...'));
|
|
70
|
+
console.log();
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
const cmd = platform === 'win32'
|
|
74
|
+
? `powershell -ExecutionPolicy Bypass -File "${scriptPath}"`
|
|
75
|
+
: `"${scriptPath}"`;
|
|
76
|
+
|
|
77
|
+
execSync(cmd, {
|
|
78
|
+
stdio: 'inherit',
|
|
79
|
+
cwd: projectRoot
|
|
80
|
+
});
|
|
81
|
+
console.log();
|
|
82
|
+
console.log(colors.green('✅ Uninstallation completed!'));
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if (error.status === 1) {
|
|
85
|
+
console.log();
|
|
86
|
+
console.log(colors.yellow('⚠️ Uninstallation cancelled by user.'));
|
|
87
|
+
} else {
|
|
88
|
+
console.log();
|
|
89
|
+
console.log(colors.yellow('⚠️ Uninstallation script finished with warnings.'));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
75
92
|
} else {
|
|
76
93
|
// Unix-like systems (Linux, macOS, etc.)
|
|
77
94
|
scriptPath = path.join(lwaziDir, 'uninstall');
|
|
@@ -85,45 +102,29 @@ async function runUninstall() {
|
|
|
85
102
|
|
|
86
103
|
// Make executable
|
|
87
104
|
fs.chmodSync(scriptPath, '755');
|
|
88
|
-
scriptCommand = `"${scriptPath}"`;
|
|
89
105
|
}
|
|
90
106
|
|
|
91
107
|
console.log(colors.blue('Running uninstallation script...'));
|
|
92
108
|
console.log();
|
|
93
109
|
|
|
94
110
|
try {
|
|
95
|
-
|
|
111
|
+
execSync(`"${scriptPath}"`, {
|
|
96
112
|
stdio: 'inherit',
|
|
97
|
-
cwd: projectRoot
|
|
98
|
-
shell: platform === 'win32'
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
return new Promise((resolve, reject) => {
|
|
102
|
-
child.on('close', (code) => {
|
|
103
|
-
if (code === 0) {
|
|
104
|
-
console.log();
|
|
105
|
-
console.log(colors.green('✅ Uninstallation completed!'));
|
|
106
|
-
resolve();
|
|
107
|
-
} else {
|
|
108
|
-
console.log();
|
|
109
|
-
console.log(colors.yellow('⚠️ Uninstallation script finished with warnings.'));
|
|
110
|
-
resolve();
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
child.on('error', (err) => {
|
|
115
|
-
console.log(colors.red('❌ Error running uninstall script:'), err.message);
|
|
116
|
-
reject(err);
|
|
117
|
-
});
|
|
113
|
+
cwd: projectRoot
|
|
118
114
|
});
|
|
115
|
+
console.log();
|
|
116
|
+
console.log(colors.green('✅ Uninstallation completed!'));
|
|
119
117
|
} catch (error) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
118
|
+
if (error.status === 1) {
|
|
119
|
+
console.log();
|
|
120
|
+
console.log(colors.yellow('⚠️ Uninstallation cancelled by user.'));
|
|
121
|
+
} else {
|
|
122
|
+
console.log();
|
|
123
|
+
console.log(colors.yellow('⚠️ Uninstallation script finished with warnings.'));
|
|
124
|
+
}
|
|
123
125
|
}
|
|
124
|
-
}
|
|
125
126
|
|
|
126
|
-
|
|
127
|
+
function manualCleanup() {
|
|
127
128
|
console.log(colors.blue('Performing manual cleanup...'));
|
|
128
129
|
console.log();
|
|
129
130
|
|
|
@@ -190,9 +191,3 @@ async function manualCleanup() {
|
|
|
190
191
|
console.log();
|
|
191
192
|
console.log(colors.green('✅ Manual cleanup completed!'));
|
|
192
193
|
}
|
|
193
|
-
|
|
194
|
-
// Run the uninstaller
|
|
195
|
-
runUninstall().catch((error) => {
|
|
196
|
-
console.error(colors.red('❌ Uninstallation failed:'), error.message);
|
|
197
|
-
process.exit(1);
|
|
198
|
-
});
|
package/package.json
CHANGED
|
@@ -4,6 +4,7 @@ namespace Lwazi\Core\Console;
|
|
|
4
4
|
|
|
5
5
|
use Illuminate\Console\Command;
|
|
6
6
|
use Lwazi\Core\Installer\NavigationCrawler;
|
|
7
|
+
use Lwazi\Core\Services\GraphVisualizer;
|
|
7
8
|
use Illuminate\Support\Facades\Storage;
|
|
8
9
|
|
|
9
10
|
class AnalyzeProjectCommand extends Command
|
|
@@ -36,6 +37,17 @@ class AnalyzeProjectCommand extends Command
|
|
|
36
37
|
$this->info("Analysis complete. Manifest stored at: {$manifestFile}");
|
|
37
38
|
$this->info("Pages discovered: " . count($manifest['nodes']));
|
|
38
39
|
|
|
40
|
+
$this->info("\n" . str_repeat('=', 50));
|
|
41
|
+
$this->info('SITE NAVIGATION GRAPH');
|
|
42
|
+
$this->info(str_repeat('=', 50));
|
|
43
|
+
|
|
44
|
+
$visualizer = new GraphVisualizer();
|
|
45
|
+
$graphOutput = $visualizer->generateAsciiGraph($manifest);
|
|
46
|
+
$this->line($graphOutput);
|
|
47
|
+
|
|
48
|
+
$summaryOutput = $visualizer->generateSummary($manifest);
|
|
49
|
+
$this->line($summaryOutput);
|
|
50
|
+
|
|
39
51
|
return 0;
|
|
40
52
|
}
|
|
41
53
|
}
|
|
@@ -6,6 +6,7 @@ use Illuminate\Console\Command;
|
|
|
6
6
|
use Illuminate\Support\Facades\Artisan;
|
|
7
7
|
use Lwazi\Core\Installer\ProjectAnalyzer;
|
|
8
8
|
use Lwazi\Core\Installer\NavigationCrawler;
|
|
9
|
+
use Lwazi\Core\Services\GraphVisualizer;
|
|
9
10
|
|
|
10
11
|
class SetupCommand extends Command
|
|
11
12
|
{
|
|
@@ -111,7 +112,19 @@ class SetupCommand extends Command
|
|
|
111
112
|
$crawler = new NavigationCrawler($url, true);
|
|
112
113
|
$manifest = $crawler->crawl();
|
|
113
114
|
$crawler->saveManifest();
|
|
115
|
+
|
|
114
116
|
$this->info("Crawled " . count($manifest['nodes']) . " pages.");
|
|
117
|
+
|
|
118
|
+
$this->info("\n" . str_repeat('=', 50));
|
|
119
|
+
$this->info('SITE NAVIGATION GRAPH');
|
|
120
|
+
$this->info(str_repeat('=', 50));
|
|
121
|
+
|
|
122
|
+
$visualizer = new GraphVisualizer();
|
|
123
|
+
$graphOutput = $visualizer->generateAsciiGraph($manifest);
|
|
124
|
+
$this->line($graphOutput);
|
|
125
|
+
|
|
126
|
+
$summaryOutput = $visualizer->generateSummary($manifest);
|
|
127
|
+
$this->line($summaryOutput);
|
|
115
128
|
} catch (\Throwable $e) {
|
|
116
129
|
$this->warn('Website crawling failed: ' . $e->getMessage());
|
|
117
130
|
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Lwazi\Core\Services;
|
|
4
|
+
|
|
5
|
+
class GraphVisualizer
|
|
6
|
+
{
|
|
7
|
+
public function generateAsciiGraph(array $manifest, int $maxDepth = 3, int $maxChildren = 8): string
|
|
8
|
+
{
|
|
9
|
+
$adjacency = $manifest['adjacency'] ?? [];
|
|
10
|
+
$nodes = $manifest['nodes'] ?? [];
|
|
11
|
+
$rootUrl = $manifest['root_url'] ?? '';
|
|
12
|
+
|
|
13
|
+
if (empty($adjacency)) {
|
|
14
|
+
return "No graph data available.\n";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
$root = $this->normalizeRoot($rootUrl);
|
|
18
|
+
$visited = [];
|
|
19
|
+
$output = "SITE NAVIGATION GRAPH\n";
|
|
20
|
+
$output .= str_repeat('=', 50) . "\n\n";
|
|
21
|
+
$output .= "Root: {$root}\n";
|
|
22
|
+
$output .= "Total pages: " . count($nodes) . "\n";
|
|
23
|
+
$output .= "Total links: " . array_sum(array_map('count', $adjacency)) . "\n";
|
|
24
|
+
$output .= "\n" . str_repeat('-', 50) . "\n\n";
|
|
25
|
+
|
|
26
|
+
$output .= $this->buildTreeAscii($adjacency, $root, 0, $maxDepth, $maxChildren, $visited);
|
|
27
|
+
|
|
28
|
+
return $output;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
protected function normalizeRoot(string $url): string
|
|
32
|
+
{
|
|
33
|
+
$parts = parse_url($url);
|
|
34
|
+
return ($parts['scheme'] ?? 'http') . '://' . ($parts['host'] ?? $url);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
protected function buildTreeAscii(
|
|
38
|
+
array $adjacency,
|
|
39
|
+
string $current,
|
|
40
|
+
int $depth,
|
|
41
|
+
int $maxDepth,
|
|
42
|
+
int $maxChildren,
|
|
43
|
+
array &$visited
|
|
44
|
+
): string {
|
|
45
|
+
if ($depth > $maxDepth) {
|
|
46
|
+
return '';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (isset($visited[$current])) {
|
|
50
|
+
return " [loop back]\n";
|
|
51
|
+
}
|
|
52
|
+
$visited[$current] = true;
|
|
53
|
+
|
|
54
|
+
$label = $this->getPageLabel($current);
|
|
55
|
+
$indent = str_repeat(' ', $depth);
|
|
56
|
+
$prefix = $depth === 0 ? '●' : '├';
|
|
57
|
+
$output = "{$indent}{$prefix} {$label}\n";
|
|
58
|
+
|
|
59
|
+
$children = $adjacency[$current] ?? [];
|
|
60
|
+
$childCount = count($children);
|
|
61
|
+
|
|
62
|
+
if ($childCount === 0) {
|
|
63
|
+
return $output;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
$displayChildren = array_slice($children, 0, $maxChildren);
|
|
67
|
+
$hasMore = $childCount > $maxChildren;
|
|
68
|
+
|
|
69
|
+
foreach ($displayChildren as $i => $child) {
|
|
70
|
+
$isLast = ($i === count($displayChildren) - 1) && !$hasMore;
|
|
71
|
+
$childIndent = str_repeat(' ', $depth + 1);
|
|
72
|
+
$childPrefix = $isLast ? '└' : '├';
|
|
73
|
+
|
|
74
|
+
$childLabel = $this->getPageLabel($child);
|
|
75
|
+
$output .= "{$childIndent}{$childPrefix}─ {$childLabel}\n";
|
|
76
|
+
|
|
77
|
+
if ($depth < $maxDepth) {
|
|
78
|
+
$output .= $this->buildTreeAscii(
|
|
79
|
+
$adjacency,
|
|
80
|
+
$child,
|
|
81
|
+
$depth + 1,
|
|
82
|
+
$maxDepth,
|
|
83
|
+
$maxChildren,
|
|
84
|
+
$visited
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if ($hasMore) {
|
|
90
|
+
$moreIndent = str_repeat(' ', $depth + 1);
|
|
91
|
+
$output .= "{$moreIndent}└─ ... (+" . ($childCount - $maxChildren) . " more)\n";
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return $output;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
protected function getPageLabel(string $url): string
|
|
98
|
+
{
|
|
99
|
+
$path = parse_url($url, PHP_URL_PATH) ?? '/';
|
|
100
|
+
$path = rtrim($path, '/');
|
|
101
|
+
|
|
102
|
+
if ($path === '' || $path === '/') {
|
|
103
|
+
return '/ (home)';
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
$segments = explode('/', trim($path, '/'));
|
|
107
|
+
$last = end($segments) ?: basename($path);
|
|
108
|
+
|
|
109
|
+
if (strlen($last) > 25) {
|
|
110
|
+
$last = substr($last, 0, 22) . '...';
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return '/' . $last;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
public function generateSummary(array $manifest): string
|
|
117
|
+
{
|
|
118
|
+
$adjacency = $manifest['adjacency'] ?? [];
|
|
119
|
+
$nodes = $manifest['nodes'] ?? [];
|
|
120
|
+
|
|
121
|
+
$totalPages = count($nodes);
|
|
122
|
+
$totalLinks = array_sum(array_map('count', $adjacency));
|
|
123
|
+
|
|
124
|
+
$depths = [];
|
|
125
|
+
$this->calculateDepths($adjacency, $this->normalizeRoot($manifest['root_url'] ?? ''), 0, $depths);
|
|
126
|
+
$maxDepth = empty($depths) ? 0 : max($depths);
|
|
127
|
+
|
|
128
|
+
$outdegree = array_map('count', $adjacency);
|
|
129
|
+
$avgLinks = $totalPages > 0 ? round($totalLinks / $totalPages, 1) : 0;
|
|
130
|
+
$maxLinks = empty($outdegree) ? 0 : max($outdegree);
|
|
131
|
+
|
|
132
|
+
$output = "GRAPH SUMMARY\n";
|
|
133
|
+
$output .= str_repeat('=', 40) . "\n";
|
|
134
|
+
$output .= "Pages: {$totalPages}\n";
|
|
135
|
+
$output .= "Links: {$totalLinks}\n";
|
|
136
|
+
$output .= "Avg links: {$avgLinks} per page\n";
|
|
137
|
+
$output .= "Max depth: {$maxDepth}\n";
|
|
138
|
+
$output .= "Max links: {$maxLinks} from one page\n";
|
|
139
|
+
|
|
140
|
+
return $output;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
protected function calculateDepths(array $adjacency, string $current, int $depth, array &$depths): void
|
|
144
|
+
{
|
|
145
|
+
$depths[] = $depth;
|
|
146
|
+
|
|
147
|
+
foreach ($adjacency[$current] ?? [] as $child) {
|
|
148
|
+
$this->calculateDepths($adjacency, $child, $depth + 1, $depths);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
public function generateLinkList(array $manifest, int $limit = 20): string
|
|
153
|
+
{
|
|
154
|
+
$adjacency = $manifest['adjacency'] ?? [];
|
|
155
|
+
|
|
156
|
+
$output = "TOP LINK CONNECTIONS\n";
|
|
157
|
+
$output .= str_repeat('=', 40) . "\n";
|
|
158
|
+
|
|
159
|
+
$outdegree = [];
|
|
160
|
+
foreach ($adjacency as $from => $links) {
|
|
161
|
+
$outdegree[$from] = count($links);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
arsort($outdegree);
|
|
165
|
+
$top = array_slice($outdegree, 0, $limit, true);
|
|
166
|
+
|
|
167
|
+
foreach ($top as $url => $count) {
|
|
168
|
+
$label = $this->getPageLabel($url);
|
|
169
|
+
$output .= sprintf(" %-30s → %d links\n", $label, $count);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return $output;
|
|
173
|
+
}
|
|
174
|
+
}
|