@faros-fde-sandbox/cli 1.0.0
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/LICENSE +17 -0
- package/README.md +416 -0
- package/bin/faros +3 -0
- package/lib/commands/logs/index.d.ts +3 -0
- package/lib/commands/logs/index.d.ts.map +1 -0
- package/lib/commands/logs/index.js +162 -0
- package/lib/commands/logs/index.js.map +1 -0
- package/lib/commands/sources/index.d.ts +3 -0
- package/lib/commands/sources/index.d.ts.map +1 -0
- package/lib/commands/sources/index.js +99 -0
- package/lib/commands/sources/index.js.map +1 -0
- package/lib/commands/sync/ci-cd.d.ts +3 -0
- package/lib/commands/sync/ci-cd.d.ts.map +1 -0
- package/lib/commands/sync/ci-cd.js +188 -0
- package/lib/commands/sync/ci-cd.js.map +1 -0
- package/lib/commands/sync/index.d.ts +3 -0
- package/lib/commands/sync/index.d.ts.map +1 -0
- package/lib/commands/sync/index.js +25 -0
- package/lib/commands/sync/index.js.map +1 -0
- package/lib/commands/sync/tests.d.ts +3 -0
- package/lib/commands/sync/tests.d.ts.map +1 -0
- package/lib/commands/sync/tests.js +317 -0
- package/lib/commands/sync/tests.js.map +1 -0
- package/lib/config/loader.d.ts +5 -0
- package/lib/config/loader.d.ts.map +1 -0
- package/lib/config/loader.js +137 -0
- package/lib/config/loader.js.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +73 -0
- package/lib/index.js.map +1 -0
- package/lib/lib/api/client.d.ts +8 -0
- package/lib/lib/api/client.d.ts.map +1 -0
- package/lib/lib/api/client.js +43 -0
- package/lib/lib/api/client.js.map +1 -0
- package/lib/lib/sources/s3.d.ts +19 -0
- package/lib/lib/sources/s3.d.ts.map +1 -0
- package/lib/lib/sources/s3.js +139 -0
- package/lib/lib/sources/s3.js.map +1 -0
- package/lib/lib/ui/index.d.ts +32 -0
- package/lib/lib/ui/index.d.ts.map +1 -0
- package/lib/lib/ui/index.js +88 -0
- package/lib/lib/ui/index.js.map +1 -0
- package/lib/types/config.d.ts +160 -0
- package/lib/types/config.d.ts.map +1 -0
- package/lib/types/config.js +40 -0
- package/lib/types/config.js.map +1 -0
- package/package.json +74 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
Copyright 2024-2026 Faros AI, Inc.
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
you may not use this file except in compliance with the License.
|
|
9
|
+
You may obtain a copy of the License at
|
|
10
|
+
|
|
11
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
See the License for the specific language governing permissions and
|
|
17
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
# Faros CLI
|
|
2
|
+
|
|
3
|
+
CLI for Faros AI - sync data, manage sources, view logs.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @faros-fde-sandbox/cli
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# Sync test results
|
|
15
|
+
faros sync tests test-results/*.xml \
|
|
16
|
+
--source "Jenkins" \
|
|
17
|
+
--commit "GitHub://myorg/myrepo/abc123"
|
|
18
|
+
|
|
19
|
+
# Report build status
|
|
20
|
+
faros sync ci-cd build \
|
|
21
|
+
--status Success \
|
|
22
|
+
--commit "GitHub://myorg/myrepo/abc123" \
|
|
23
|
+
--run "Jenkins://myorg/pipeline/456"
|
|
24
|
+
|
|
25
|
+
# View logs
|
|
26
|
+
faros logs
|
|
27
|
+
|
|
28
|
+
# List configured sources
|
|
29
|
+
faros sources list
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Commands
|
|
33
|
+
|
|
34
|
+
### `faros sync`
|
|
35
|
+
|
|
36
|
+
Sync data from various sources to Faros.
|
|
37
|
+
|
|
38
|
+
#### `faros sync tests`
|
|
39
|
+
|
|
40
|
+
Sync test results (JUnit, TestNG, xUnit, Cucumber, Mocha) to Faros.
|
|
41
|
+
|
|
42
|
+
**Usage:**
|
|
43
|
+
```bash
|
|
44
|
+
faros sync tests <paths...> [options]
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**Options:**
|
|
48
|
+
- `--format <format>` - Test format (junit, testng, xunit, cucumber, mocha)
|
|
49
|
+
- `--type <type>` - Test type (Unit, Integration, Functional, etc.)
|
|
50
|
+
- `--source <source>` - Test source system (e.g. Jenkins, GitHub-Actions)
|
|
51
|
+
- `--commit <uri>` - Commit URI: `<source>://<org>/<repo>/<sha>`
|
|
52
|
+
- `--test-start <time>` - Test start time (ISO-8601, epoch millis, or "Now")
|
|
53
|
+
- `--test-end <time>` - Test end time (ISO-8601, epoch millis, or "Now")
|
|
54
|
+
- `--concurrency <number>` - Concurrent uploads (default: 8)
|
|
55
|
+
- `--validate` - Validate only, don't send (fast, offline)
|
|
56
|
+
- `--preview` - Show sample records
|
|
57
|
+
- `--dry-run` - Sync to staging graph
|
|
58
|
+
|
|
59
|
+
**Examples:**
|
|
60
|
+
|
|
61
|
+
Local files:
|
|
62
|
+
```bash
|
|
63
|
+
faros sync tests test-results/*.xml \
|
|
64
|
+
--source "Jenkins" \
|
|
65
|
+
--commit "GitHub://myorg/myrepo/abc123"
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
From S3:
|
|
69
|
+
```bash
|
|
70
|
+
faros sync tests s3://bucket/junit/ \
|
|
71
|
+
--pattern ".*\\.xml$" \
|
|
72
|
+
--s3-region us-east-1 \
|
|
73
|
+
--source "Jenkins"
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Validate before syncing:
|
|
77
|
+
```bash
|
|
78
|
+
faros sync tests *.xml --validate
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Dry run to staging:
|
|
82
|
+
```bash
|
|
83
|
+
faros sync tests *.xml --dry-run
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
#### `faros sync ci-cd`
|
|
87
|
+
|
|
88
|
+
Sync CI/CD events (builds and deployments) to Faros.
|
|
89
|
+
|
|
90
|
+
**Subcommands:**
|
|
91
|
+
- `faros sync ci-cd build` - Report build status
|
|
92
|
+
- `faros sync ci-cd deploy` - Report deployment status
|
|
93
|
+
|
|
94
|
+
**Build Example:**
|
|
95
|
+
```bash
|
|
96
|
+
faros sync ci-cd build \
|
|
97
|
+
--status Success \
|
|
98
|
+
--commit "GitHub://myorg/myrepo/abc123" \
|
|
99
|
+
--run "Jenkins://myorg/pipeline/456" \
|
|
100
|
+
--run-start-time "2024-01-15T10:00:00Z" \
|
|
101
|
+
--run-end-time "2024-01-15T10:05:00Z" \
|
|
102
|
+
--artifact "Docker://myorg/image/v1.0.0"
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**Deploy Example:**
|
|
106
|
+
```bash
|
|
107
|
+
faros sync ci-cd deploy \
|
|
108
|
+
--status Success \
|
|
109
|
+
--commit "GitHub://myorg/myrepo/abc123" \
|
|
110
|
+
--deploy "Kubernetes://myapp/Prod/deploy-789" \
|
|
111
|
+
--deploy-start-time "2024-01-15T11:00:00Z" \
|
|
112
|
+
--deploy-end-time "2024-01-15T11:03:00Z"
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### `faros sources`
|
|
116
|
+
|
|
117
|
+
Manage data sources.
|
|
118
|
+
|
|
119
|
+
**Commands:**
|
|
120
|
+
- `faros sources list` - List all configured sources
|
|
121
|
+
- `faros sources get <name>` - Get source details
|
|
122
|
+
|
|
123
|
+
**Example:**
|
|
124
|
+
```bash
|
|
125
|
+
$ faros sources list
|
|
126
|
+
|
|
127
|
+
Configured Sources:
|
|
128
|
+
|
|
129
|
+
┌────────┬────────┬────────┬────────────────────┐
|
|
130
|
+
│ Source │ Type │ Status │ Config │
|
|
131
|
+
├────────┼────────┼────────┼────────────────────┤
|
|
132
|
+
│ linear │ Linear │ ✓ │ Configured │
|
|
133
|
+
│ github │ GitHub │ ✓ │ Configured │
|
|
134
|
+
│ s3 │ S3 │ ⚠ │ Missing credentials│
|
|
135
|
+
└────────┴────────┴────────┴────────────────────┘
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### `faros logs`
|
|
139
|
+
|
|
140
|
+
View sync logs and debug information.
|
|
141
|
+
|
|
142
|
+
**Usage:**
|
|
143
|
+
```bash
|
|
144
|
+
faros logs [options]
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
**Options:**
|
|
148
|
+
- `--level <level>` - Filter by log level (info, warn, error, debug)
|
|
149
|
+
- `--since <time>` - Show logs since time (ISO-8601)
|
|
150
|
+
- `--until <time>` - Show logs until time (ISO-8601)
|
|
151
|
+
- `--out-file <path>` - Export logs to file
|
|
152
|
+
|
|
153
|
+
**Examples:**
|
|
154
|
+
```bash
|
|
155
|
+
# Recent logs
|
|
156
|
+
faros logs
|
|
157
|
+
|
|
158
|
+
# Error logs only
|
|
159
|
+
faros logs --level error
|
|
160
|
+
|
|
161
|
+
# Export logs
|
|
162
|
+
faros logs --out-file sync-logs.json
|
|
163
|
+
|
|
164
|
+
# Logs from specific time
|
|
165
|
+
faros logs --since "2024-01-15T10:00:00Z"
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Configuration
|
|
169
|
+
|
|
170
|
+
The CLI uses a two-file configuration approach:
|
|
171
|
+
|
|
172
|
+
### 1. Credentials (`.env`)
|
|
173
|
+
|
|
174
|
+
Store sensitive credentials in a `.env` file (never commit this!):
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
# Required
|
|
178
|
+
FAROS_API_KEY=your_faros_api_key_here
|
|
179
|
+
|
|
180
|
+
# Optional overrides
|
|
181
|
+
FAROS_URL=https://prod.api.faros.ai
|
|
182
|
+
FAROS_GRAPH=default
|
|
183
|
+
|
|
184
|
+
# Data source credentials
|
|
185
|
+
LINEAR_API_KEY=your_linear_api_key
|
|
186
|
+
GITHUB_TOKEN=your_github_token
|
|
187
|
+
|
|
188
|
+
# AWS credentials (for S3 test results)
|
|
189
|
+
AWS_ACCESS_KEY_ID=your_aws_access_key
|
|
190
|
+
AWS_SECRET_ACCESS_KEY=your_aws_secret_key
|
|
191
|
+
AWS_REGION=us-east-1
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
See `.env.example` for a complete template.
|
|
195
|
+
|
|
196
|
+
### 2. Configuration (`faros.config.yaml`)
|
|
197
|
+
|
|
198
|
+
Store non-sensitive configuration in `faros.config.yaml`:
|
|
199
|
+
|
|
200
|
+
```yaml
|
|
201
|
+
# Faros API configuration
|
|
202
|
+
url: https://prod.api.faros.ai
|
|
203
|
+
graph: default
|
|
204
|
+
stagingGraph: default-staging
|
|
205
|
+
origin: my-company-ci
|
|
206
|
+
|
|
207
|
+
# Data sources (credentials in .env)
|
|
208
|
+
sources:
|
|
209
|
+
linear:
|
|
210
|
+
type: Linear
|
|
211
|
+
syncInterval: 1h
|
|
212
|
+
streams:
|
|
213
|
+
- issues
|
|
214
|
+
- projects
|
|
215
|
+
- teams
|
|
216
|
+
- users
|
|
217
|
+
|
|
218
|
+
# Default values for commands
|
|
219
|
+
defaults:
|
|
220
|
+
testSource: Jenkins
|
|
221
|
+
testType: Unit
|
|
222
|
+
concurrency: 8
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
See `faros.config.example.yaml` for a complete template with detailed comments.
|
|
226
|
+
|
|
227
|
+
### Configuration Priority
|
|
228
|
+
|
|
229
|
+
Configuration is loaded in this order (highest priority first):
|
|
230
|
+
|
|
231
|
+
1. **CLI options**: `--api-key`, `--graph`, etc.
|
|
232
|
+
2. **Environment variables**: `FAROS_API_KEY`, `FAROS_GRAPH`, etc.
|
|
233
|
+
3. **Config file**: `faros.config.yaml` (or `.yml`, `.json`)
|
|
234
|
+
4. **Defaults**: Built-in defaults
|
|
235
|
+
|
|
236
|
+
**Config file search order**: `faros.config.yaml` → `faros.config.yml` → `faros.config.json` → `.farosrc.*`
|
|
237
|
+
|
|
238
|
+
## Global Options
|
|
239
|
+
|
|
240
|
+
All commands support these global options:
|
|
241
|
+
|
|
242
|
+
- `-k, --api-key <key>` - Faros API key
|
|
243
|
+
- `-u, --url <url>` - Faros API URL
|
|
244
|
+
- `-g, --graph <name>` - Faros graph name
|
|
245
|
+
- `--debug` - Enable debug logging
|
|
246
|
+
- `--quiet` - Minimal output
|
|
247
|
+
- `--json` - Output JSON (for scripting)
|
|
248
|
+
- `--no-color` - Disable colors
|
|
249
|
+
|
|
250
|
+
## Dry Run & Validation
|
|
251
|
+
|
|
252
|
+
The CLI supports three verification modes:
|
|
253
|
+
|
|
254
|
+
### 1. `--validate` (Fast, Offline)
|
|
255
|
+
|
|
256
|
+
Validate data without sending to Faros:
|
|
257
|
+
|
|
258
|
+
```bash
|
|
259
|
+
faros sync tests *.xml --validate
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
**Output:**
|
|
263
|
+
```
|
|
264
|
+
✓ Parsed 24 test suites
|
|
265
|
+
✓ All data is valid
|
|
266
|
+
|
|
267
|
+
Would create:
|
|
268
|
+
• 24 qa_TestExecution records
|
|
269
|
+
• 1,234 qa_TestCase records
|
|
270
|
+
|
|
271
|
+
Run without --validate to sync to Faros
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### 2. `--dry-run` (Full E2E, Staging Graph)
|
|
275
|
+
|
|
276
|
+
Sync to a staging graph for full verification:
|
|
277
|
+
|
|
278
|
+
```bash
|
|
279
|
+
faros sync tests *.xml --dry-run
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
**Output:**
|
|
283
|
+
```
|
|
284
|
+
⚠ Dry-run mode: syncing to staging graph 'default-staging'
|
|
285
|
+
|
|
286
|
+
Uploading |████████████████████| 100% | 24/24 suites
|
|
287
|
+
|
|
288
|
+
✓ Synced 24 test suites to staging graph
|
|
289
|
+
Graph: default-staging
|
|
290
|
+
View in Faros: https://app.faros.ai/default-staging/qa
|
|
291
|
+
|
|
292
|
+
To sync to production, run without --dry-run
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### 3. `--preview` (Sample Preview)
|
|
296
|
+
|
|
297
|
+
Show sample records that would be created:
|
|
298
|
+
|
|
299
|
+
```bash
|
|
300
|
+
faros sync tests *.xml --preview
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
**Output:**
|
|
304
|
+
```
|
|
305
|
+
✓ Parsed 24 test suites
|
|
306
|
+
|
|
307
|
+
Sample records (first 2):
|
|
308
|
+
|
|
309
|
+
qa_TestExecution:
|
|
310
|
+
{
|
|
311
|
+
"suite": "AuthTests",
|
|
312
|
+
"source": "Jenkins",
|
|
313
|
+
"status": "Success",
|
|
314
|
+
"stats": { "passed": 45, "failed": 0 }
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
Run with --dry-run to sync to staging
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
## CI/CD Integration
|
|
321
|
+
|
|
322
|
+
### GitHub Actions
|
|
323
|
+
|
|
324
|
+
```yaml
|
|
325
|
+
- name: Sync Test Results
|
|
326
|
+
if: always()
|
|
327
|
+
run: |
|
|
328
|
+
npx @faros-fde-sandbox/cli sync tests test-results/*.xml \
|
|
329
|
+
--source "GitHub-Actions" \
|
|
330
|
+
--commit "GitHub://${{ github.repository }}/${{ github.sha }}"
|
|
331
|
+
env:
|
|
332
|
+
FAROS_API_KEY: ${{ secrets.FAROS_API_KEY }}
|
|
333
|
+
|
|
334
|
+
- name: Report Build Status
|
|
335
|
+
run: |
|
|
336
|
+
npx @faros-fde-sandbox/cli sync ci-cd build \
|
|
337
|
+
--status Success \
|
|
338
|
+
--commit "GitHub://${{ github.repository }}/${{ github.sha }}" \
|
|
339
|
+
--run "GitHub-Actions://${{ github.repository }}/${{ github.run_id }}"
|
|
340
|
+
env:
|
|
341
|
+
FAROS_API_KEY: ${{ secrets.FAROS_API_KEY }}
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
### Jenkins
|
|
345
|
+
|
|
346
|
+
```groovy
|
|
347
|
+
environment {
|
|
348
|
+
FAROS_API_KEY = credentials('faros-api-key')
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
stage('Sync Results') {
|
|
352
|
+
steps {
|
|
353
|
+
sh '''
|
|
354
|
+
faros sync tests test-results/*.xml \
|
|
355
|
+
--source "Jenkins" \
|
|
356
|
+
--commit "GitHub://org/repo/${GIT_COMMIT}"
|
|
357
|
+
'''
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
## URI Formats
|
|
363
|
+
|
|
364
|
+
### Commit URI
|
|
365
|
+
`<source>://<org>/<repo>/<sha>`
|
|
366
|
+
|
|
367
|
+
Examples:
|
|
368
|
+
- `GitHub://myorg/myrepo/abc123def`
|
|
369
|
+
- `GitLab://company/project/xyz789`
|
|
370
|
+
|
|
371
|
+
### Run URI
|
|
372
|
+
`<source>://<org>/<pipeline>/<id>`
|
|
373
|
+
|
|
374
|
+
Examples:
|
|
375
|
+
- `Jenkins://myorg/pipeline/456`
|
|
376
|
+
- `GitHub-Actions://myorg/repo/12345`
|
|
377
|
+
|
|
378
|
+
### Deploy URI
|
|
379
|
+
`<source>://<app>/<env>/<id>`
|
|
380
|
+
|
|
381
|
+
Examples:
|
|
382
|
+
- `Kubernetes://myapp/Prod/deploy-789`
|
|
383
|
+
- `ECS://api-service/Staging/deploy-456`
|
|
384
|
+
|
|
385
|
+
### Artifact URI
|
|
386
|
+
`<source>://<org>/<repo>/<id>`
|
|
387
|
+
|
|
388
|
+
Examples:
|
|
389
|
+
- `Docker://myorg/image/v1.0.0`
|
|
390
|
+
- `NPM://myorg/package/2.3.4`
|
|
391
|
+
|
|
392
|
+
## Development
|
|
393
|
+
|
|
394
|
+
```bash
|
|
395
|
+
# Install dependencies
|
|
396
|
+
npm install
|
|
397
|
+
|
|
398
|
+
# Build
|
|
399
|
+
npm run build
|
|
400
|
+
|
|
401
|
+
# Watch mode
|
|
402
|
+
npm run dev
|
|
403
|
+
|
|
404
|
+
# Link for local testing
|
|
405
|
+
npm link
|
|
406
|
+
|
|
407
|
+
# Test
|
|
408
|
+
npm test
|
|
409
|
+
|
|
410
|
+
# Lint
|
|
411
|
+
npm run lint
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
## License
|
|
415
|
+
|
|
416
|
+
Apache-2.0
|
package/bin/faros
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/logs/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA0HpC,wBAAgB,WAAW,IAAI,OAAO,CA2BrC"}
|
|
@@ -0,0 +1,162 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.logsCommand = logsCommand;
|
|
40
|
+
const commander_1 = require("commander");
|
|
41
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
42
|
+
const fs = __importStar(require("fs"));
|
|
43
|
+
const path = __importStar(require("path"));
|
|
44
|
+
const os = __importStar(require("os"));
|
|
45
|
+
const ui_1 = require("../../lib/ui");
|
|
46
|
+
function getLogsDirectory() {
|
|
47
|
+
return path.join(os.homedir(), '.faros', 'logs');
|
|
48
|
+
}
|
|
49
|
+
function readLogs(options) {
|
|
50
|
+
const logsDir = getLogsDirectory();
|
|
51
|
+
if (!fs.existsSync(logsDir)) {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
const logFiles = fs.readdirSync(logsDir)
|
|
55
|
+
.filter(f => f.endsWith('.log'))
|
|
56
|
+
.sort()
|
|
57
|
+
.reverse();
|
|
58
|
+
const logs = [];
|
|
59
|
+
for (const file of logFiles.slice(0, 10)) { // Last 10 log files
|
|
60
|
+
const content = fs.readFileSync(path.join(logsDir, file), 'utf-8');
|
|
61
|
+
const lines = content.split('\n').filter(l => l.trim());
|
|
62
|
+
for (const line of lines) {
|
|
63
|
+
try {
|
|
64
|
+
const entry = JSON.parse(line);
|
|
65
|
+
logs.push({
|
|
66
|
+
timestamp: entry.time || entry.timestamp,
|
|
67
|
+
level: entry.level,
|
|
68
|
+
source: entry.source,
|
|
69
|
+
message: entry.msg || entry.message,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
// Skip invalid lines
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return logs;
|
|
78
|
+
}
|
|
79
|
+
function formatLogLevel(level) {
|
|
80
|
+
switch (level.toLowerCase()) {
|
|
81
|
+
case 'info':
|
|
82
|
+
return chalk_1.default.blue('INFO');
|
|
83
|
+
case 'warn':
|
|
84
|
+
case 'warning':
|
|
85
|
+
return chalk_1.default.yellow('WARN');
|
|
86
|
+
case 'error':
|
|
87
|
+
return chalk_1.default.red('ERROR');
|
|
88
|
+
case 'debug':
|
|
89
|
+
return chalk_1.default.dim('DEBUG');
|
|
90
|
+
default:
|
|
91
|
+
return level.toUpperCase();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async function viewLogs(options) {
|
|
95
|
+
const logs = readLogs(options);
|
|
96
|
+
if (logs.length === 0) {
|
|
97
|
+
ui_1.ui.log.info('No logs found');
|
|
98
|
+
console.log(chalk_1.default.dim('Logs are stored in: ' + getLogsDirectory()));
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
// Filter by level
|
|
102
|
+
let filteredLogs = logs;
|
|
103
|
+
if (options.level) {
|
|
104
|
+
filteredLogs = logs.filter(l => l.level === options.level);
|
|
105
|
+
}
|
|
106
|
+
// Filter by time range
|
|
107
|
+
if (options.since) {
|
|
108
|
+
const sinceTime = new Date(options.since).getTime();
|
|
109
|
+
filteredLogs = filteredLogs.filter(l => new Date(l.timestamp).getTime() >= sinceTime);
|
|
110
|
+
}
|
|
111
|
+
if (options.until) {
|
|
112
|
+
const untilTime = new Date(options.until).getTime();
|
|
113
|
+
filteredLogs = filteredLogs.filter(l => new Date(l.timestamp).getTime() <= untilTime);
|
|
114
|
+
}
|
|
115
|
+
// Output to file if requested
|
|
116
|
+
if (options.outFile) {
|
|
117
|
+
fs.writeFileSync(options.outFile, JSON.stringify(filteredLogs, null, 2));
|
|
118
|
+
ui_1.ui.log.success(`Exported ${filteredLogs.length} log entries to ${options.outFile}`);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
// Display logs
|
|
122
|
+
console.log(chalk_1.default.bold(`\nRecent Logs (${filteredLogs.length} entries):\n`));
|
|
123
|
+
const displayLogs = filteredLogs.slice(0, 100); // Limit to 100 for display
|
|
124
|
+
for (const log of displayLogs) {
|
|
125
|
+
const timestamp = new Date(log.timestamp).toLocaleString();
|
|
126
|
+
const level = formatLogLevel(log.level);
|
|
127
|
+
const source = log.source ? chalk_1.default.cyan(`[${log.source}]`) : '';
|
|
128
|
+
console.log(`${chalk_1.default.dim(timestamp)} ${level} ${source} ${log.message}`);
|
|
129
|
+
}
|
|
130
|
+
if (filteredLogs.length > 100) {
|
|
131
|
+
console.log(chalk_1.default.dim(`\n... and ${filteredLogs.length - 100} more entries`));
|
|
132
|
+
console.log(chalk_1.default.dim('Use --out-file to export all logs'));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function logsCommand() {
|
|
136
|
+
const cmd = new commander_1.Command('logs');
|
|
137
|
+
cmd
|
|
138
|
+
.description('View sync logs and debug information')
|
|
139
|
+
.option('--level <level>', 'Filter by log level (info, warn, error, debug)')
|
|
140
|
+
.option('--since <time>', 'Show logs since time (ISO-8601)')
|
|
141
|
+
.option('--until <time>', 'Show logs until time (ISO-8601)')
|
|
142
|
+
.option('--out-file <path>', 'Export logs to file')
|
|
143
|
+
.option('--follow', 'Follow logs in real-time (not yet implemented)')
|
|
144
|
+
.addHelpText('after', `
|
|
145
|
+
Examples:
|
|
146
|
+
$ faros logs
|
|
147
|
+
$ faros logs --level error
|
|
148
|
+
$ faros logs --since "2024-01-15T10:00:00Z"
|
|
149
|
+
$ faros logs --out-file sync-logs.json
|
|
150
|
+
`)
|
|
151
|
+
.action(async (options) => {
|
|
152
|
+
try {
|
|
153
|
+
await viewLogs(options);
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
ui_1.ui.log.error(error.message);
|
|
157
|
+
process.exit(1);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
return cmd;
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/logs/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0HA,kCA2BC;AArJD,yCAAoC;AACpC,kDAA0B;AAC1B,uCAAyB;AACzB,2CAA6B;AAC7B,uCAAyB;AACzB,qCAAkC;AASlC,SAAS,gBAAgB;IACvB,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;AACnD,CAAC;AAED,SAAS,QAAQ,CAAC,OAAY;IAC5B,MAAM,OAAO,GAAG,gBAAgB,EAAE,CAAC;IAEnC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,QAAQ,GAAG,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC;SACrC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;SAC/B,IAAI,EAAE;SACN,OAAO,EAAE,CAAC;IAEb,MAAM,IAA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