Skip to content

Commit

Permalink
fix get lock file
Browse files Browse the repository at this point in the history
  • Loading branch information
sottar committed Feb 14, 2020
1 parent d1c2dc5 commit 0fbc835
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { ExecException } from 'child_process';
const exec = require('child_process').exec;

const convertCommandToYarn = (command: string, options: Array<string>): string => {
if (!command) {
return 'install';
}

if (command === 'install' && options.length > 0) {
return 'add';
}
Expand All @@ -22,12 +26,12 @@ const convertCommandToNpm = (command: string): string => {
if (command === 'remove') {
return 'uninstall';
}
return command;
return `run ${command}`;
};

((): void => {
const npmLockFile = path.resolve(__dirname, '..', 'package-lock.json');
const yarnLockFile = path.resolve(__dirname, '..', 'yarn.lock');
const npmLockFile = 'package-lock.json';
const yarnLockFile = 'yarn.lock';
const isNpmExisted = fs.existsSync(npmLockFile);
const isYarnExisted = fs.existsSync(yarnLockFile);
if (isNpmExisted && isYarnExisted) {
Expand All @@ -43,7 +47,8 @@ const convertCommandToNpm = (command: string): string => {

const npmCommand = convertCommandToNpm(command);

console.log(chalk.gray(`npm ${npmCommand} ${options.join(' ')}`));
console.log('');
console.log(chalk.gray(`> npm ${npmCommand} ${options.join(' ')}`));

exec(`npm ${npmCommand} ${options.join(' ')}`, (err: ExecException, stdout: string, stderr: string) => {
if (err) {
Expand All @@ -57,10 +62,8 @@ const convertCommandToNpm = (command: string): string => {
console.log(chalk.green('yarn.lock is found, use yarn...'));

const yarnCommand = convertCommandToYarn(command, options);
console.log(
chalk.green(`
> yarn ${yarnCommand} ${options.join(' ')}`),
);
console.log('');
console.log(chalk.green(`> yarn ${yarnCommand} ${options.join(' ')}`));

exec(`yarn ${yarnCommand} ${options.join(' ')}`, (err: ExecException, stdout: string, stderr: string) => {
if (err) {
Expand Down

0 comments on commit 0fbc835

Please sign in to comment.