Skip to content

Commit

Permalink
Fix: error date in output files
Browse files Browse the repository at this point in the history
  • Loading branch information
hrenaud committed Dec 7, 2023
1 parent a008860 commit 9dc335a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lighthouse-plugin-ecoindex/cli/cli-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function getFlags(manualArgv, options = {}) {
cliFlags['listAllAudits'] = false

// Save results as reports.
cliFlags['generationDate'] = new Date().toISOString().replaceAll(':', '_')
cliFlags['generationDate'] = new Date().toISOString()

// Prepare statements reports name
// if (!cliFlags['input-report']) {
Expand Down
9 changes: 9 additions & 0 deletions lighthouse-plugin-ecoindex/cli/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as constants from 'lighthouse/core/config/constants.js'

import _slugify from 'slugify'
import fs from 'fs'
import { isDate } from 'util/types'
import logSymbols from 'log-symbols'
import path from 'path'

Expand Down Expand Up @@ -33,6 +34,13 @@ async function listAudits() {
// process.exit(0)
}

async function dateToFileString(date) {
if (isDate(date)) {
return date.toISOString().replace(/:/g, '-')
}
return date.replace(/:/g, '-')
}

/**
* Read en config JSON file
* @param {*} cliFlags
Expand Down Expand Up @@ -232,6 +240,7 @@ const slugify = children => {
}

export {
dateToFileString,
endEcoindexPageMesure,
getEnvStatementsObj,
getLighthouseConfig,
Expand Down
6 changes: 4 additions & 2 deletions lighthouse-plugin-ecoindex/cli/printer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { dateToFileString, getEnvStatementsObj, slugify } from './commands.js'
import fs, { writeFileSync } from 'fs'
import { getEnvStatementsObj, slugify } from './commands.js'
import path, { dirname } from 'path'

import Handlebars from 'handlebars'
Expand Down Expand Up @@ -28,7 +28,9 @@ Handlebars.registerHelper('ifEquals', function (arg1, arg2, options) {
*/
async function preparareReports(cliFlags, course = undefined) {
// Create the output folder if it doesn't exist.
let exportPath = `${cliFlags['output-path']}/${cliFlags['generationDate']}`
let exportPath = `${cliFlags['output-path']}/${await dateToFileString(
cliFlags['generationDate'],
)}`

if (course) {
await fs.mkdirSync(`${exportPath}/statements`, {
Expand Down

0 comments on commit 9dc335a

Please sign in to comment.