scripts/rangement/index.mjs

75 lines
2.1 KiB
JavaScript
Raw Normal View History

2023-06-29 18:58:08 +02:00
/**---------------------
* @name tykayn Rangement
* @description Rangement sorts and rename files depending on their exif data
* @contact contact@cipherbliss.com
--------------------- */
/** ---------------------
libs
--------------------- */
2023-06-27 15:40:50 +02:00
import fs from 'node-fs'
2023-06-29 18:58:08 +02:00
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()
2023-06-27 15:40:50 +02:00
2023-06-29 17:09:18 +02:00
const pathFolder = '/home/poule/encrypted/stockage-syncable/photos/a_dispatcher/tout'
2023-06-29 18:13:46 +02:00
const sortingFolder = '/home/poule/encrypted/stockage-syncable/photos/a_dispatcher'
2023-06-27 15:40:50 +02:00
2023-06-29 18:58:08 +02:00
function renameFile (originalFileName, fileMixedNewName) {
fs.rename(originalFileName, fileMixedNewName, function (err) {
if (err) console.log('rename ERROR: ' + err)
})
2023-06-27 23:03:35 +02:00
}
const fileDefinition = {
2023-06-29 18:58:08 +02:00
dateStamp: '',
freeText: '',
tags: [],
extension: '',
2023-06-27 23:03:35 +02:00
}
2023-06-29 18:58:08 +02:00
function makeFileNameFromProperties (fileProperties) {
return finder.cleanSpaces(fileProperties.dateStamp + ' ' + fileProperties.freeText + ' ' + tagSectionSeparator + ' ' + fileProperties.tags.join(tagSeparator) + fileProperties.extension)
2023-06-27 23:03:35 +02:00
}
2023-06-27 16:06:22 +02:00
2023-06-29 18:58:08 +02:00
function appendFileName (fileProperties, newText) {
fileProperties.freeText = finder.cleanSpaces(fileProperties.freeText + ' ' + newText)
return fileProperties
2023-06-27 23:18:00 +02:00
}
2023-06-29 17:09:18 +02:00
2023-06-29 18:58:08 +02:00
function prependFileName (fileProperties, newText) {
fileProperties.freeText = finder.cleanSpaces(newText + ' ' + fileProperties.freeText)
return fileProperties
2023-06-27 23:03:35 +02:00
}
2023-06-29 17:09:18 +02:00
2023-06-27 23:18:00 +02:00
/**
* work in progress
*
*/
// run tests
2023-06-29 18:13:46 +02:00
if (enableTestsLocally) {
2023-06-27 23:18:00 +02:00
2023-06-29 18:58:08 +02:00
TestTagsAreDetectedInFileName()
TestFindFormattedDate()
TestScreenShotIsFoundAndRenamed()
2023-06-27 23:18:00 +02:00
}
2023-06-29 18:58:08 +02:00
if (reportStatistics || mini_arguments.stats) {
finder.reportStatistics()
2023-06-27 23:03:35 +02:00
}