viewgate-wrapper 1.3.2 → 1.3.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/dist/cli.js ADDED
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env node
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ import os from 'os';
5
+ import { fileURLToPath } from 'url';
6
+ const __filename = fileURLToPath(import.meta.url);
7
+ const __dirname = path.dirname(__filename);
8
+ async function setup() {
9
+ console.log('šŸš€ Setting up ViewGate MCP Server...');
10
+ // 1. Locate mcp_config.json
11
+ const configDir = path.join(os.homedir(), '.gemini', 'antigravity');
12
+ const configPath = path.join(configDir, 'mcp_config.json');
13
+ if (!fs.existsSync(configPath)) {
14
+ console.error(`āŒ Could not find mcp_config.json at ${configPath}`);
15
+ process.exit(1);
16
+ }
17
+ // 2. Determine the path to the MCP server
18
+ // In production (node_modules), we'll be in dist/cli.js, so mcp-server is at ../mcp-server
19
+ // During local dev, it might be different.
20
+ let mcpServerPath = '';
21
+ // Check if we are running from node_modules or local dev
22
+ const isLocalDev = __dirname.includes('view-gate-wrapper' + path.sep + 'src') || __dirname.includes('view-gate-wrapper' + path.sep + 'dist');
23
+ if (isLocalDev) {
24
+ // Find the root of the project
25
+ let root = __dirname;
26
+ while (root !== path.parse(root).root && !fs.existsSync(path.join(root, 'package.json'))) {
27
+ root = path.dirname(root);
28
+ }
29
+ mcpServerPath = path.join(root, 'mcp-server', 'dist', 'index.js');
30
+ }
31
+ else {
32
+ // In node_modules, we expect to be in something like node_modules/viewgate-wrapper/dist
33
+ mcpServerPath = path.join(__dirname, '..', 'mcp-server', 'dist', 'index.js');
34
+ }
35
+ // Normalize to forward slashes for the JSON config (cleaner on Windows)
36
+ const normalizedMcpPath = mcpServerPath.replace(/\\/g, '/');
37
+ if (!fs.existsSync(mcpServerPath)) {
38
+ console.error(`āŒ MCP Server not found at: ${mcpServerPath}`);
39
+ console.log('Please ensure you have built the project: npm run build');
40
+ process.exit(1);
41
+ }
42
+ // 3. Read and update mcp_config.json
43
+ try {
44
+ const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
45
+ if (!config.mcpServers) {
46
+ config.mcpServers = {};
47
+ }
48
+ const currentServer = config.mcpServers.viewgate || {};
49
+ const env = currentServer.env || {};
50
+ // Default values if not present
51
+ const backendUrl = env.BACKEND_URL || 'https://view-gate.vercel.app';
52
+ const apiKey = env.API_KEY || 'YOUR_API_KEY_HERE';
53
+ config.mcpServers.viewgate = {
54
+ command: 'node',
55
+ args: [normalizedMcpPath],
56
+ env: {
57
+ BACKEND_URL: backendUrl,
58
+ API_KEY: apiKey
59
+ }
60
+ };
61
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
62
+ console.log(`āœ… Updated mcp_config.json successfully!`);
63
+ console.log(`šŸ“ MCP Path: ${normalizedMcpPath}`);
64
+ if (apiKey === 'YOUR_API_KEY_HERE') {
65
+ console.log('\nāš ļø Remember to set your API_KEY in:');
66
+ console.log(` ${configPath}`);
67
+ }
68
+ }
69
+ catch (error) {
70
+ console.error(`āŒ Error updating configuration: ${error.message}`);
71
+ process.exit(1);
72
+ }
73
+ }
74
+ setup();
@@ -0,0 +1,11 @@
1
+ import { transformSourcePaths } from './transform-logic.js';
2
+ export default function viewgateNextLoader(source) {
3
+ const id = this.resourcePath;
4
+ if (!id)
5
+ return source;
6
+ // Debug log to ensure loader is running
7
+ if (process.env.NODE_ENV === 'development') {
8
+ // console.log(`[ViewGate] Transforming: ${id}`);
9
+ }
10
+ return transformSourcePaths(source, id, process.cwd());
11
+ }
@@ -0,0 +1,20 @@
1
+ export function transformSourcePaths(code, id, cwd) {
2
+ if (!id.endsWith('.tsx') && !id.endsWith('.jsx'))
3
+ return code;
4
+ if (id.includes('node_modules'))
5
+ return code;
6
+ const normalizePath = (p) => p.replace(/\\/g, '/');
7
+ const relativePath = normalizePath(id).replace(normalizePath(cwd), '');
8
+ const lines = code.split('\n');
9
+ const transformedLines = lines.map((line, index) => {
10
+ const lineNumber = index + 1;
11
+ // Regex to find JSX tags and inject data-source-path (handles self-closing tags)
12
+ return line.replace(/(^|[^a-zA-Z0-9])<([a-zA-Z][a-zA-Z0-9\.]*)(?=[ \t\n\/\>])/g, (match, prefix, tagName) => {
13
+ if (match.includes('data-source-path') || tagName === 'Fragment' || tagName === 'React.Fragment') {
14
+ return match;
15
+ }
16
+ return `${prefix}<${tagName} data-source-path="${relativePath}:${lineNumber}"`;
17
+ });
18
+ });
19
+ return transformedLines.join('\n');
20
+ }
@@ -0,0 +1,14 @@
1
+ import { transformSourcePaths } from './transform-logic.js';
2
+ export default function viewgatePlugin() {
3
+ return {
4
+ name: 'vite-plugin-viewgate',
5
+ enforce: 'pre',
6
+ transform(code, id) {
7
+ const transformedCode = transformSourcePaths(code, id, process.cwd());
8
+ return {
9
+ code: transformedCode,
10
+ map: null
11
+ };
12
+ }
13
+ };
14
+ }