@arc-fusion/cli
Version:
CLI for running Arc Fusion on your local machine
87 lines (73 loc) • 2.33 kB
JavaScript
const semver = require('semver')
const Box = require('cli-box')
const chalk = require('chalk')
const {
name: packageName,
version: installedVersion
} = require('../../package.json')
const { exec } = require('../utils/promises')
const { FUSION_RELEASE } = require('../environment')
async function getLatest () {
const { stdout: latestVersion } = await exec(
`npm view ${packageName} version`
)
return latestVersion.trim()
}
async function printFusionCliNotice (installedPadded, latestVersion) {
const latestPadded = `${latestVersion}`.padStart(12, ' ')
const shouldWarningShow =
FUSION_RELEASE &&
(FUSION_RELEASE === 'latest' || semver.lt(FUSION_RELEASE.replace(/-.*$/, ''), '7.0.0'))
const warningLine = chalk.bgYellowBright.bold(
`\nWARNING: ${latestVersion} is compatible with Engine 7 and higher!`
)
const lines = [
`You are using Fusion CLI version: ${installedPadded}`,
`The latest Fusion CLI version is: ${latestPadded}`,
...(shouldWarningShow ? [warningLine] : []),
...(shouldWarningShow
? ['Engine 7 upgrade guide: https://arcxp.com/go/fcli\n']
: []),
'Please consider updating by running:',
'> npm install --save-dev @arc-fusion/cli@latest'
]
const innerWidth = Math.max(
/* eslint-disable no-control-regex */
...lines.map((l) => l.replace(/\x1B\[[0-9;]*m/g, '').length)
)
const padX = 1
const padY = 0
const padRight = (s, target) =>
s +
/* eslint-disable no-control-regex */
' '.repeat(Math.max(0, target - s.replace(/\x1B\[[0-9;]*m/g, '').length))
const content =
'\n'.repeat(padY) +
lines
.map((l) => ' '.repeat(padX) + padRight(l, innerWidth) + ' '.repeat(padX))
.join('\n') +
'\n'.repeat(padY)
const width = innerWidth + padX * 2 + 2
const height = lines.length + padY * 2 + 2
const box = Box(`${width}x${height}`, content, {
marks: {
nw: '+',
n: '-',
ne: '+',
e: '|',
se: '+',
s: '-',
sw: '+',
w: '|'
}
})
console.warn('\n' + box + '\n')
}
module.exports = async () => {
const latestVersion = await getLatest()
if (latestVersion !== installedVersion) {
const installedPadded = `${installedVersion}`.padStart(12, ' ')
printFusionCliNotice(installedPadded, latestVersion)
}
}