Skip to content

Commit

Permalink
Support yarn 🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimyr committed Jun 5, 2019
1 parent f47c605 commit a47b67b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 16 deletions.
19 changes: 12 additions & 7 deletions lib/out/install-packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,29 @@ function install(packages, currentState) {
}

const installer = currentState.get('installer');
const installGlobal = currentState.get('global') ? '--global' : null;
const saveExact = currentState.get('saveExact') ? '--save-exact' : null;
const saveExact = currentState.get('saveExact')

const isYarn = installer === 'yarn';
const exact = saveExact ? (isYarn ? '--exact' : '--save-exact') : null;
const color = chalk.supportsColor ? '--color=always' : null;

const npmArgs = ['install']
.concat(installGlobal)
.concat(saveExact)
const install = [isYarn ? 'add' : 'install'];
if (currentState.get('global')) {
isYarn ? install.unshift('global') : install.push('--global');
}
const args = install
.concat(packages)
.concat(exact)
.concat(color)
.filter(Boolean);

console.log('');
console.log(`$ ${chalk.green(installer)} ${chalk.green(npmArgs.join(' '))}`);
console.log(`$ ${chalk.green(installer)} ${chalk.green(args.join(' '))}`);
const spinner = ora(`Installing using ${chalk.green(installer)}...`);
spinner.enabled = spinner.enabled && currentState.get('spinner');
spinner.start();

return execa(installer, npmArgs, {cwd: currentState.get('cwd')}).then(output => {
return execa(installer, args, {cwd: currentState.get('cwd')}).then(output => {
spinner.stop();
console.log(output.stdout);
console.log(output.stderr);
Expand Down
8 changes: 6 additions & 2 deletions lib/out/interactive-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,17 @@ function interactive(currentState) {
const updatedPackages = packagesToUpdate
.map(pkg => pkg.moduleName + '@' + pkg.latest).join(', ');

const isYarn = currentState.get('installer') === 'yarn';

if (!currentState.get('global')) {
if (saveDependencies.length) {
saveDependencies.unshift('--save');
!isYarn && saveDependencies.push('--save');
}

if (saveDevDependencies.length) {
saveDevDependencies.unshift('--save-dev');
isYarn
? saveDevDependencies.push('--dev')
: saveDevDependencies.push('--save-dev');
}
}

Expand Down
18 changes: 16 additions & 2 deletions lib/out/static-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,22 @@ function render(pkg, currentState) {
const rows = [];

const indent = ' ' + emoji(' ');
const flags = currentState.get('global') ? '--global' : `--save${pkg.devDependency ? '-dev' : ''}`;
const upgradeCommand = `npm install ${flags} ${packageName}@${pkg.latest}`;
const installer = currentState.get('installer');
const isYarn = installer === 'yarn';

const args = [isYarn ? 'add' : 'install'];
if (currentState.get('global')) {
isYarn ? args.unshift('global') : args.push('--global');
}

const flags = [];
if (isYarn) {
pkg.devDependency && flags.push('--dev');
} else {
pkg.devDependency ? flags.push('--save-dev') : flags.push('--save');
}

const upgradeCommand = `${installer} ${args.join(' ')} ${packageName}@${pkg.latest} ${flags.join(' ')}`;
const upgradeMessage = `${chalk.green(upgradeCommand)} to go from ${pkg.installed} to ${pkg.latest}`;
// DYLAN: clean this up
const status = _([
Expand Down
11 changes: 6 additions & 5 deletions lib/out/update-all.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
'use strict';

const _ = require('lodash');
const inquirer = require('inquirer');
const chalk = require('chalk');
const table = require('text-table');
const installPackages = require('./install-packages');
const emoji = require('./emoji');

Expand Down Expand Up @@ -32,13 +29,17 @@ function updateAll(currentState) {
const updatedPackages = packagesToUpdate
.map(pkg => pkg.moduleName + '@' + pkg.latest).join(', ');

const isYarn = currentState.get('installer') === 'yarn';

if (!currentState.get('global')) {
if (saveDependencies.length) {
saveDependencies.unshift('--save');
!isYarn && saveDependencies.push('--save');
}

if (saveDevDependencies.length) {
saveDevDependencies.unshift('--save-dev');
isYarn
? saveDevDependencies.push('--dev')
: saveDevDependencies.push('--save-dev');
}
}

Expand Down

0 comments on commit a47b67b

Please sign in to comment.