cluso-inspector 1.0.2 → 1.0.3

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.
@@ -0,0 +1,122 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * cluso-inspector CLI
5
+ *
6
+ * Usage:
7
+ * cluso-inspector <url> [language]
8
+ *
9
+ * Examples:
10
+ * cluso-inspector https://github.com
11
+ * cluso-inspector https://github.com typescript
12
+ * npx cluso-inspector https://example.com javascript
13
+ */
14
+
15
+ const { spawn } = require('child_process');
16
+ const path = require('path');
17
+ const fs = require('fs');
18
+
19
+ // Parse CLI arguments
20
+ const args = process.argv.slice(2);
21
+
22
+ if (args.length === 0 || args.includes('--help') || args.includes('-h')) {
23
+ console.log(`
24
+ cluso-inspector - Visual element selector for web components
25
+
26
+ Usage:
27
+ cluso-inspector <url> [language]
28
+
29
+ Arguments:
30
+ url - The URL to open and extract from (required)
31
+ language - Target language: typescript or javascript (default: typescript)
32
+
33
+ Examples:
34
+ cluso-inspector https://github.com
35
+ cluso-inspector https://github.com typescript
36
+ npx cluso-inspector https://example.com javascript
37
+
38
+ Output:
39
+ Outputs JSON to stdout with: { screenshot, html, selector, dimensions, ... }
40
+ `);
41
+ process.exit(args.includes('--help') || args.includes('-h') ? 0 : 1);
42
+ }
43
+
44
+ const url = args[0];
45
+ const language = args[1] || 'typescript';
46
+
47
+ // Validate URL
48
+ try {
49
+ new URL(url);
50
+ } catch (error) {
51
+ console.error('Error: Invalid URL:', url);
52
+ process.exit(1);
53
+ }
54
+
55
+ // Validate language
56
+ if (!['typescript', 'javascript'].includes(language)) {
57
+ console.error('Error: Language must be "typescript" or "javascript"');
58
+ process.exit(1);
59
+ }
60
+
61
+ // Create temp file for output (Electron will write here, we'll read and output to stdout)
62
+ const tmpFile = `/tmp/cluso-inspector-${process.pid}.json`;
63
+
64
+ // Path to Electron app
65
+ const electronPath = require('electron');
66
+ const mainPath = path.join(__dirname, '..', 'main.js');
67
+
68
+ // Launch Electron
69
+ const electron = spawn(electronPath, [mainPath, url, tmpFile, language], {
70
+ stdio: ['inherit', 'pipe', 'pipe']
71
+ });
72
+
73
+ // Capture electron stdout/stderr (for debugging)
74
+ electron.stdout.on('data', (data) => {
75
+ // Log to stderr so it doesn't interfere with JSON output
76
+ process.stderr.write(`[cluso-inspector] ${data}`);
77
+ });
78
+
79
+ electron.stderr.on('data', (data) => {
80
+ process.stderr.write(`[cluso-inspector] ${data}`);
81
+ });
82
+
83
+ // When Electron exits
84
+ electron.on('close', (code) => {
85
+ if (code === 0) {
86
+ // Read the temp file and output to stdout
87
+ if (fs.existsSync(tmpFile)) {
88
+ const data = fs.readFileSync(tmpFile, 'utf8');
89
+ console.log(data); // Output JSON to stdout
90
+
91
+ // Clean up temp file
92
+ try {
93
+ fs.unlinkSync(tmpFile);
94
+ } catch (e) {
95
+ // Ignore cleanup errors
96
+ }
97
+
98
+ process.exit(0);
99
+ } else {
100
+ console.error('Error: Extraction data not found');
101
+ process.exit(1);
102
+ }
103
+ } else if (code === 1) {
104
+ // User cancelled
105
+ console.error('Extraction cancelled');
106
+ process.exit(1);
107
+ } else {
108
+ console.error('Error: Electron process failed with code', code);
109
+ process.exit(code || 1);
110
+ }
111
+ });
112
+
113
+ // Handle signals
114
+ process.on('SIGINT', () => {
115
+ electron.kill('SIGINT');
116
+ process.exit(1);
117
+ });
118
+
119
+ process.on('SIGTERM', () => {
120
+ electron.kill('SIGTERM');
121
+ process.exit(1);
122
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cluso-inspector",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Visual element selector for extracting HTML and screenshots from websites",
5
5
  "main": "main.js",
6
6
  "bin": {