diff --git a/utils/finder.ts b/utils/finder.ts index afaf6e5..4c7293d 100644 --- a/utils/finder.ts +++ b/utils/finder.ts @@ -8,22 +8,14 @@ import rangement_instance from '../conf/configs' import * as fs from "fs"; import path from "node:path"; import minimist from 'minimist'; +import {fileDestructuration, taggingCommand} from './interfaces'; log.setLevel(rangement_instance.log_level) -interface fileDestructuration { - fullPath: string - folderPath: string - fileNameOriginal: string - dateStampInFileNameOriginal: string - dateStampExif: string, - freeText: string, - tags: string[], - extension: string, -} let cwd = path.dirname(process.cwd()) + '/' + path.basename(process.cwd()) + /** * finds patterns for file name */ @@ -81,7 +73,7 @@ export default class finder { * @param fullPath */ - static guessFileNameOnOnefile(fullPath: string):void { + static guessFileNameOnOnefile(fullPath: string): void { log.info('go guess file name on file: ', fullPath) fs.stat(fullPath, (err, stats) => { @@ -161,7 +153,7 @@ export default class finder { }) } - static guessFileNameOnAllFilesFromArguments():void { + static guessFileNameOnAllFilesFromArguments(): void { // parcourir les fichiers log.debug('liste des fichiers', this.mini_arguments._) @@ -212,6 +204,9 @@ export default class finder { static parseArguments() { this.mini_arguments = minimist(process.argv.slice(2)) log.debug('arguments', this.mini_arguments) + if (!this.mini_arguments._.length) { + log.info('pas de fichier ou de dossier demandé, veuillez spécifier un chemin en argument') + } } static shouldWeChangeName(structureForFile: fileDestructuration) { @@ -357,7 +352,7 @@ export default class finder { * @param tagCommand * @returns {{tagsToAdd: [], tagCommand: *, tagsToRemove: []}} */ - static addOrRemoveTagsParsing(tagCommand: string): any { + static addOrRemoveTagsParsing(tagCommand: string): taggingCommand { let tagsToAdd: Array = [] let tagsToRemove: Array = [] @@ -377,12 +372,15 @@ export default class finder { } static applyTagChangesOnProperties(tagChange: any, properties: fileDestructuration) { - - + // add new tags properties.tags = [...properties.tags, tagChange.tagsToAdd] - properties.tags.filter(elem => { - return tagChange.tagsToRemove.includes(elem) + properties.tags.forEach((elem, index) => { + if (tagChange.tagsToRemove.includes(elem)) { + delete properties.tags[index] + } }) + properties.tags = [...new Set(properties.tags)]; + return properties } diff --git a/utils/interfaces.ts b/utils/interfaces.ts new file mode 100644 index 0000000..6db4fe6 --- /dev/null +++ b/utils/interfaces.ts @@ -0,0 +1,16 @@ +export interface fileDestructuration { + fullPath: string + folderPath: string + fileNameOriginal: string + dateStampInFileNameOriginal: string + dateStampExif: string, + freeText: string, + tags: string[], + extension: string, +} + +export interface taggingCommand { + tagCommand: string, + tagsToAdd: Array, + tagsToRemove: Array +} \ No newline at end of file