projax 1.3.0 → 1.3.1

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,2 @@
1
+ export declare const getDatabaseManager: typeof import("projax-core").getDatabaseManager, getAllProjects: typeof import("projax-core").getAllProjects, addProject: typeof import("projax-core").addProject, removeProject: typeof import("projax-core").removeProject, scanProject: typeof import("projax-core").scanProject, scanAllProjects: typeof import("projax-core").scanAllProjects;
2
+ export type { Project, Test, ProjectPort } from 'projax-core';
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.scanAllProjects = exports.scanProject = exports.removeProject = exports.addProject = exports.getAllProjects = exports.getDatabaseManager = void 0;
37
+ const path = __importStar(require("path"));
38
+ let cachedCore = null;
39
+ function tryRequire(candidate) {
40
+ try {
41
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
42
+ return require(candidate);
43
+ }
44
+ catch (error) {
45
+ if (!(error instanceof Error) ||
46
+ !('code' in error) ||
47
+ error.code !== 'MODULE_NOT_FOUND') {
48
+ throw error;
49
+ }
50
+ return null;
51
+ }
52
+ }
53
+ function loadCore() {
54
+ if (cachedCore) {
55
+ return cachedCore;
56
+ }
57
+ const candidates = [
58
+ path.join(__dirname, 'core'),
59
+ path.join(__dirname, '..', 'core', 'dist'),
60
+ path.join(__dirname, '..', '..', 'core', 'dist'),
61
+ 'projax-core',
62
+ ];
63
+ for (const candidate of candidates) {
64
+ const mod = tryRequire(candidate);
65
+ if (mod) {
66
+ cachedCore = mod;
67
+ return mod;
68
+ }
69
+ }
70
+ throw new Error(`Unable to load projax core module. Tried locations: ${candidates.join(', ')}`);
71
+ }
72
+ const core = loadCore();
73
+ exports.getDatabaseManager = core.getDatabaseManager, exports.getAllProjects = core.getAllProjects, exports.addProject = core.addProject, exports.removeProject = core.removeProject, exports.scanProject = core.scanProject, exports.scanAllProjects = core.scanAllProjects;
package/dist/core.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare const getDatabaseManager: typeof import("projax-core").getDatabaseManager, getAllProjects: typeof import("projax-core").getAllProjects, addProject: typeof import("projax-core").addProject, removeProject: typeof import("projax-core").removeProject, scanProject: typeof import("projax-core").scanProject, scanAllProjects: typeof import("projax-core").scanAllProjects;
2
+ export type { Project, Test, ProjectPort } from 'projax-core';
package/dist/core.js ADDED
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.scanAllProjects = exports.scanProject = exports.removeProject = exports.addProject = exports.getAllProjects = exports.getDatabaseManager = void 0;
37
+ const path = __importStar(require("path"));
38
+ let cachedCore = null;
39
+ function tryRequire(candidate) {
40
+ try {
41
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
42
+ return require(candidate);
43
+ }
44
+ catch (error) {
45
+ if (!(error instanceof Error) ||
46
+ !('code' in error) ||
47
+ error.code !== 'MODULE_NOT_FOUND') {
48
+ throw error;
49
+ }
50
+ return null;
51
+ }
52
+ }
53
+ function loadCore() {
54
+ if (cachedCore) {
55
+ return cachedCore;
56
+ }
57
+ const candidates = [
58
+ // When running the published CLI (core is copied into dist/core)
59
+ path.join(__dirname, 'core'),
60
+ // When running the CLI directly from the workspace build output
61
+ path.join(__dirname, '..', 'core', 'dist'),
62
+ path.join(__dirname, '..', '..', 'core', 'dist'),
63
+ // Fallback to installed module (useful during development)
64
+ 'projax-core',
65
+ ];
66
+ for (const candidate of candidates) {
67
+ const mod = tryRequire(candidate);
68
+ if (mod) {
69
+ cachedCore = mod;
70
+ return mod;
71
+ }
72
+ }
73
+ throw new Error(`Unable to load projax core module. Tried locations: ${candidates.join(', ')}`);
74
+ }
75
+ const core = loadCore();
76
+ exports.getDatabaseManager = core.getDatabaseManager, exports.getAllProjects = core.getAllProjects, exports.addProject = core.addProject, exports.removeProject = core.removeProject, exports.scanProject = core.scanProject, exports.scanAllProjects = core.scanAllProjects;
@@ -0,0 +1,76 @@
1
+ export interface Project {
2
+ id: number;
3
+ name: string;
4
+ path: string;
5
+ framework: string | null;
6
+ last_scanned: number | null;
7
+ created_at: number;
8
+ }
9
+ export interface Test {
10
+ id: number;
11
+ project_id: number;
12
+ file_path: string;
13
+ framework: string | null;
14
+ status: string | null;
15
+ last_run: number | null;
16
+ created_at: number;
17
+ }
18
+ export interface JenkinsJob {
19
+ id: number;
20
+ project_id: number;
21
+ job_name: string;
22
+ job_url: string;
23
+ last_build_status: string | null;
24
+ last_build_number: number | null;
25
+ last_updated: number | null;
26
+ created_at: number;
27
+ }
28
+ export interface ProjectPort {
29
+ id: number;
30
+ project_id: number;
31
+ port: number;
32
+ script_name: string | null;
33
+ config_source: string;
34
+ last_detected: number;
35
+ created_at: number;
36
+ }
37
+ type ScanResponse = {
38
+ project: Project;
39
+ testsFound: number;
40
+ tests: Test[];
41
+ };
42
+ declare class DatabaseManager {
43
+ private apiBaseUrl;
44
+ private defaultPort;
45
+ constructor();
46
+ private request;
47
+ addProject(name: string, projectPath: string): Project;
48
+ getProject(id: number): Project | null;
49
+ getProjectByPath(projectPath: string): Project | null;
50
+ getAllProjects(): Project[];
51
+ updateProjectLastScanned(id: number): void;
52
+ updateProjectFramework(id: number, framework: string): void;
53
+ updateProjectName(id: number, newName: string): Project;
54
+ removeProject(id: number): void;
55
+ scanProject(id: number): ScanResponse;
56
+ scanAllProjects(): ScanResponse[];
57
+ addTest(projectId: number, filePath: string, framework?: string | null): Test;
58
+ getTest(id: number): Test | null;
59
+ getTestsByProject(projectId: number): Test[];
60
+ removeTestsByProject(projectId: number): void;
61
+ addJenkinsJob(projectId: number, jobName: string, jobUrl: string): JenkinsJob;
62
+ getJenkinsJob(id: number): JenkinsJob | null;
63
+ getJenkinsJobsByProject(projectId: number): JenkinsJob[];
64
+ addProjectPort(projectId: number, port: number, configSource: string, scriptName?: string | null): ProjectPort;
65
+ getProjectPort(id: number): ProjectPort | null;
66
+ getProjectPorts(projectId: number): ProjectPort[];
67
+ getProjectPortsByScript(projectId: number, scriptName: string): ProjectPort[];
68
+ removeProjectPorts(projectId: number): void;
69
+ updateProjectPortLastDetected(projectId: number, port: number, scriptName: string | null): void;
70
+ getSetting(key: string): string | null;
71
+ setSetting(key: string, value: string): void;
72
+ getAllSettings(): Record<string, string>;
73
+ close(): void;
74
+ }
75
+ export declare function getDatabaseManager(): DatabaseManager;
76
+ export {};
@@ -0,0 +1,240 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.getDatabaseManager = getDatabaseManager;
37
+ const path = __importStar(require("path"));
38
+ const os = __importStar(require("os"));
39
+ const fs = __importStar(require("fs"));
40
+ const child_process_1 = require("child_process");
41
+ class DatabaseManager {
42
+ apiBaseUrl;
43
+ defaultPort = 3001;
44
+ constructor() {
45
+ // Read API port from file, or use default
46
+ const dataDir = path.join(os.homedir(), '.projax');
47
+ const portFile = path.join(dataDir, 'api-port.txt');
48
+ let port = this.defaultPort;
49
+ if (fs.existsSync(portFile)) {
50
+ try {
51
+ const portStr = fs.readFileSync(portFile, 'utf-8').trim();
52
+ port = parseInt(portStr, 10) || this.defaultPort;
53
+ }
54
+ catch {
55
+ // Use default if file read fails
56
+ }
57
+ }
58
+ this.apiBaseUrl = `http://localhost:${port}/api`;
59
+ }
60
+ request(endpoint, options = {}) {
61
+ const url = `${this.apiBaseUrl}${endpoint}`;
62
+ const method = options.method || 'GET';
63
+ const body = options.body;
64
+ try {
65
+ let curlCmd;
66
+ if (method === 'GET') {
67
+ curlCmd = `curl -s -f "${url}"`;
68
+ }
69
+ else if (method === 'DELETE') {
70
+ curlCmd = `curl -s -f -X DELETE "${url}"`;
71
+ }
72
+ else {
73
+ // POST, PUT, PATCH
74
+ const tempFile = path.join(os.tmpdir(), `prx-${Date.now()}.json`);
75
+ if (body) {
76
+ fs.writeFileSync(tempFile, body);
77
+ }
78
+ curlCmd = `curl -s -f -X ${method} -H "Content-Type: application/json" ${body ? `-d @${tempFile}` : ''} "${url}"`;
79
+ }
80
+ const result = (0, child_process_1.execSync)(curlCmd, { encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe'] });
81
+ // Clean up temp file if created
82
+ if (method !== 'GET' && method !== 'DELETE' && body) {
83
+ const tempFile = path.join(os.tmpdir(), `prx-${Date.now()}.json`);
84
+ try {
85
+ fs.unlinkSync(tempFile);
86
+ }
87
+ catch {
88
+ // Ignore cleanup errors
89
+ }
90
+ }
91
+ if (!result || result.trim() === '') {
92
+ return undefined;
93
+ }
94
+ return JSON.parse(result);
95
+ }
96
+ catch (error) {
97
+ // Check if it's a 404 or other HTTP error
98
+ if (error instanceof Error && error.message.includes('404')) {
99
+ throw new Error('Resource not found');
100
+ }
101
+ throw new Error(`API request failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
102
+ }
103
+ }
104
+ // Project operations
105
+ addProject(name, projectPath) {
106
+ return this.request('/projects', {
107
+ method: 'POST',
108
+ body: JSON.stringify({ name, path: projectPath }),
109
+ });
110
+ }
111
+ getProject(id) {
112
+ try {
113
+ return this.request(`/projects/${id}`);
114
+ }
115
+ catch (error) {
116
+ if (error instanceof Error && error.message.includes('404')) {
117
+ return null;
118
+ }
119
+ throw error;
120
+ }
121
+ }
122
+ getProjectByPath(projectPath) {
123
+ const projects = this.getAllProjects();
124
+ return projects.find(p => p.path === projectPath) || null;
125
+ }
126
+ getAllProjects() {
127
+ return this.request('/projects');
128
+ }
129
+ updateProjectLastScanned(id) {
130
+ // Fire and forget - this is handled by the scan endpoint
131
+ // No need to explicitly update last_scanned
132
+ }
133
+ updateProjectFramework(id, framework) {
134
+ // This will be called during scan to update the detected framework
135
+ this.request(`/projects/${id}`, {
136
+ method: 'PUT',
137
+ body: JSON.stringify({ framework }),
138
+ });
139
+ }
140
+ updateProjectName(id, newName) {
141
+ return this.request(`/projects/${id}`, {
142
+ method: 'PUT',
143
+ body: JSON.stringify({ name: newName }),
144
+ });
145
+ }
146
+ removeProject(id) {
147
+ this.request(`/projects/${id}`, {
148
+ method: 'DELETE',
149
+ });
150
+ }
151
+ scanProject(id) {
152
+ return this.request(`/projects/${id}/scan`, {
153
+ method: 'POST',
154
+ });
155
+ }
156
+ scanAllProjects() {
157
+ return this.request('/projects/scan/all', {
158
+ method: 'POST',
159
+ });
160
+ }
161
+ // Test operations
162
+ addTest(projectId, filePath, framework = null) {
163
+ // Tests are added via scan endpoint, not directly
164
+ throw new Error('addTest should not be called directly. Use scan endpoint instead.');
165
+ }
166
+ getTest(id) {
167
+ // This endpoint doesn't exist yet
168
+ throw new Error('getTest endpoint not yet implemented in API');
169
+ }
170
+ getTestsByProject(projectId) {
171
+ return this.request(`/projects/${projectId}/tests`);
172
+ }
173
+ removeTestsByProject(projectId) {
174
+ // This is handled by the scan endpoint
175
+ // For now, we'll just call scan which removes and re-adds
176
+ throw new Error('removeTestsByProject should not be called directly. Use scan endpoint instead.');
177
+ }
178
+ // Jenkins operations
179
+ addJenkinsJob(projectId, jobName, jobUrl) {
180
+ // This endpoint doesn't exist yet
181
+ throw new Error('addJenkinsJob endpoint not yet implemented in API');
182
+ }
183
+ getJenkinsJob(id) {
184
+ // This endpoint doesn't exist yet
185
+ throw new Error('getJenkinsJob endpoint not yet implemented in API');
186
+ }
187
+ getJenkinsJobsByProject(projectId) {
188
+ // This endpoint doesn't exist yet
189
+ throw new Error('getJenkinsJobsByProject endpoint not yet implemented in API');
190
+ }
191
+ // Project port operations
192
+ addProjectPort(projectId, port, configSource, scriptName = null) {
193
+ // This endpoint doesn't exist yet
194
+ throw new Error('addProjectPort endpoint not yet implemented in API');
195
+ }
196
+ getProjectPort(id) {
197
+ // This endpoint doesn't exist yet
198
+ throw new Error('getProjectPort endpoint not yet implemented in API');
199
+ }
200
+ getProjectPorts(projectId) {
201
+ return this.request(`/projects/${projectId}/ports`);
202
+ }
203
+ getProjectPortsByScript(projectId, scriptName) {
204
+ const ports = this.getProjectPorts(projectId);
205
+ return ports.filter(p => p.script_name === scriptName);
206
+ }
207
+ removeProjectPorts(projectId) {
208
+ // This endpoint doesn't exist yet
209
+ throw new Error('removeProjectPorts endpoint not yet implemented in API');
210
+ }
211
+ updateProjectPortLastDetected(projectId, port, scriptName) {
212
+ // This endpoint doesn't exist yet - no-op for now
213
+ // Ports are updated via the scan endpoint
214
+ }
215
+ // Settings operations
216
+ getSetting(key) {
217
+ const settings = this.getAllSettings();
218
+ return settings[key] || null;
219
+ }
220
+ setSetting(key, value) {
221
+ this.request(`/settings/${encodeURIComponent(key)}`, {
222
+ method: 'PUT',
223
+ body: JSON.stringify({ value }),
224
+ });
225
+ }
226
+ getAllSettings() {
227
+ return this.request('/settings');
228
+ }
229
+ close() {
230
+ // No-op for API client
231
+ }
232
+ }
233
+ // Singleton instance
234
+ let dbManager = null;
235
+ function getDatabaseManager() {
236
+ if (!dbManager) {
237
+ dbManager = new DatabaseManager();
238
+ }
239
+ return dbManager;
240
+ }
@@ -0,0 +1,14 @@
1
+ export interface TestFramework {
2
+ name: string;
3
+ configFiles: string[];
4
+ testPatterns: RegExp[];
5
+ testDirs: string[];
6
+ }
7
+ export declare const FRAMEWORKS: TestFramework[];
8
+ export declare function detectTestFramework(projectPath: string): string | null;
9
+ export declare function isTestFile(filePath: string, detectedFramework?: string | null): boolean;
10
+ /**
11
+ * Detect the main framework/library used in a project
12
+ * Returns null if no framework is detected
13
+ */
14
+ export declare function detectProjectFramework(projectPath: string): string | null;