2023-08-05 10:57:07 +02:00
|
|
|
|
import fs from 'fs'
|
2023-07-30 18:37:07 +02:00
|
|
|
|
|
2023-07-31 23:01:41 +02:00
|
|
|
|
let show_debug = 0
|
2023-08-05 12:05:52 +02:00
|
|
|
|
show_debug = 1
|
2023-08-05 09:55:14 +02:00
|
|
|
|
let output_folder = 'output';
|
2023-07-30 18:37:07 +02:00
|
|
|
|
|
2023-08-05 12:01:24 +02:00
|
|
|
|
console.log('----------------------show_debug', show_debug)
|
|
|
|
|
|
2023-07-30 18:37:07 +02:00
|
|
|
|
/**
|
2023-08-05 09:55:14 +02:00
|
|
|
|
* wrapper de log qui se montre uniquemnt si show_debug a été activé
|
|
|
|
|
* @param args
|
2023-07-30 18:37:07 +02:00
|
|
|
|
*/
|
2023-08-05 09:55:14 +02:00
|
|
|
|
function debugLog(...args: any[]) {
|
2023-08-05 12:01:24 +02:00
|
|
|
|
if (show_debug) {
|
2023-08-05 12:05:52 +02:00
|
|
|
|
console.log('### debug: ', ...args)
|
2023-07-30 18:37:07 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-30 19:18:17 +02:00
|
|
|
|
|
|
|
|
|
|
2023-08-05 09:55:14 +02:00
|
|
|
|
let listOfBooleanKeys = [
|
|
|
|
|
"prise_type_ef",
|
|
|
|
|
"prise_type_2",
|
|
|
|
|
"prise_type_combo_ccs",
|
|
|
|
|
"prise_type_chademo",
|
|
|
|
|
"gratuit",
|
|
|
|
|
"paiement_acte",
|
|
|
|
|
"paiement_cb",
|
|
|
|
|
"cable_t2_attache"
|
|
|
|
|
]
|
2023-07-30 19:18:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param pointKeyName
|
|
|
|
|
* @returns {boolean}
|
|
|
|
|
*/
|
2023-08-05 09:55:14 +02:00
|
|
|
|
function isBooleanKey(pointKeyName: string): boolean {
|
2023-07-30 19:18:17 +02:00
|
|
|
|
|
|
|
|
|
return listOfBooleanKeys.indexOf(pointKeyName) !== -1
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-05 09:55:14 +02:00
|
|
|
|
/**
|
|
|
|
|
* crée un fichier dans le dossier par défaut, output
|
|
|
|
|
* @param fileName
|
|
|
|
|
* @param fileContent
|
|
|
|
|
*/
|
|
|
|
|
function writeFile(fileName: string, fileContent: any) {
|
2023-07-31 19:27:17 +02:00
|
|
|
|
debugLog('write file ', fileName)
|
|
|
|
|
|
2023-08-05 09:55:14 +02:00
|
|
|
|
|
2023-07-31 19:27:17 +02:00
|
|
|
|
return fs.writeFile(
|
2023-08-05 09:55:14 +02:00
|
|
|
|
`./${output_folder}/${fileName}`,
|
2023-08-02 13:20:50 +02:00
|
|
|
|
fileContent,
|
|
|
|
|
'utf8',
|
|
|
|
|
(err) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
debugLog(`Error writing file: ${err}`)
|
|
|
|
|
} else {
|
|
|
|
|
debugLog(`File ${fileName} is written successfully!`)
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-31 19:27:17 +02:00
|
|
|
|
)
|
|
|
|
|
}
|
2023-08-02 13:20:50 +02:00
|
|
|
|
|
|
|
|
|
export default {
|
2023-07-30 19:18:17 +02:00
|
|
|
|
debugLog,
|
2023-07-31 19:27:17 +02:00
|
|
|
|
isBooleanKey,
|
|
|
|
|
writeFile
|
2023-07-30 18:37:07 +02:00
|
|
|
|
}
|