Skip to content

Commit

Permalink
support "yarn create qawolf --yarn"
Browse files Browse the repository at this point in the history
  • Loading branch information
jperl committed Mar 20, 2020
1 parent 6650185 commit 0fef046
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
11 changes: 9 additions & 2 deletions packages/create-qawolf/src/cli.ts
Expand Up @@ -15,12 +15,19 @@ export const logError = (error: Error): void => {
}
};

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

Object.keys(packages).forEach(name => {
const version = packages[name];
console.log(cyan(`npm install --save-dev ${name}@${version}`));
console.log(
cyan(
`${useYarn ? 'yarn add' : 'npm install --save-dev'} ${name}@${version}`,
),
);
});
};

Expand Down
16 changes: 12 additions & 4 deletions packages/create-qawolf/src/index.ts
Expand Up @@ -2,15 +2,22 @@
import { install as installCi } from 'playwright-ci';
import {
logError,
logNpmInstall,
logInstallDependencies,
logUseTypeScript,
promptRootDir,
} from './cli';
import { detectTypeScript, writeConfig } from './config';
import { addDevDependencies, readPackageJson, npmInstall } from './packageJson';
import {
addDevDependencies,
readPackageJson,
installDependencies,
} from './packageJson';

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

// const isYarn = '';
// create a new line for yarn create
console.log();

Expand All @@ -27,8 +34,9 @@ import { addDevDependencies, readPackageJson, npmInstall } from './packageJson';
await writeConfig({ rootDir, useTypeScript });

const packages = await addDevDependencies(useTypeScript);
logNpmInstall(packages);
npmInstall();
logInstallDependencies(packages, useYarn);

installDependencies(useYarn);
} catch (error) {
logError(error);
process.exit(1);
Expand Down
4 changes: 2 additions & 2 deletions packages/create-qawolf/src/packageJson.ts
Expand Up @@ -76,6 +76,6 @@ export const addDevDependencies = async (
return packages;
};

export const npmInstall = (): void => {
execSync('npm install', { stdio: 'inherit' });
export const installDependencies = (useYarn = false): void => {
execSync(useYarn ? 'yarn' : 'npm install', { stdio: 'inherit' });
};

0 comments on commit 0fef046

Please sign in to comment.