UNPKG

@puls-atlas/cli

Version:

The Puls Atlas CLI tool for managing Atlas projects

94 lines 2.48 kB
import path from 'path'; import chalk from 'chalk'; import inquirer from 'inquirer'; import { logger } from '../../utils/logger.js'; export const LOCKFILE_INSTALL_SOURCE = 'lockfile'; export const MANIFEST_INSTALL_SOURCE = 'manifest'; export const formatInstallTargetLabel = (rootDir, targetDir) => { const relativePath = path.relative(rootDir, targetDir).split(path.sep).join('/'); if (relativePath.length === 0) { return 'project root'; } if (relativePath.startsWith('..')) { return targetDir.split(path.sep).join('/'); } return `/${relativePath}`; }; export const confirmDependencyInstall = async ({ allYes = false, dependencyLabel, promptImpl = inquirer.prompt, subjectLabel, targetLabel }) => { if (allYes) { return true; } const { isConfirmed } = await promptImpl([{ type: 'confirm', name: 'isConfirmed', default: true, message: 'Continue installing ' + `${chalk.yellow(`${dependencyLabel} dependencies`)} ` + 'for your ' + `${chalk.yellow(subjectLabel)} ` + `in ${chalk.cyan(targetLabel)}?` }]); return isConfirmed; }; export const selectInstallSource = async ({ allYes = false, dependencyLabel, lockfileChoiceLabel, manifestChoiceLabel, promptImpl = inquirer.prompt, targetLabel }) => { if (allYes) { return LOCKFILE_INSTALL_SOURCE; } const { installSource } = await promptImpl([{ type: 'select', name: 'installSource', default: LOCKFILE_INSTALL_SOURCE, message: `Select how to resolve the ${chalk.yellow(dependencyLabel)} dependencies ` + `for ${chalk.cyan(targetLabel)}:`, loop: false, choices: [{ name: lockfileChoiceLabel, value: LOCKFILE_INSTALL_SOURCE, short: 'lockfile' }, { name: manifestChoiceLabel, value: MANIFEST_INSTALL_SOURCE, short: 'manifest' }] }]); return installSource; }; const normalizeSummaryRows = rows => { const resolvedRows = Array.isArray(rows) ? rows : [rows]; return resolvedRows.filter(Boolean); }; export const outputInstallSummary = ({ dependencyLabel, extraRows = [], loggerImpl = logger, sourceLabel, targetLabel }) => { loggerImpl.summary('Install plan', [{ label: 'Package Manager', value: dependencyLabel, tone: 'warning' }, { label: 'Directory', value: targetLabel, tone: 'accent' }, ...normalizeSummaryRows(extraRows), { label: 'Source', value: sourceLabel, tone: 'warning' }], { spacing: 'after' }); };