UNPKG

@puls-atlas/cli

Version:

The Puls Atlas CLI tool for managing Atlas projects

47 lines 1.3 kB
import fs from 'fs'; import inquirer from 'inquirer'; import { rimraf } from 'rimraf'; import logger from './logger.js'; import execSync from './execSync.js'; const install = async (cwd, options = {}) => { const hasNodeModules = fs.existsSync(`${cwd}/node_modules`); const hasLockFile = fs.existsSync(`${cwd}/package-lock.json`); const { removeNodeModules = false } = hasNodeModules ? await inquirer.prompt([{ type: 'confirm', name: 'removeNodeModules', default: false, message: 'Do you want to perform an install with a fresh node_modules directory?' }]) : {}; if (removeNodeModules) { const removingLockFile = logger.spinner('Removing node_modules directory...'); try { rimraf.sync(`${cwd}/node_modules`); if (hasLockFile) { rimraf.sync(`${cwd}/package-lock.json`); } removingLockFile.succeed('Removed node_modules directory.'); } catch (error) { removingLockFile.fail('Failed to remove node_modules directory.'); } } try { return execSync('npm i', { ...options, cwd }); } catch (error) {} }; const cleanInstall = async (cwd, options = {}) => { try { return execSync('npm ci', { ...options, cwd }); } catch (error) {} }; export default { install, cleanInstall };