|
| 1 | +import * as chalk from 'chalk'; |
| 2 | +import {exec} from 'child_process'; |
| 3 | + |
| 4 | +import {CliConfig} from '../models/config'; |
| 5 | + |
| 6 | +const Promise = require('../ember-cli/lib/ext/promise'); |
| 7 | +const config = CliConfig.fromProject(); |
| 8 | + |
| 9 | +const execPromise = Promise.denodeify(exec); |
| 10 | + |
| 11 | +let packageManager = 'npm'; |
| 12 | +if (config && config.get('packageManager')) { |
| 13 | + packageManager = config.get('packageManager'); |
| 14 | +} |
| 15 | + |
| 16 | +export function checkYarnOrCNPM() { |
| 17 | + return Promise |
| 18 | + .all([checkYarn(), checkCNPM()]) |
| 19 | + .then((data: Array<boolean>) => { |
| 20 | + if (packageManager === 'npm') { |
| 21 | + const [isYarnInstalled, isCNPMInstalled] = data; |
| 22 | + if (isYarnInstalled && isCNPMInstalled) { |
| 23 | + console.log(chalk.yellow('you can `ng set --global packageManager=yarn` ' + |
| 24 | + 'or `ng set --global packageManager=cnpm`')); |
| 25 | + } else if (isYarnInstalled) { |
| 26 | + console.log(chalk.yellow('you can `ng set --global packageManager=yarn`')); |
| 27 | + } else if (isCNPMInstalled) { |
| 28 | + console.log(chalk.yellow('you can `ng set --global packageManager=cnpm`')); |
| 29 | + } |
| 30 | + } |
| 31 | + }); |
| 32 | +} |
| 33 | + |
| 34 | +function checkYarn() { |
| 35 | + return execPromise('yarn --version') |
| 36 | + .then(() => true, () => false); |
| 37 | +} |
| 38 | + |
| 39 | +function checkCNPM() { |
| 40 | + return execPromise('cnpm --version') |
| 41 | + .then(() => true, () => false); |
| 42 | +} |
0 commit comments