Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support "yarn create qawolf" #529

Merged
merged 3 commits into from Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 16 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 @@ -15,12 +15,19 @@ export const logError = (error: Error): void => {
}
};

export const logNpmInstall = (packages: Packages): void => {
export const logInstallDependencies = (
packages: Packages,
isYarn = 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(
`${isYarn ? 'yarn add' : 'npm install --save-dev'} ${name}@${version}`,
),
);
});
};

Expand All @@ -34,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
19 changes: 11 additions & 8 deletions packages/create-qawolf/src/index.ts
Expand Up @@ -2,18 +2,19 @@
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 { detectTypeScript, detectYarn, writeConfig } from './config';
import {
addDevDependencies,
installDependencies,
readPackageJson,
} from './packageJson';

(async (): Promise<void> => {
try {
// create a new line for yarn create
console.log();

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

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

const packages = await addDevDependencies(useTypeScript);
logNpmInstall(packages);
npmInstall();

const isYarn = detectYarn();
logInstallDependencies(packages, isYarn);
installDependencies(isYarn);
} 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' });
};