diff --git a/lighthouse-plugin-ecoindex/cli/cli-flags.js b/lighthouse-plugin-ecoindex/cli/cli-flags.js index def80cd0..d9ca980d 100644 --- a/lighthouse-plugin-ecoindex/cli/cli-flags.js +++ b/lighthouse-plugin-ecoindex/cli/cli-flags.js @@ -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']) { diff --git a/lighthouse-plugin-ecoindex/cli/commands.js b/lighthouse-plugin-ecoindex/cli/commands.js index 23c6fc27..a1126f40 100644 --- a/lighthouse-plugin-ecoindex/cli/commands.js +++ b/lighthouse-plugin-ecoindex/cli/commands.js @@ -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' @@ -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 @@ -232,6 +240,7 @@ const slugify = children => { } export { + dateToFileString, endEcoindexPageMesure, getEnvStatementsObj, getLighthouseConfig, diff --git a/lighthouse-plugin-ecoindex/cli/printer.js b/lighthouse-plugin-ecoindex/cli/printer.js index 8a9e501a..b9c65035 100644 --- a/lighthouse-plugin-ecoindex/cli/printer.js +++ b/lighthouse-plugin-ecoindex/cli/printer.js @@ -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' @@ -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`, {