Remove unecessary async function

pull/2413/head
Jérémy Rialland 2022-11-24 16:29:50 +01:00 committed by Jérémy Rialland
parent 238e69fc37
commit 11ed1432b0
7 changed files with 163 additions and 185 deletions

View File

@ -71,14 +71,13 @@ function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms))
}
;(async () => {
await Promise.allSettled(
Array.from({ length: simultaneousItems }).map(processNextQueueItem)
)
if (detectedErrors.length > 0) {
// Formattage spécifique pour récupérer le résultat avec l'action Github
if (process.argv.slice(2).includes('--ci')) {
const message = `
await Promise.allSettled(
Array.from({ length: simultaneousItems }).map(processNextQueueItem)
)
if (detectedErrors.length > 0) {
// Formattage spécifique pour récupérer le résultat avec l'action Github
if (process.argv.slice(2).includes('--ci')) {
const message = `
Certains liens référencés ne semblent plus fonctionner :
@ -88,22 +87,21 @@ function sleep(ms) {
.map(({ status, link }) => `| ${status} | ${link} |`)
.join('\n')}`
const format = (msg) =>
msg
.trim()
.split('\n')
.map((line) => line.trim())
.join('<br />')
console.log(`::set-output name=comment::${format(message)}`)
} else if (detectedErrors) {
console.log(
'Liens invalides :' +
detectedErrors
.map(({ status, link }) => `\n- [${status}] ${link}`)
.join('')
)
}
console.log('Terminé')
const format = (msg) =>
msg
.trim()
.split('\n')
.map((line) => line.trim())
.join('<br />')
console.log(`::set-output name=comment::${format(message)}`)
} else if (detectedErrors) {
console.log(
'Liens invalides :' +
detectedErrors
.map(({ status, link }) => `\n- [${status}] ${link}`)
.join('')
)
}
})()
console.log('Terminé')
}

View File

@ -11,13 +11,9 @@ dotenv.config()
const parseXML = promisify(parseString)
main()
async function main() {
createDataDir()
const jobOffers = await fetchJobOffers()
writeInDataDir('job-offers.json', jobOffers)
}
createDataDir()
const jobOffers = await fetchJobOffers()
writeInDataDir('job-offers.json', jobOffers)
async function fetchJobOffers() {
let jobOffers = []

View File

@ -55,16 +55,14 @@ const fakeData = [
},
]
async function main() {
createDataDir()
const releases = await fetchReleases()
// The last release name is fetched on all pages (to display the banner)
// whereas the full release data is used only in the dedicated page, that why
// we deduplicate the releases data in two separated files that can be
// bundled/fetched separately.
writeInDataDir('releases.json', releases)
writeInDataDir('last-release.json', { name: releases[0].name })
}
createDataDir()
const releases = await fetchReleases()
// The last release name is fetched on all pages (to display the banner)
// whereas the full release data is used only in the dedicated page, that why
// we deduplicate the releases data in two separated files that can be
// bundled/fetched separately.
writeInDataDir('releases.json', releases)
writeInDataDir('last-release.json', { name: releases[0].name })
async function fetchReleases(after = 'null') {
if (!githubAuthToken) {
@ -100,5 +98,3 @@ async function fetchReleases(after = 'null') {
return fakeData
}
}
main()

View File

@ -543,62 +543,59 @@ async function fetchAllUserFeedbackIssues() {
}
}
async function main() {
createDataDir()
// In case we cannot fetch the release (the API is down or the Authorization
// token isn't valid) we fallback to some fake data -- it would be better to
// have a static ressource accessible without authentification.
writeInDataDir('stats.json', {
retoursUtilisateurs: {
open: [],
closed: [],
},
nbAnswersLast30days: 0,
})
createDataDir()
// In case we cannot fetch the release (the API is down or the Authorization
// token isn't valid) we fallback to some fake data -- it would be better to
// have a static ressource accessible without authentification.
writeInDataDir('stats.json', {
retoursUtilisateurs: {
open: [],
closed: [],
},
nbAnswersLast30days: 0,
})
try {
if (
!process.env.ATINTERNET_API_ACCESS_KEY ||
!process.env.ATINTERNET_API_SECRET_KEY ||
!process.env.ZAMMAD_API_SECRET_KEY
) {
console.log(
"Variables d'environnement manquantes : nous ne récupérons pas les statistiques d'usage"
)
return
}
const [
visitesJours,
visitesMois,
rawSatisfaction,
retoursUtilisateurs,
nbAnswersLast30days,
] = await Promise.all([
fetchDailyVisits(),
fetchMonthlyVisits(),
fetchApi(buildSatisfactionQuery()),
fetchAllUserFeedbackIssues(),
fetchAllUserAnswerStats(),
])
const satisfaction = uniformiseData(flattenPage(await rawSatisfaction)).map(
(page) => {
// eslint-disable-next-line no-unused-vars
const { date, ...satisfactionPage } = {
month: new Date(new Date(page.date).setDate(1)),
...page,
}
return satisfactionPage
}
try {
if (
!process.env.ATINTERNET_API_ACCESS_KEY ||
!process.env.ATINTERNET_API_SECRET_KEY ||
!process.env.ZAMMAD_API_SECRET_KEY
) {
console.log(
"Variables d'environnement manquantes : nous ne récupérons pas les statistiques d'usage"
)
writeInDataDir('stats.json', {
visitesJours,
visitesMois,
satisfaction,
retoursUtilisateurs,
nbAnswersLast30days,
})
} catch (e) {
console.error(e)
process.exit(1)
}
const [
visitesJours,
visitesMois,
rawSatisfaction,
retoursUtilisateurs,
nbAnswersLast30days,
] = await Promise.all([
fetchDailyVisits(),
fetchMonthlyVisits(),
fetchApi(buildSatisfactionQuery()),
fetchAllUserFeedbackIssues(),
fetchAllUserAnswerStats(),
])
const satisfaction = uniformiseData(flattenPage(await rawSatisfaction)).map(
(page) => {
// eslint-disable-next-line no-unused-vars
const { date, ...satisfactionPage } = {
month: new Date(new Date(page.date).setDate(1)),
...page,
}
return satisfactionPage
}
)
writeInDataDir('stats.json', {
visitesJours,
visitesMois,
satisfaction,
retoursUtilisateurs,
nbAnswersLast30days,
})
} catch (e) {
console.error(e)
}
main()

View File

@ -10,37 +10,33 @@ const INDEX = {
DATE_EFFET: 4,
}
;(async function main() {
const response = await fetch(CSV_URL)
const rawCSV = await response.text()
const data = rawCSV
.split('\n')
.slice(1, -1)
.map((row) => row.split(';'))
.filter((r) => r[INDEX.TAUX] !== '0')
.filter(
(r) => !r[INDEX.DATE_EFFET].startsWith((CURRENT_YEAR + 1).toString())
)
.map((r) => {
r[INDEX.CODE_COMMUNE] = r[INDEX.CODE_COMMUNE].slice(1, -1) // Remove single quote ''
return r
})
.sort((a, b) =>
+a[INDEX.CODE_COMMUNE] < +b[INDEX.CODE_COMMUNE]
? -1
: +a[INDEX.CODE_COMMUNE] > +b[INDEX.CODE_COMMUNE]
? 1
: a[INDEX.DATE_EFFET] > b[INDEX.DATE_EFFET]
? -1
: 1
)
.reduce(
(acc, r) => ({
[r[INDEX.CODE_COMMUNE]]: +r[INDEX.TAUX],
...acc,
}),
{}
)
const response = await fetch(CSV_URL)
const rawCSV = await response.text()
const data = rawCSV
.split('\n')
.slice(1, -1)
.map((row) => row.split(';'))
.filter((r) => r[INDEX.TAUX] !== '0')
.filter((r) => !r[INDEX.DATE_EFFET].startsWith((CURRENT_YEAR + 1).toString()))
.map((r) => {
r[INDEX.CODE_COMMUNE] = r[INDEX.CODE_COMMUNE].slice(1, -1) // Remove single quote ''
return r
})
.sort((a, b) =>
+a[INDEX.CODE_COMMUNE] < +b[INDEX.CODE_COMMUNE]
? -1
: +a[INDEX.CODE_COMMUNE] > +b[INDEX.CODE_COMMUNE]
? 1
: a[INDEX.DATE_EFFET] > b[INDEX.DATE_EFFET]
? -1
: 1
)
.reduce(
(acc, r) => ({
[r[INDEX.CODE_COMMUNE]]: +r[INDEX.TAUX],
...acc,
}),
{}
)
writeInDataDir('versement-mobilité.json', data)
})()
writeInDataDir('versement-mobilité.json', data)

View File

@ -14,27 +14,26 @@ writeFileSync(
rulesTranslationPath,
yaml.stringify(resolved, { sortMapEntries: true })
)
;(async function main() {
await Promise.all(
missingTranslations.map(async ([dottedName, attr, value]) => {
try {
const translation = await fetchTranslation(value)
resolved[dottedName][attr] = '[automatic] ' + translation
} catch (e) {
console.error(e)
console.log(value)
}
})
)
prettier.resolveConfig(rulesTranslationPath).then((options) => {
const formattedYaml = prettier.format(
yaml.stringify(resolved, { sortMapEntries: true }),
{
...options,
parser: 'yaml',
}
)
writeFileSync(rulesTranslationPath, formattedYaml)
await Promise.all(
missingTranslations.map(async ([dottedName, attr, value]) => {
try {
const translation = await fetchTranslation(value)
resolved[dottedName][attr] = '[automatic] ' + translation
} catch (e) {
console.error(e)
console.log(value)
}
})
})()
)
prettier.resolveConfig(rulesTranslationPath).then((options) => {
const formattedYaml = prettier.format(
yaml.stringify(resolved, { sortMapEntries: true }),
{
...options,
parser: 'yaml',
}
)
writeFileSync(rulesTranslationPath, formattedYaml)
})

View File

@ -8,36 +8,32 @@ import {
getUiMissingTranslations,
} from './utils.js'
;(async function () {
const missingTranslations = getUiMissingTranslations()
let originalKeys = yaml.parse(
readFileSync(UiOriginalTranslationPath, 'utf-8')
)
let translatedKeys = yaml.parse(readFileSync(UiTranslationPath, 'utf-8'))
await Promise.all(
Object.entries(missingTranslations)
.map(([key, value]) => [key, value === 'NO_TRANSLATION' ? key : value])
.map(async ([key, originalTranslation]) => {
try {
const translation = await fetchTranslation(originalTranslation)
const path = key.split(/(?<=[A-zÀ-ü0-9])\.(?=[A-zÀ-ü0-9])/)
translatedKeys = assocPath(path, translation, translatedKeys)
originalKeys = assocPath(path, originalTranslation, originalKeys)
} catch (e) {
console.error(e)
console.log(originalTranslation)
}
})
)
writeFileSync(
UiTranslationPath,
yaml.stringify(translatedKeys, { sortMapEntries: true })
)
writeFileSync(
UiOriginalTranslationPath,
yaml.stringify(originalKeys, { sortMapEntries: true })
)
})()
const missingTranslations = getUiMissingTranslations()
let originalKeys = yaml.parse(readFileSync(UiOriginalTranslationPath, 'utf-8'))
let translatedKeys = yaml.parse(readFileSync(UiTranslationPath, 'utf-8'))
await Promise.all(
Object.entries(missingTranslations)
.map(([key, value]) => [key, value === 'NO_TRANSLATION' ? key : value])
.map(async ([key, originalTranslation]) => {
try {
const translation = await fetchTranslation(originalTranslation)
const path = key.split(/(?<=[A-zÀ-ü0-9])\.(?=[A-zÀ-ü0-9])/)
translatedKeys = assocPath(path, translation, translatedKeys)
originalKeys = assocPath(path, originalTranslation, originalKeys)
} catch (e) {
console.error(e)
console.log(originalTranslation)
}
})
)
writeFileSync(
UiTranslationPath,
yaml.stringify(translatedKeys, { sortMapEntries: true })
)
writeFileSync(
UiOriginalTranslationPath,
yaml.stringify(originalKeys, { sortMapEntries: true })
)
function assocPath(path, val, obj) {
if (path.length === 0) return val