Skip to content

Commit

Permalink
detect yarn
Browse files Browse the repository at this point in the history
  • Loading branch information
jperl committed Mar 20, 2020
1 parent 8b970aa commit 9331124
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
14 changes: 9 additions & 5 deletions packages/create-qawolf/src/cli.ts
@@ -1,5 +1,5 @@
import input from '@inquirer/input';
import { cyan, bold } from 'kleur';
import { bold, cyan } from 'kleur';
import { getPackageJsonPath } from './packageJson';
import { Packages } from './types';

Expand All @@ -17,15 +17,15 @@ export const logError = (error: Error): void => {

export const logInstallDependencies = (
packages: Packages,
useYarn = false,
isYarn = false,
): void => {
console.log(cyan(`Installing dependencies`));

Object.keys(packages).forEach(name => {
const version = packages[name];
console.log(
cyan(
`${useYarn ? 'yarn add' : 'npm install --save-dev'} ${name}@${version}`,
`${isYarn ? 'yarn add' : 'npm install --save-dev'} ${name}@${version}`,
),
);
});
Expand All @@ -41,8 +41,12 @@ export const logUseTypeScript = (useTypeScript: boolean): void => {
);
};

export const promptRootDir = (): Promise<string> =>
input({
export const promptRootDir = (): Promise<string> => {
// create a line break before our CLI prompt
console.log();

return input({
message: 'rootDir: Directory to create tests in',
default: '.qawolf',
});
};
3 changes: 3 additions & 0 deletions packages/create-qawolf/src/config.ts
Expand Up @@ -17,6 +17,9 @@ export const detectTypeScript = async (): Promise<boolean> => {
});
};

export const detectYarn = (): boolean =>
(process.env.npm_execpath || '').includes('yarn');

export const writeConfig = async ({
rootDir,
useTypeScript,
Expand Down
13 changes: 4 additions & 9 deletions packages/create-qawolf/src/index.ts
Expand Up @@ -6,7 +6,7 @@ import {
logUseTypeScript,
promptRootDir,
} from './cli';
import { detectTypeScript, writeConfig } from './config';
import { detectTypeScript, detectYarn, writeConfig } from './config';
import {
addDevDependencies,
readPackageJson,
Expand All @@ -15,11 +15,6 @@ import {

(async (): Promise<void> => {
try {
const useYarn = process.argv[process.argv.length - 1] === '--yarn';

// create a new line for yarn create
console.log();

// run this first to ensure package.json
await readPackageJson();

Expand All @@ -34,9 +29,9 @@ import {

const packages = await addDevDependencies(useTypeScript);

logInstallDependencies(packages, useYarn);

installDependencies(useYarn);
const isYarn = detectYarn();
logInstallDependencies(packages, isYarn);
installDependencies(isYarn);
} catch (error) {
logError(error);
process.exit(1);
Expand Down

0 comments on commit 9331124

Please sign in to comment.