This repository has been archived by the owner on Jul 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
convert2xkt.js
executable file
·79 lines (62 loc) · 2.16 KB
/
convert2xkt.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
73
74
75
76
77
78
79
#!/usr/bin/env node
const commander = require('commander');
const package = require('./package.json');
const convert2xkt = require('./dist/convert2xkt.cjs.js');
const fs = require('fs');
const program = new commander.Command();
program.version(package.version, '-v, --version');
program
.option('-s, --source [file]', 'path to source file')
.option('-f, --format [string]', 'source file format (optional); supported formats are gltf, ifc, laz, las, pcd, ply, stl and cityjson')
.option('-m, --metamodel [file]', 'path to source metamodel JSON file (optional)')
.option('-i, --include [types]', 'only convert these types (optional)')
.option('-x, --exclude [types]', 'never convert these types (optional)')
.option('-o, --output [file]', 'path to target .xkt file; creates directories on path automatically if not existing')
.option('-l, --log', 'enable logging');
program.on('--help', () => {
});
program.parse(process.argv);
const options = program.opts();
if (program.source === undefined) {
console.error('Error: please specify source file path.');
program.help();
process.exit(1);
}
if (program.output === undefined) {
console.error('Error: please specify target xkt file path.');
program.help();
process.exit(1);
}
function log(msg) {
if (options.log) {
console.log(msg);
}
}
async function main() {
if (program.output) {
const outputDir = getBasePath(program.output).trim();
if (outputDir !== "" && !fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, {recursive: true});
}
}
const result = await convert2xkt({
source: program.source,
format: program.format,
metaModelSource: program.metamodel,
output: program.output,
includeTypes: program.include ? program.include.slice(",") : null,
excludeTypes: program.exclude ? program.exclude.slice(",") : null,
log
});
if (result < 0) {
process.exit(1);
}
}
function getBasePath(src) {
const i = src.lastIndexOf("/");
return (i !== 0) ? src.substring(0, i + 1) : "";
}
main().catch(err => {
console.error('Error:', err);
process.exit(1);
});