@shapediver/sdk.sdtf-v1
Version:
Official sdTF SDK for TypeScript
118 lines • 4.88 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const process = __importStar(require("process"));
const SdtfSdk_1 = require("./SdtfSdk");
const general = {
help: ['-h', '--help'],
};
const command_jsonContent = {
name: 'json-content',
options: {
url: ['-u', '--url'],
file: ['-f', '--file'],
},
};
(() => __awaiter(void 0, void 0, void 0, function* () {
try {
const sdk = yield (0, SdtfSdk_1.create)();
if (process.argv.length < 3 || (process.argv.length === 3 && isHelpArg(process.argv[2]))) {
printGeneralInfo();
}
else if (process.argv[2] === command_jsonContent.name) {
if (command_jsonContent.options.url.includes(process.argv[3])) {
const asset = yield sdk.createParser().readFromUrl(process.argv[4]);
console.log('sdTF JSON content:\n', sdk.createFormatter().prettifyReadableAsset(asset));
}
else if (command_jsonContent.options.file.includes(process.argv[3])) {
const asset = yield sdk.createParser().readFromFile(process.argv[4]);
console.log('sdTF JSON content:\n', sdk.createFormatter().prettifyReadableAsset(asset));
}
else if (process.argv[3] === undefined || general.help.includes(process.argv[3])) {
printJsonContentCommandInfo();
}
else {
errExit(`Invalid option '${process.argv[3]}'.`);
}
}
else {
errExit(`Invalid command '${process.argv[2]}.'`);
}
}
catch (e) {
errExit(e);
}
}))();
function isHelpArg(arg) {
return general.help.includes(arg);
}
function errExit(e) {
if (e instanceof Error) {
console.error('ERROR:', e.message, '\n');
console.error(e.stack);
}
else {
console.error('ERROR:', e);
}
process.exit(1);
}
function printGeneralInfo() {
console.log('Usage: sdtf <command>', '\n');
console.log('This is a commandline loader for sdTF (Structured Data Transfer Format) files.', '\n');
console.log('Commands:');
console.log('\t', command_jsonContent.name, '-', 'Print JSON content of the specified sdTF.');
}
function printJsonContentCommandInfo() {
console.log('Usage: sdtf <command>', 'command_jsonContent.name', '\n');
console.log('Fetch or read the specified sdTF file and print its JSON content.', '\n');
console.log('Options:');
console.log('\t', general.help.join(', '), '\t', 'Show help.');
console.log('\t', command_jsonContent.options.url.join(', '), '\t', 'Fetch sdTF from URL.', [
'string',
]);
console.log('\t', command_jsonContent.options.file.join(', '), '\t', 'Read sdTF from file.', [
'string',
]);
}
//# sourceMappingURL=cli.js.map