add log level, start i18n
This commit is contained in:
parent
70b86ff4bd
commit
66df16671e
17
README.md
17
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.
|
"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
|
# Roadmap
|
||||||
|
* Internationalisation of console texts
|
||||||
* Proper testing
|
* Proper testing
|
||||||
* Handle verbosity levels
|
|
||||||
* Handle a configuration file
|
* Handle a configuration file
|
||||||
* create config file if needed
|
- * create config file if needed
|
||||||
* batch rename like the python pip script "guessfilename"
|
* batch rename like the python pip script "guessfilename"
|
||||||
* revert renaming actions
|
* revert renaming actions
|
||||||
* Log renaming actions
|
- * Log renaming actions
|
||||||
|
39
index.mjs
39
index.mjs
@ -8,6 +8,8 @@
|
|||||||
--------------------- */
|
--------------------- */
|
||||||
import fs from 'node-fs'
|
import fs from 'node-fs'
|
||||||
import minimist from 'minimist'
|
import minimist from 'minimist'
|
||||||
|
import log from 'loglevel';
|
||||||
|
|
||||||
/** ---------------------
|
/** ---------------------
|
||||||
custom utilities and configuration
|
custom utilities and configuration
|
||||||
--------------------- */
|
--------------------- */
|
||||||
@ -20,19 +22,20 @@ import {
|
|||||||
import finder from './finder.mjs'
|
import finder from './finder.mjs'
|
||||||
|
|
||||||
let mini_arguments
|
let mini_arguments
|
||||||
console.log(' ')
|
log.setLevel('info')
|
||||||
|
log.info(' ')
|
||||||
|
|
||||||
function parseArguments () {
|
function parseArguments () {
|
||||||
mini_arguments = minimist(process.argv.slice(2))
|
mini_arguments = minimist(process.argv.slice(2))
|
||||||
console.log('arguments', mini_arguments)
|
log.info('arguments', mini_arguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
parseArguments()
|
parseArguments()
|
||||||
|
|
||||||
function renameFile (originalFileName, fileMixedNewName) {
|
function renameFile (originalFileName, fileMixedNewName) {
|
||||||
fs.rename(originalFileName, fileMixedNewName, function (err) {
|
fs.rename(originalFileName, fileMixedNewName, function (err) {
|
||||||
console.log('name changed', fileMixedNewName)
|
log.info('name changed', fileMixedNewName)
|
||||||
if (err) console.log('rename ERROR: ' + err)
|
if (err) log.info('rename ERROR: ' + err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,22 +60,22 @@ function makeFileNameFromProperties(fileProperties) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function shouldWeChangeName (structureForFile) {
|
function shouldWeChangeName (structureForFile) {
|
||||||
console.log(' ______ allez hop fini la recherche on fait un nouveau nom')
|
log.info(' ______ allez hop fini la recherche on fait un nouveau nom')
|
||||||
console.log('structureForFile', structureForFile)
|
log.info('structureForFile', structureForFile)
|
||||||
let newName = makeFileNameFromProperties(structureForFile)
|
let newName = makeFileNameFromProperties(structureForFile)
|
||||||
if (structureForFile.fileNameOriginal !== newName) {
|
if (structureForFile.fileNameOriginal !== newName) {
|
||||||
|
|
||||||
console.log('\n ancien nom :', structureForFile.fileNameOriginal)
|
log.info('\n ancien nom :', structureForFile.fileNameOriginal)
|
||||||
// console.log(' nouveau nom:', foundDate +structureForFile.freeText + structureForFile.tags.join(tagSeparator) + structureForFile.extension )
|
// log.info(' nouveau nom:', foundDate +structureForFile.freeText + structureForFile.tags.join(tagSeparator) + structureForFile.extension )
|
||||||
console.log(' nouveau nom:', newName)
|
log.info(' nouveau nom:', newName)
|
||||||
if(! mini_arguments.dryRun){
|
if(! mini_arguments.dryRun){
|
||||||
renameFile(structureForFile.fullPath, structureForFile.folderPath + newName)
|
renameFile(structureForFile.fullPath, structureForFile.folderPath + newName)
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
console.log('no renaming for real, this is a dry run')
|
log.info('no renaming for real, this is a dry run')
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log(' rien à changer')
|
log.info(' rien à changer')
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -82,7 +85,7 @@ async function guessFileNameOnAllFilesFromArguments () {
|
|||||||
// parcourir les dossiers
|
// parcourir les dossiers
|
||||||
// parcourir les fichiers
|
// parcourir les fichiers
|
||||||
|
|
||||||
console.log('liste des fichiers', mini_arguments._)
|
log.info('liste des fichiers', mini_arguments._)
|
||||||
let fileList = mini_arguments._
|
let fileList = mini_arguments._
|
||||||
|
|
||||||
fileList.forEach(fullPath => {
|
fileList.forEach(fullPath => {
|
||||||
@ -91,19 +94,19 @@ async function guessFileNameOnAllFilesFromArguments () {
|
|||||||
|
|
||||||
// examiner les infos exif de chaque fichier pour proposer un nouveau nom
|
// examiner les infos exif de chaque fichier pour proposer un nouveau nom
|
||||||
if (!structureForFile.dateStampInFileNameOriginal) {
|
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)
|
finder.findExifCreationDate(structureForFile.fullPath)
|
||||||
.then(data => {
|
.then(data => {
|
||||||
console.log(' ... chercher la date de création')
|
log.info(' ... chercher la date de création')
|
||||||
let foundDate = finder.findEarliestDateInExifData(data)
|
let foundDate = finder.findEarliestDateInExifData(data)
|
||||||
|
|
||||||
console.log(' =>>>>>>> foundDate : ', foundDate)
|
log.info(' =>>>>>>> foundDate : ', foundDate)
|
||||||
if (foundDate) {
|
if (foundDate) {
|
||||||
|
|
||||||
|
|
||||||
// finder.findEarliestDateInExifData(fullPath).then(response => {
|
// finder.findEarliestDateInExifData(fullPath).then(response => {
|
||||||
// console.log(' ... trouvée')
|
// log.info(' ... trouvée')
|
||||||
// if (response) {
|
// if (response) {
|
||||||
structureForFile.dateStampExif = foundDate
|
structureForFile.dateStampExif = foundDate
|
||||||
|
|
||||||
@ -112,13 +115,13 @@ async function guessFileNameOnAllFilesFromArguments () {
|
|||||||
// })
|
// })
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
console.log('pas de date trouvée dans le nom')
|
log.info('pas de date trouvée dans le nom')
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
(error) => {
|
(error) => {
|
||||||
console.log('/////////// Error in reading exif of file: ' + error.message)
|
log.info('/////////// Error in reading exif of file: ' + error.message)
|
||||||
return ''
|
return ''
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
0
locales/en/en.json
Normal file
0
locales/en/en.json
Normal file
0
locales/fr/fr.json
Normal file
0
locales/fr/fr.json
Normal file
41
package-lock.json
generated
41
package-lock.json
generated
@ -10,6 +10,7 @@
|
|||||||
"license": "AGPL-3.0-or-later",
|
"license": "AGPL-3.0-or-later",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"exifr": "^7.1.3",
|
"exifr": "^7.1.3",
|
||||||
|
"i18next": "^23.2.6",
|
||||||
"minimist": "^1.2.8",
|
"minimist": "^1.2.8",
|
||||||
"moment": "^2.29.4",
|
"moment": "^2.29.4",
|
||||||
"node-fs": "^0.1.7"
|
"node-fs": "^0.1.7"
|
||||||
@ -21,6 +22,7 @@
|
|||||||
"@jest/globals": "^29.5.0",
|
"@jest/globals": "^29.5.0",
|
||||||
"babel-jest": "^29.5.0",
|
"babel-jest": "^29.5.0",
|
||||||
"jest": "^29.5.0",
|
"jest": "^29.5.0",
|
||||||
|
"loglevel": "^1.8.1",
|
||||||
"nodemon": "^2.0.22",
|
"nodemon": "^2.0.22",
|
||||||
"ts-node": "^10.9.1"
|
"ts-node": "^10.9.1"
|
||||||
}
|
}
|
||||||
@ -1798,7 +1800,6 @@
|
|||||||
"version": "7.22.5",
|
"version": "7.22.5",
|
||||||
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.22.5.tgz",
|
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.22.5.tgz",
|
||||||
"integrity": "sha512-ecjvYlnAaZ/KVneE/OdKYBYfgXV3Ptu6zQWmgEF7vwKhQnvVS6bjMD2XYgj+SNvQ1GfK/pjgokfPkC/2CO8CuA==",
|
"integrity": "sha512-ecjvYlnAaZ/KVneE/OdKYBYfgXV3Ptu6zQWmgEF7vwKhQnvVS6bjMD2XYgj+SNvQ1GfK/pjgokfPkC/2CO8CuA==",
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"regenerator-runtime": "^0.13.11"
|
"regenerator-runtime": "^0.13.11"
|
||||||
},
|
},
|
||||||
@ -3280,6 +3281,28 @@
|
|||||||
"node": ">=10.17.0"
|
"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": {
|
"node_modules/ignore-by-default": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/ignore-by-default/-/ignore-by-default-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/ignore-by-default/-/ignore-by-default-1.0.1.tgz",
|
||||||
@ -4174,6 +4197,19 @@
|
|||||||
"integrity": "sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==",
|
"integrity": "sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==",
|
||||||
"dev": true
|
"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": {
|
"node_modules/lru-cache": {
|
||||||
"version": "5.1.1",
|
"version": "5.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz",
|
||||||
@ -4677,8 +4713,7 @@
|
|||||||
"node_modules/regenerator-runtime": {
|
"node_modules/regenerator-runtime": {
|
||||||
"version": "0.13.11",
|
"version": "0.13.11",
|
||||||
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz",
|
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz",
|
||||||
"integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==",
|
"integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"node_modules/regenerator-transform": {
|
"node_modules/regenerator-transform": {
|
||||||
"version": "0.15.1",
|
"version": "0.15.1",
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
"license": "AGPL-3.0-or-later",
|
"license": "AGPL-3.0-or-later",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"exifr": "^7.1.3",
|
"exifr": "^7.1.3",
|
||||||
|
"i18next": "^23.2.6",
|
||||||
"minimist": "^1.2.8",
|
"minimist": "^1.2.8",
|
||||||
"moment": "^2.29.4",
|
"moment": "^2.29.4",
|
||||||
"node-fs": "^0.1.7"
|
"node-fs": "^0.1.7"
|
||||||
@ -36,6 +37,7 @@
|
|||||||
"@jest/globals": "^29.5.0",
|
"@jest/globals": "^29.5.0",
|
||||||
"babel-jest": "^29.5.0",
|
"babel-jest": "^29.5.0",
|
||||||
"jest": "^29.5.0",
|
"jest": "^29.5.0",
|
||||||
|
"loglevel": "^1.8.1",
|
||||||
"nodemon": "^2.0.22",
|
"nodemon": "^2.0.22",
|
||||||
"ts-node": "^10.9.1"
|
"ts-node": "^10.9.1"
|
||||||
}
|
}
|
||||||
|
37
setup.mjs
Normal file
37
setup.mjs
Normal file
@ -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();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user