2024-10-08 10:09:21 +02:00
|
|
|
|
import * as fs from 'node:fs'
|
2023-08-09 23:10:45 +02:00
|
|
|
|
|
|
|
|
|
let show_debug = 0
|
2023-10-01 11:23:19 +02:00
|
|
|
|
// show_debug = 1
|
2023-08-09 23:10:45 +02:00
|
|
|
|
let output_folder = 'output';
|
2024-10-15 18:43:52 +02:00
|
|
|
|
const prefix_phone_fr_only = true
|
2023-08-09 23:10:45 +02:00
|
|
|
|
|
|
|
|
|
// console.log('----------------------show_debug', show_debug)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* wrapper de log qui se montre uniquemnt si show_debug a été activé
|
|
|
|
|
* @param args
|
|
|
|
|
*/
|
|
|
|
|
function debugLog(...args: any[]) {
|
|
|
|
|
if (show_debug) {
|
2023-08-18 11:39:40 +02:00
|
|
|
|
console.log('### debug: ',)
|
2023-08-18 12:59:09 +02:00
|
|
|
|
args.map((elem: any) => console.log(' ', elem))
|
2023-08-09 23:10:45 +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"
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param pointKeyName
|
|
|
|
|
* @returns {boolean}
|
|
|
|
|
*/
|
|
|
|
|
function isBooleanKey(pointKeyName: string): boolean {
|
|
|
|
|
|
|
|
|
|
return listOfBooleanKeys.indexOf(pointKeyName) !== -1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* crée un fichier dans le dossier par défaut, output
|
|
|
|
|
* @param fileName
|
|
|
|
|
* @param fileContent
|
|
|
|
|
*/
|
2023-08-18 12:59:09 +02:00
|
|
|
|
function writeFile(fileName: string, fileContent: any, outputPathOverride: string = '') {
|
2023-08-09 23:10:45 +02:00
|
|
|
|
|
2023-08-18 12:59:09 +02:00
|
|
|
|
if (outputPathOverride) {
|
|
|
|
|
output_folder = outputPathOverride
|
2023-08-18 13:25:58 +02:00
|
|
|
|
} else {
|
|
|
|
|
console.log('pas de output', outputPathOverride
|
|
|
|
|
)
|
2023-08-18 12:59:09 +02:00
|
|
|
|
}
|
2023-08-18 13:25:58 +02:00
|
|
|
|
let destination = `./${output_folder}/${fileName}`.replace('//','/');
|
|
|
|
|
console.log('write file ', destination)
|
2023-08-09 23:10:45 +02:00
|
|
|
|
return fs.writeFile(
|
2023-08-18 12:59:09 +02:00
|
|
|
|
destination,
|
2023-08-09 23:10:45 +02:00
|
|
|
|
fileContent,
|
|
|
|
|
'utf8',
|
|
|
|
|
(err) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
console.log(`Error writing file: ${err}`)
|
|
|
|
|
} else {
|
|
|
|
|
console.log(`File ${fileName} is written successfully!`)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
debugLog,
|
|
|
|
|
isBooleanKey,
|
2024-10-15 18:43:52 +02:00
|
|
|
|
writeFile,
|
|
|
|
|
prefix_phone_fr_only
|
2023-08-09 23:10:45 +02:00
|
|
|
|
}
|