flexmonster-cli
Version:
CLI for Flexmonster Pivot Table & Charts installation
44 lines (41 loc) • 1.43 kB
JavaScript
import {
commandInAction,
COMMANDS,
VERSION,
program
} from '../cli.js';
import chalk from 'chalk';
import boxen from 'boxen';
import { exec } from 'child_process';
export function executeVersion() {
commandInAction();
console.log(VERSION);
notifyIfNewVersionAvailable();
}
export function notifyIfNewVersionAvailable() {
exec("npm view flexmonster-cli version",
function (error, stdout, stderr) {
const latestVersion = stdout.trim();
if (VERSION !== latestVersion) {
console.log(boxen(`A new version of ${chalk.yellowBright("flexmonster-cli")} is available: ${chalk.redBright(VERSION)} -> ${chalk.greenBright(latestVersion)}\n\nRun ${chalk.yellowBright("npm install flexmonster-cli -g")} to update.`, {
borderColor: "yellow",
padding: 1,
float: "center",
align: "center"
}));
}
});
}
export function initVersionCommand() {
program.command('version') // sub-command name
.alias('v') // alternative sub-command
.description(COMMANDS[3].description) // command description
.action(function () { // function to execute when command is used
executeVersion();
})
.addHelpText('after', `
Examples:
flexmonster version
flexmonster v
`);
}