-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
executable file
·59 lines (52 loc) · 1.76 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
#! /usr/bin/env node
import { Command } from "commander";
import { packageJSON } from "./utils/index.js";
import {
importStream,
passthroughStream,
transformStream,
} from "./import/index.js";
import exportStream from "./export/index.js";
(async () => {
const program = new Command();
program
.name(packageJSON.name)
.description("Manage csvs databases.")
.version(packageJSON.version, "-v, --version")
.option("-i, --source-path <string>", "Path to source", process.cwd())
.option("-o, --target-path <string>", "Path to target")
.option("--hashsum", "Hashsum files during caching", false)
.option("--yank", "Yank files to target database", false)
.option("--insert", "Append tablets instead of updating", false)
// TODO if targetPath is specified, targetType defaults to "csvs"
.option("-t, --target-type <string>", "Type of target", "json")
.option("-q, --query <string>", "Search string", "?")
.option("--stats", "Show database statistics", false)
.action(async (options) => {
const isStdin = process.stdin.isTTY === undefined;
const input = isStdin
? ReadableStream.from(process.stdin)
: await importStream(
options.sourcePath,
options.query,
options.hashsum,
options.stats,
);
const through = isStdin
? await transformStream(
options.sourcePath,
options.query,
options.hashsum,
options.stats,
)
: passthroughStream();
const output = await exportStream(
options.targetPath,
options.targetType,
options.yank,
options.insert,
);
await input.pipeThrough(through).pipeTo(output);
});
program.parse();
})();