enable testing mjs files
This commit is contained in:
parent
70b86ff4bd
commit
ed23623be0
7
babel.config.js
Normal file
7
babel.config.js
Normal file
@ -0,0 +1,7 @@
|
||||
const presets = [
|
||||
[
|
||||
"@babel/preset-env",
|
||||
]
|
||||
];
|
||||
|
||||
module.exports = { presets };
|
34
finder.mjs
34
finder.mjs
@ -4,7 +4,8 @@
|
||||
import { tagSectionSeparator, tagSeparator } from './configs.mjs'
|
||||
import exifr from 'exifr'
|
||||
import moment from 'moment'
|
||||
import path from 'path'
|
||||
import log from 'log_level'
|
||||
|
||||
|
||||
/**
|
||||
* finds patterns for file name
|
||||
@ -25,8 +26,8 @@ export default class finder {
|
||||
}
|
||||
|
||||
static findFormattedDate (filepath) {
|
||||
let match = filepath.match(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/ig)
|
||||
// console.log('match findFormattedDate', match)
|
||||
let match = filepath.match(/\d{4}-\d{2}-\d{2}T\d{2}\.\d{2}\.\d{2}/ig)
|
||||
log.debug('match findFormattedDate', match)
|
||||
let result = ''
|
||||
if (match && match[0]) {
|
||||
result = match[0]
|
||||
@ -35,8 +36,11 @@ export default class finder {
|
||||
}
|
||||
|
||||
static findFileExtension (inputString) {
|
||||
if(!inputString){
|
||||
return '';
|
||||
}
|
||||
let result = inputString.match(/\.\w{3,4}$/i)
|
||||
return result
|
||||
return result.shift()
|
||||
}
|
||||
|
||||
/**
|
||||
@ -73,17 +77,17 @@ export default class finder {
|
||||
}
|
||||
inputString = inputString.replace(extensionFile, '')
|
||||
|
||||
// console.log('extensionFile', extensionFile)
|
||||
log.debug('extensionFile', extensionFile)
|
||||
if (inputString.includes(tagSectionSeparator)) {
|
||||
// console.log('inputString', inputString)
|
||||
log.debug('inputString', inputString)
|
||||
if (inputString.length) {
|
||||
|
||||
let boom = inputString.split(tagSectionSeparator)
|
||||
// console.log('boom', boom)
|
||||
log.debug('boom', boom)
|
||||
if (boom.length) {
|
||||
let fileSectionsName = boom.splice(tagSeparator)
|
||||
listOfTags = [...fileSectionsName[1].trim().split(tagSeparator)]
|
||||
// console.log('listOfTags', listOfTags)
|
||||
log.debug('listOfTags', listOfTags)
|
||||
} else {
|
||||
console.log('no boom', boom)
|
||||
}
|
||||
@ -164,17 +168,17 @@ export default class finder {
|
||||
|
||||
let moments = []
|
||||
|
||||
// console.log('exif data : ', exifData) // Do something with your data!
|
||||
log.debug('exif data : ', exifData) // Do something with your data!
|
||||
if (exifData.DateTimeOriginal) {
|
||||
// console.log('image créée le : DateTimeOriginal : ', exifData.DateTimeOriginal) // Do something with your data!
|
||||
log.debug('image créée le : DateTimeOriginal : ', exifData.DateTimeOriginal) // Do something with your data!
|
||||
moments.push(exifData.DateTimeOriginal)
|
||||
}
|
||||
if (exifData.ModificationDateTime) {
|
||||
// console.log('image créée le : ModificationDateTime : ', exifData.ModificationDateTime) // Do something with your data!
|
||||
log.debug('image créée le : ModificationDateTime : ', exifData.ModificationDateTime) // Do something with your data!
|
||||
moments.push(exifData.ModificationDateTime)
|
||||
}
|
||||
if (exifData.ModifyDate) {
|
||||
// console.log('image créée le : ModifyDate : ', exifData.ModifyDate) // Do something with your data!
|
||||
log.debug('image créée le : ModifyDate : ', exifData.ModifyDate) // Do something with your data!
|
||||
moments.push(exifData.ModifyDate)
|
||||
}
|
||||
if (exifData.FileAccessDateTime) {
|
||||
@ -184,11 +188,11 @@ export default class finder {
|
||||
moments.push(exifData.FileInodeChangeDateTime)
|
||||
}
|
||||
if (exifData.FileModificationDateTime) {
|
||||
// console.log('image créée le : FileModificationDateTime : ', exifData.FileModificationDateTime) // Do something with your data!
|
||||
log.debug('image créée le : FileModificationDateTime : ', exifData.FileModificationDateTime) // Do something with your data!
|
||||
moments.push(exifData.FileModificationDateTime)
|
||||
}
|
||||
if (exifData.CreateDate) {
|
||||
// console.log('image créée le : CreateDate : ', exifData.CreateDate) // Do something with your data!
|
||||
log.debug('image créée le : CreateDate : ', exifData.CreateDate) // Do something with your data!
|
||||
moments.push(exifData.CreateDate)
|
||||
}
|
||||
|
||||
@ -198,7 +202,7 @@ export default class finder {
|
||||
})
|
||||
let minDate = moment.min(moments)
|
||||
|
||||
// console.log('minDate :::::::::', minDate)
|
||||
log.debug('minDate :::::::::', minDate)
|
||||
console.log('minDate :::::::::', minDate.format('yyyy-MM-DDTHH:mm:ss'))
|
||||
|
||||
return minDate.format('yyyy-MM-DDTHH:mm:ss')
|
||||
|
17
finder.test.js
Normal file
17
finder.test.js
Normal file
@ -0,0 +1,17 @@
|
||||
import finder from './finder.mjs'
|
||||
|
||||
describe('rangement file name', () => {
|
||||
|
||||
test('detects date in file name', () => {
|
||||
expect(finder
|
||||
.findFormattedDate('2023-06-23T18.36.47 -- machin bidule.jpg')
|
||||
)
|
||||
.toBe('2023-06-23T18.36.47')
|
||||
})
|
||||
test('detects file extension in file name', () => {
|
||||
expect(finder
|
||||
.findFileExtension('2023-06-23T18.36.47 -- machin bidule.jpg')
|
||||
)
|
||||
.toBe('.jpg')
|
||||
})
|
||||
})
|
16
index.mjs
16
index.mjs
@ -11,7 +11,7 @@ import minimist from 'minimist'
|
||||
/** ---------------------
|
||||
custom utilities and configuration
|
||||
--------------------- */
|
||||
import { enableTestsLocally, reportStatistics,tagSectionSeparator, tagSeparator } from './configs.mjs'
|
||||
import { enableTestsLocally, reportStatistics, tagSectionSeparator, tagSeparator } from './configs.mjs'
|
||||
import {
|
||||
TestFindFormattedDate,
|
||||
TestScreenShotIsFoundAndRenamed,
|
||||
@ -46,14 +46,14 @@ function prependFileName (fileProperties, newText) {
|
||||
return fileProperties
|
||||
}
|
||||
|
||||
function makeFileNameFromProperties(fileProperties) {
|
||||
function makeFileNameFromProperties (fileProperties) {
|
||||
|
||||
let tagPlace = ''
|
||||
if (fileProperties.tags.length) {
|
||||
tagPlace = ' ' + tagSectionSeparator + ' '
|
||||
}
|
||||
// return finder.cleanSpaces(fileProperties.dateStamp + ' ' + fileProperties.freeText + tagPlace + fileProperties.tags.join(tagSeparator) + fileProperties.extension).replace(+' ' + tagSectionSeparator + ' ' + '.', '.')
|
||||
return ''+fileProperties.dateStampExif + ' ' + fileProperties.freeText + tagPlace + fileProperties.tags.join(tagSeparator) + fileProperties.extension
|
||||
return '' + fileProperties.dateStampExif + ' ' + fileProperties.freeText + tagPlace + fileProperties.tags.join(tagSeparator) + fileProperties.extension
|
||||
}
|
||||
|
||||
function shouldWeChangeName (structureForFile) {
|
||||
@ -65,10 +65,9 @@ function shouldWeChangeName (structureForFile) {
|
||||
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)
|
||||
if(! mini_arguments.dryRun){
|
||||
if (!mini_arguments.dryRun) {
|
||||
renameFile(structureForFile.fullPath, structureForFile.folderPath + newName)
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
console.log('no renaming for real, this is a dry run')
|
||||
}
|
||||
} else {
|
||||
@ -101,13 +100,12 @@ async function guessFileNameOnAllFilesFromArguments () {
|
||||
console.log(' =>>>>>>> foundDate : ', foundDate)
|
||||
if (foundDate) {
|
||||
|
||||
|
||||
// finder.findEarliestDateInExifData(fullPath).then(response => {
|
||||
// console.log(' ... trouvée')
|
||||
// if (response) {
|
||||
structureForFile.dateStampExif = foundDate
|
||||
structureForFile.dateStampExif = foundDate
|
||||
|
||||
shouldWeChangeName(structureForFile)
|
||||
shouldWeChangeName(structureForFile)
|
||||
// }
|
||||
// })
|
||||
|
||||
|
15
main.test.js
15
main.test.js
@ -1,5 +1,4 @@
|
||||
import finder from "./finders.mjs";
|
||||
// const finders = require('./finders.mjs')
|
||||
import finder from "./finder.mjs";
|
||||
|
||||
describe('rangement file name', () => {
|
||||
|
||||
@ -7,16 +6,6 @@ describe('rangement file name', () => {
|
||||
expect(finder.findFormattedDate('2023-06-23T18.36.47 -- machin bidule.jpg')).toBe('2023-06-23T18.36.47');
|
||||
});
|
||||
test('detects file extension in file name', () => {
|
||||
expect(finder.findFileExtension()('2023-06-23T18.36.47 -- machin bidule.jpg')).toBe('jpg');
|
||||
expect(finder.findFileExtension('2023-06-23T18.36.47 -- machin bidule.jpg')).toBe('.jpg');
|
||||
});
|
||||
})
|
||||
console.log('finders', finder)
|
||||
|
||||
test('adding positive numbers is not zero', () => {
|
||||
for (let a = 1; a < 10; a++) {
|
||||
for (let b = 1; b < 10; b++) {
|
||||
expect(a + b).not.toBe(0);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user