-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
72 lines (68 loc) · 2.52 KB
/
index.js
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
61
62
63
64
65
66
67
68
69
70
71
72
import { styleText } from 'node:util';
import { readPackage } from 'read-pkg';
import { readMusicFile, readOutputfile } from './modules/read.js';
import { printTable } from './modules/print.js';
import timeSpan from './modules/hms.js';
import { handle } from './modules/helpers.js';
import { writeStatus } from './modules/write.js';
const skipArtists = !!process.env.npm_config_skipArtists;
const skipAlbums = !!process.env.npm_config_skipAlbums;
const printArtistsWithoutArt = !!process.env.npm_config_printArtistsWithoutArt;
const printArtists = !!process.env.npm_config_printArtists;
const printAlbumsWithoutArt = !!process.env.npm_config_printAlbumsWithoutArt;
const printAlbums = !!process.env.npm_config_printAlbums;
const updateLib = !!process.env.npm_config_updateLib;
const writeSource = !!process.env.npm_config_writeSource;
const isTurbo = !!process.env.npm_config_turbo;
const daemonMode = !!process.env.npm_config_daemon;
readPackage().then(async () => {
readPackage().then(async ({ name, version }) => {
if (!daemonMode)
console.log(`Starting ${styleText('green', `${name} v${version}`)}\n`);
if (daemonMode) writeStatus({ status: 'running' });
let printtype = '';
let printFilter = '';
if (printArtistsWithoutArt) {
printtype = 'artists-without-art';
}
if (printArtists) {
printtype = 'artists';
}
if (printAlbums) {
printtype = 'albums';
}
if (printAlbumsWithoutArt) {
printtype = 'albums';
printFilter = 'unknown';
}
if (printtype) {
const list = JSON.parse(await readOutputfile(printtype, printFilter));
printTable(list, printtype, printFilter);
process.exit(0);
}
if (updateLib) {
const data = await readMusicFile();
await handle(data, 'update', isTurbo, daemonMode);
process.exit(0);
}
if (writeSource) {
const data = await readMusicFile();
await handle(data, 'writeSource', isTurbo, daemonMode);
process.exit(0);
}
const start = new Date().getTime();
const data = await readMusicFile();
if (!skipArtists) {
await handle(data, 'artists', isTurbo, daemonMode);
}
if (!skipAlbums) {
await handle(data, 'albums', isTurbo, daemonMode);
}
await handle(data, 'update', isTurbo, daemonMode);
await handle(data, 'writeSource', isTurbo, daemonMode);
const stop = new Date().getTime();
if (!daemonMode)
console.log(`Finished in ${styleText('yellow', timeSpan(stop - start))}`);
if (daemonMode) writeStatus({ status: 'done' }, true);
});
});