-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
60 lines (46 loc) · 1.78 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import * as path from 'path';
import * as fs from 'fs';
import * as dree from 'dree';
import { Logger } from 'euberlog';
const logger = new Logger();
// function main() {
// const args = process.argv.slice(2);
// const [src] = args;
// if (!src) {
// logger.error('Error, required positional agument src path is missing');
// throw new Error('Error, required positional agument src path is missing');
// }
// const handledSrc = path.resolve(process.cwd(), src);
// const files: string[] = [];
// dree.scan(handledSrc, { extensions: ['jpg'] }, file => {
// files.push(file.path);
// });
// for (const file of files) {
// const filename = path.basename(file);
// const dirname = path.dirname(file);
// const date = new Date(filename.replace('.jpg', ''));
// const newFileName = `${date.toISOString().slice(0, 19)}.jpg`;
// const newPath = path.join(dirname, newFileName);
// fs.renameSync(file, newPath);
// }
// }
function main() {
const args = process.argv.slice(2);
const [src] = args;
if (!src) {
logger.error('Error, required positional agument src path is missing');
throw new Error('Error, required positional agument src path is missing');
}
const handledSrc = path.resolve(process.cwd(), src);
const queries: string[] = [];
dree.scan(handledSrc, { extensions: ['jpg'] }, file => {
const filename = path.basename(file.path);
const date = filename.replace('.jpg', '').replace('T', ' ');
queries.push(`
INSERT INTO images(name, path, timestamp)
VALUES ('hotelmadrigale', '/hotelmadrigale/${filename}', '${date}');`
);
});
fs.writeFileSync('./result.sql', queries.join('\n\n'));
}
main();