UNPKG

flexmonster-cli

Version:

CLI for Flexmonster Pivot Table & Charts installation

105 lines (92 loc) 3.59 kB
import { Command } from 'commander'; import escExit from 'esc-exit'; import inquirer from 'inquirer'; import { initCreateCommand, helpCreate } from './command/create.js'; import { initAddCommand, helpAdd } from './command/add.js'; import { initUpdateCommand, helpUpdate } from './command/update.js'; import { initVersionCommand, executeVersion } from './command/version.js'; import { initHelpCommand, executeHelp } from './command/help.js'; import { listChoices } from './utils.js'; export const VERSION = '2.9.73'; export const COMMANDS = [{ name: 'create', description: 'creates a sample project with Flexmonster Pivot', }, { name: 'add', description: 'adds Flexmonster Pivot, framework wrappers, or Theme Builder to your project, installs Flexmonster Data Server (FDS), or Flexmonster Accelerator for SSAS', }, { name: 'update', description: 'updates Flexmonster Pivot, framework wrappers, FDS, or the Accelerator for SSAS', }, { name: 'version', description: 'outputs the current version', }, { name: 'help', description: 'outputs usage information', } ]; const Q_COMMAND = [{ type: 'list', name: 'command', message: 'Choose a command to execute:', choices: listChoices(COMMANDS) }]; var runInquirer = true; export function commandInAction() { runInquirer = false; } export const program = new Command(); function initCommands() { program.version(VERSION, '-v, --version', 'output the current version') .showHelpAfterError() .showSuggestionAfterError(); initCreateCommand(); initAddCommand(); initUpdateCommand(); initVersionCommand(); initHelpCommand(); } function isKnownOption(option){ return option == '-r' || option == '--run' || option == '-i' || option == '--install'|| option == '-h'|| option == '--help'|| option == '-v'|| option == '--version'; } export function cli(args) { initCommands(); let unknownOption = args.find(arg => arg.startsWith('-') && !(isKnownOption(arg))); if(unknownOption !== undefined){ console.log(''); console.log('~ unknown option: %s', unknownOption); console.log(''); executeHelp(); }else{ if (args && args[2] !== undefined) program.parse(args); if (runInquirer) { escExit(); inquirer.prompt(Q_COMMAND) .then(function (answers) { if (answers["command"] == COMMANDS[0].name) { // create helpCreate(); } else if (answers["command"] == COMMANDS[1].name) { // add helpAdd(); } else if (answers["command"] == COMMANDS[2].name) { // update helpUpdate(); } else if (answers["command"] == COMMANDS[3].name) { // version executeVersion() } else if (answers["command"] == COMMANDS[4].name) { // help executeHelp(); } }) .catch(function (error) { if (error) { console.log("Got in error") // Prompt couldn't be rendered in the current environment // Something when wrong } }); } } } export const tempDirURL = './tmp-unpack-fm-cli';