diff --git a/README.md b/README.md index 0367ca8..1e8f76c 100644 --- a/README.md +++ b/README.md @@ -25,11 +25,22 @@ mais ce n'est pas encore prêt à être utilisé en production. "npm start" gives you a demo of what Rangement can do, but this is not a production ready package yet. +# done + +* Handle verbosity levels in logs + - log.trace(msg) + - log.debug(msg) + - log.info(msg) + - log.warn(msg) + - log.error(msg) + + # Roadmap +* Internationalisation of console texts * Proper testing -* Handle verbosity levels + * Handle a configuration file - * create config file if needed +- * create config file if needed * batch rename like the python pip script "guessfilename" * revert renaming actions - * Log renaming actions +- * Log renaming actions diff --git a/index.mjs b/index.mjs index 9148a60..86baaa9 100644 --- a/index.mjs +++ b/index.mjs @@ -8,6 +8,8 @@ --------------------- */ import fs from 'node-fs' import minimist from 'minimist' +import log from 'loglevel'; + /** --------------------- custom utilities and configuration --------------------- */ @@ -20,19 +22,20 @@ import { import finder from './finder.mjs' let mini_arguments -console.log(' ') +log.setLevel('info') +log.info(' ') function parseArguments () { mini_arguments = minimist(process.argv.slice(2)) - console.log('arguments', mini_arguments) + log.info('arguments', mini_arguments) } parseArguments() function renameFile (originalFileName, fileMixedNewName) { fs.rename(originalFileName, fileMixedNewName, function (err) { - console.log('name changed', fileMixedNewName) - if (err) console.log('rename ERROR: ' + err) + log.info('name changed', fileMixedNewName) + if (err) log.info('rename ERROR: ' + err) }) } @@ -57,22 +60,22 @@ function makeFileNameFromProperties(fileProperties) { } function shouldWeChangeName (structureForFile) { - console.log(' ______ allez hop fini la recherche on fait un nouveau nom') - console.log('structureForFile', structureForFile) + log.info(' ______ allez hop fini la recherche on fait un nouveau nom') + log.info('structureForFile', structureForFile) let newName = makeFileNameFromProperties(structureForFile) if (structureForFile.fileNameOriginal !== newName) { - console.log('\n ancien nom :', structureForFile.fileNameOriginal) - // console.log(' nouveau nom:', foundDate +structureForFile.freeText + structureForFile.tags.join(tagSeparator) + structureForFile.extension ) - console.log(' nouveau nom:', newName) + log.info('\n ancien nom :', structureForFile.fileNameOriginal) + // log.info(' nouveau nom:', foundDate +structureForFile.freeText + structureForFile.tags.join(tagSeparator) + structureForFile.extension ) + log.info(' nouveau nom:', newName) if(! mini_arguments.dryRun){ renameFile(structureForFile.fullPath, structureForFile.folderPath + newName) } else{ - console.log('no renaming for real, this is a dry run') + log.info('no renaming for real, this is a dry run') } } else { - console.log(' rien à changer') + log.info(' rien à changer') } } @@ -82,7 +85,7 @@ async function guessFileNameOnAllFilesFromArguments () { // parcourir les dossiers // parcourir les fichiers - console.log('liste des fichiers', mini_arguments._) + log.info('liste des fichiers', mini_arguments._) let fileList = mini_arguments._ fileList.forEach(fullPath => { @@ -91,19 +94,19 @@ async function guessFileNameOnAllFilesFromArguments () { // examiner les infos exif de chaque fichier pour proposer un nouveau nom if (!structureForFile.dateStampInFileNameOriginal) { - console.log(' le nom de fichier ne contient pas de date formatée au début') + log.info(' le nom de fichier ne contient pas de date formatée au début') finder.findExifCreationDate(structureForFile.fullPath) .then(data => { - console.log(' ... chercher la date de création') + log.info(' ... chercher la date de création') let foundDate = finder.findEarliestDateInExifData(data) - console.log(' =>>>>>>> foundDate : ', foundDate) + log.info(' =>>>>>>> foundDate : ', foundDate) if (foundDate) { // finder.findEarliestDateInExifData(fullPath).then(response => { - // console.log(' ... trouvée') + // log.info(' ... trouvée') // if (response) { structureForFile.dateStampExif = foundDate @@ -112,13 +115,13 @@ async function guessFileNameOnAllFilesFromArguments () { // }) } else { - console.log('pas de date trouvée dans le nom') + log.info('pas de date trouvée dans le nom') } } , (error) => { - console.log('/////////// Error in reading exif of file: ' + error.message) + log.info('/////////// Error in reading exif of file: ' + error.message) return '' }) } diff --git a/locales/en/en.json b/locales/en/en.json new file mode 100644 index 0000000..e69de29 diff --git a/locales/fr/fr.json b/locales/fr/fr.json new file mode 100644 index 0000000..e69de29 diff --git a/package-lock.json b/package-lock.json index f011e8c..b3a07ae 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "AGPL-3.0-or-later", "dependencies": { "exifr": "^7.1.3", + "i18next": "^23.2.6", "minimist": "^1.2.8", "moment": "^2.29.4", "node-fs": "^0.1.7" @@ -21,6 +22,7 @@ "@jest/globals": "^29.5.0", "babel-jest": "^29.5.0", "jest": "^29.5.0", + "loglevel": "^1.8.1", "nodemon": "^2.0.22", "ts-node": "^10.9.1" } @@ -1798,7 +1800,6 @@ "version": "7.22.5", "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.22.5.tgz", "integrity": "sha512-ecjvYlnAaZ/KVneE/OdKYBYfgXV3Ptu6zQWmgEF7vwKhQnvVS6bjMD2XYgj+SNvQ1GfK/pjgokfPkC/2CO8CuA==", - "dev": true, "dependencies": { "regenerator-runtime": "^0.13.11" }, @@ -3280,6 +3281,28 @@ "node": ">=10.17.0" } }, + "node_modules/i18next": { + "version": "23.2.6", + "resolved": "https://registry.npmjs.org/i18next/-/i18next-23.2.6.tgz", + "integrity": "sha512-i0P2XBisewaICJ7UQtwymeJj6cXUigM+s8XNIXmWk4oJ8iTok2taCbOTX0ps+u9DFcQ6FWH6xLIU0dLEnMaNbA==", + "funding": [ + { + "type": "individual", + "url": "https://locize.com" + }, + { + "type": "individual", + "url": "https://locize.com/i18next.html" + }, + { + "type": "individual", + "url": "https://www.i18next.com/how-to/faq#i18next-is-awesome.-how-can-i-support-the-project" + } + ], + "dependencies": { + "@babel/runtime": "^7.22.5" + } + }, "node_modules/ignore-by-default": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/ignore-by-default/-/ignore-by-default-1.0.1.tgz", @@ -4174,6 +4197,19 @@ "integrity": "sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==", "dev": true }, + "node_modules/loglevel": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/loglevel/-/loglevel-1.8.1.tgz", + "integrity": "sha512-tCRIJM51SHjAayKwC+QAg8hT8vg6z7GSgLJKGvzuPb1Wc+hLzqtuVLxp6/HzSPOozuK+8ErAhy7U/sVzw8Dgfg==", + "dev": true, + "engines": { + "node": ">= 0.6.0" + }, + "funding": { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/loglevel" + } + }, "node_modules/lru-cache": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", @@ -4677,8 +4713,7 @@ "node_modules/regenerator-runtime": { "version": "0.13.11", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz", - "integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==", - "dev": true + "integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==" }, "node_modules/regenerator-transform": { "version": "0.15.1", diff --git a/package.json b/package.json index 7f5a860..884faed 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "license": "AGPL-3.0-or-later", "dependencies": { "exifr": "^7.1.3", + "i18next": "^23.2.6", "minimist": "^1.2.8", "moment": "^2.29.4", "node-fs": "^0.1.7" @@ -36,6 +37,7 @@ "@jest/globals": "^29.5.0", "babel-jest": "^29.5.0", "jest": "^29.5.0", + "loglevel": "^1.8.1", "nodemon": "^2.0.22", "ts-node": "^10.9.1" } diff --git a/setup.mjs b/setup.mjs new file mode 100644 index 0000000..d10bca2 --- /dev/null +++ b/setup.mjs @@ -0,0 +1,37 @@ +/** + création de la config + */ +import config from './configs.mjs' +import i18next from 'i18next' +let base_archive_folder = config.base_archive_folder + +const { stdin, stdout } = process; + +function prompt(question) { + return new Promise((resolve, reject) => { + stdin.resume(); + stdout.write(question); + + stdin.on('data', data => resolve(data.toString().trim())); + stdin.on('error', err => reject(err)); + }); +} + + +async function main() { + try { + const name = await prompt(i18next.t("home.title")) + // const age = await prompt("What's your age? "); + // const email = await prompt("What's your email address? "); + // const user = { name, age, email }; + console.log(name); + stdin.pause(); + } catch(error) { + console.log("There's an error!"); + console.log(error); + } + process.exit(); +} + +main(); +