scripts/rangement/index.mjs
2023-06-29 18:58:08 +02:00

75 lines
2.1 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**---------------------
* @name tykayn Rangement
* @description Rangement sorts and rename files depending on their exif data
* @contact contact@cipherbliss.com
--------------------- */
/** ---------------------
libs
--------------------- */
import fs from 'node-fs'
import minimist from 'minimist'
/** ---------------------
custom utilities and configuration
--------------------- */
import { enableTestsLocally, reportStatistics, tagSectionSeparator, tagSeparator } from './configs.mjs'
import {
TestFindFormattedDate,
TestScreenShotIsFoundAndRenamed,
TestTagsAreDetectedInFileName
} from './testFunctions.mjs'
import finder from './finder.mjs'
let mini_arguments;
console.log(' ')
function parseArguments () {
mini_arguments = minimist(process.argv.slice(2))
// console.log('arguments', mini_arguments)
}
parseArguments()
const pathFolder = '/home/poule/encrypted/stockage-syncable/photos/a_dispatcher/tout'
const sortingFolder = '/home/poule/encrypted/stockage-syncable/photos/a_dispatcher'
function renameFile (originalFileName, fileMixedNewName) {
fs.rename(originalFileName, fileMixedNewName, function (err) {
if (err) console.log('rename ERROR: ' + err)
})
}
const fileDefinition = {
dateStamp: '',
freeText: '',
tags: [],
extension: '',
}
function makeFileNameFromProperties (fileProperties) {
return finder.cleanSpaces(fileProperties.dateStamp + ' ' + fileProperties.freeText + ' ' + tagSectionSeparator + ' ' + fileProperties.tags.join(tagSeparator) + fileProperties.extension)
}
function appendFileName (fileProperties, newText) {
fileProperties.freeText = finder.cleanSpaces(fileProperties.freeText + ' ' + newText)
return fileProperties
}
function prependFileName (fileProperties, newText) {
fileProperties.freeText = finder.cleanSpaces(newText + ' ' + fileProperties.freeText)
return fileProperties
}
/**
* work in progress
*
*/
// run tests
if (enableTestsLocally) {
TestTagsAreDetectedInFileName()
TestFindFormattedDate()
TestScreenShotIsFoundAndRenamed()
}
if (reportStatistics || mini_arguments.stats) {
finder.reportStatistics()
}