Skip to content

Commit

Permalink
feat(lhci-report): read report dir from lighthouse config
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepolischuk committed Oct 3, 2024
1 parent aa64a0d commit dcdf8b4
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions packages/lhci-report/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,31 @@ import * as fs from 'fs/promises'
import {formatReport} from './format'
import {getReport, type Manifest} from './report'

async function print(dir: string) {
function readConfig(dir: string) {
const configFile = path.resolve(dir, 'lighthouserc')

// eslint-disable-next-line security/detect-non-literal-require
return require(configFile)
}

async function readManifest(dir: string) {
const manifestFile = path.resolve(dir, 'manifest.json')
// eslint-disable-next-line security/detect-non-literal-fs-filename
const manifestJson = await fs.readFile(manifestFile, 'utf8')
const manifest: Manifest = JSON.parse(manifestJson)

return JSON.parse(manifestJson) as Manifest
}

async function print(dir: string) {
const manifest = await readManifest(dir)
const report = getReport(manifest)

// eslint-disable-next-line no-console
console.log(formatReport(report))
}

const [, , reportDir] = process.argv
const config = readConfig(process.cwd())
const [, , reportDir = config.ci?.upload?.outputDir] = process.argv

if (!reportDir) {
throw new Error('report dir not exists')
Expand Down

0 comments on commit dcdf8b4

Please sign in to comment.