UNPKG

@ooit/media-tools

Version:

Various media tools: smart archive and more.

100 lines 4.42 kB
#!/usr/bin/env node "use strict"; 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()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.mediatools = void 0; const command_line_args_1 = __importDefault(require("command-line-args")); const archive_1 = require("./archive"); const info_1 = require("./info"); const command_line_usage_1 = __importDefault(require("command-line-usage")); const mainDefinitions = [ { name: 'command', defaultOption: true }, { name: 'dryrun', type: Boolean, defaultOption: false }, // { name: 'archive', type: Boolean }, // { name: 'test', type: Boolean }, { name: 'src', type: String }, { name: 'dest', type: String } ]; function mediatools() { return __awaiter(this, void 0, void 0, function* () { const mainOptions = (0, command_line_args_1.default)(mainDefinitions, { stopAtFirstUnknown: false }); try { /* second - parse the merge command options */ const args = mainOptions._unknown; switch (mainOptions.command) { case 'test': { console.log(mainOptions); return mainOptions; } case 'info': { if (args.length !== 1) { console.error('Expect one file as parameter!'); return 1; } else { yield (0, info_1.info)(args[0]); } return 0; } case 'archive': { const { src, dest, dryrun } = mainOptions; yield (0, archive_1.archive)({ src, dest, dryrun }); return 0; } case 'help': default: { const usage = (0, command_line_usage_1.default)([ { header: 'Welcome to media-tools', content: 'media-tools provides some specific and hopefully useful commands for media files.' }, { header: 'Command List', content: [ { name: '{bold archive}', summary: 'Archive all media files from a source folder to a destination folder.' }, { name: '{bold help}', summary: 'Get this help information.' } ] }, { header: 'Options for {underline archive}', optionList: [ { name: 'src', typeLabel: '{underline src} ', description: 'Source folder' }, { name: 'dest', typeLabel: '{underline dest} ', description: 'Destination folder' } ] } ]); console.log(usage); return 0; } } } catch (e) { console.error('Error occurred:', e); } return 1; }); } exports.mediatools = mediatools; //# sourceMappingURL=mediatools.js.map