@puls-atlas/cli
Version:
The Puls Atlas CLI tool for managing Atlas projects
101 lines • 3.06 kB
JavaScript
import fs from 'fs';
import path from 'path';
import chalk from 'chalk';
import inquirer from 'inquirer';
import { logger, composer, npm } from './../../utils/index.js';
const installNpmDependencies = async (appDir, options) => {
const {
isConfirmed
} = await inquirer.prompt([{
type: 'confirm',
name: 'isConfirmed',
default: true,
message: `Do you want to install ${chalk.yellow('NPM')} dependencies for your ` + `${chalk.yellow('Atlas application')}?`
}]);
if (isConfirmed) {
const hasLockFile = fs.existsSync(path.join(appDir, 'package-lock.json'));
if (hasLockFile) {
logger.info('Lockfile detected.');
const {
installType
} = await inquirer.prompt([{
type: 'list',
name: 'installType',
default: 'lockfile',
message: 'Where do you want to install the NPM dependencies from?',
choices: [{
name: 'lockfile (recommended)',
value: 'lockfile',
short: 'lockfile'
}, {
name: 'package.json',
value: 'package.json',
short: 'package.json'
}]
}]);
if (installType === 'lockfile') {
return npm.cleanInstall(appDir, options);
}
} else {
logger.warning('No lockfile detected. Installing from package.json.');
}
return npm.install(appDir, options);
}
};
const installComposerDependencies = async (appDir, options) => {
const {
isConfirmed
} = await inquirer.prompt([{
type: 'confirm',
name: 'isConfirmed',
default: true,
message: 'Do you want to install ' + `${chalk.yellow('Composer dependencies')} for your ` + `${chalk.yellow('Atlas application')}?`
}]);
if (isConfirmed) {
const hasLockFile = fs.existsSync(path.join(appDir, 'package-lock.json'));
if (hasLockFile) {
logger.info('Lockfile detected.');
const {
installType
} = await inquirer.prompt([{
type: 'list',
name: 'installType',
default: 'install',
message: 'Where do you want to install the Composer dependencies from?',
choices: [{
name: 'lockfile (recommended)',
value: 'lockfile',
short: 'lockfile'
}, {
name: 'composer.json',
value: 'composer.json',
short: 'composer.json'
}]
}]);
if (installType === 'lockfile') {
return composer.install(options);
}
} else {
logger.warning('No lockfile detected. Installing from composer.json.');
}
return composer.update(options);
}
};
export default async ({
npm = false,
composer = false,
...options
}) => {
const appDir = path.join(process.cwd(), 'app');
if (!fs.existsSync(appDir)) {
logger.error('The /app directory does not exist. Make sure you are in the root directory of your project.');
}
if (npm || !composer) {
await installNpmDependencies(appDir, options);
}
if (composer || !npm) {
await installComposerDependencies(appDir, {
force: options.force ?? false
});
}
};