-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Ask for package manager when is JS project
- Loading branch information
Showing
14 changed files
with
376 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
const isNil = require('lodash/isNil') | ||
|
||
module.exports = projectInfos => ({ | ||
type: 'input', | ||
message: '📦 Install command (use empty value to skip)', | ||
name: 'installCommand', | ||
default: projectInfos.isJSProject ? 'npm install' : undefined | ||
default: answers => { | ||
const packageManager = answers.packageManager || projectInfos.packageManager | ||
return isNil(packageManager) ? undefined : `${packageManager} install` | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,34 @@ | ||
const askInstallCommand = require('./install-command') | ||
|
||
describe('askInstallCommand', () => { | ||
it('should return correct question format when project lang is js', () => { | ||
const projectInfos = { isJSProject: true } | ||
const result = askInstallCommand(projectInfos) | ||
it('should return correct question format', () => { | ||
const result = askInstallCommand() | ||
expect(result).toEqual( | ||
expect.objectContaining({ | ||
type: 'input', | ||
message: '📦 Install command (use empty value to skip)', | ||
name: 'installCommand' | ||
}) | ||
) | ||
}) | ||
|
||
it('should return undefined default answer when package manager is not defined', () => { | ||
const projectInfos = {} | ||
|
||
expect(result).toEqual({ | ||
type: 'input', | ||
message: '📦 Install command (use empty value to skip)', | ||
name: 'installCommand', | ||
default: 'npm install' | ||
const result = askInstallCommand(projectInfos).default({ | ||
packageManager: undefined | ||
}) | ||
|
||
expect(result).toBeUndefined() | ||
}) | ||
|
||
it('should return correct question format when project lang is not js', () => { | ||
const projectInfos = { isJSProject: false } | ||
const result = askInstallCommand(projectInfos) | ||
it('should return correct default answer when package manager is defined', () => { | ||
const projectInfos = {} | ||
|
||
expect(result).toEqual({ | ||
type: 'input', | ||
message: '📦 Install command (use empty value to skip)', | ||
name: 'installCommand', | ||
default: undefined | ||
const result = askInstallCommand(projectInfos).default({ | ||
packageManager: 'yarn' | ||
}) | ||
|
||
expect(result).toEqual('yarn install') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const isEmpty = require('lodash/isEmpty') | ||
|
||
module.exports = projectInfos => ({ | ||
type: 'list', | ||
message: '📦 Choose Package Manager ', | ||
name: 'packageManager', | ||
choices: [ | ||
{ | ||
name: 'npm', | ||
value: 'npm' | ||
}, | ||
{ | ||
name: 'yarn', | ||
value: 'yarn' | ||
} | ||
], | ||
when: () => projectInfos.isJSProject && isEmpty(projectInfos.packageManager) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const askPackageManager = require('./package-manager') | ||
|
||
const expectedQuestion = { | ||
type: 'list', | ||
message: '📦 Choose Package Manager ', | ||
name: 'packageManager', | ||
choices: [ | ||
{ | ||
name: 'npm', | ||
value: 'npm' | ||
}, | ||
{ | ||
name: 'yarn', | ||
value: 'yarn' | ||
} | ||
] | ||
} | ||
|
||
describe('askPackageManager', () => { | ||
it('should return correct question format when package manager is undefined', () => { | ||
const projectInfos = { packageManager: undefined } | ||
const result = askPackageManager(projectInfos) | ||
|
||
expect(result).toEqual(expect.objectContaining(expectedQuestion)) | ||
}) | ||
|
||
it('should not show question for a non JS Project', () => { | ||
const projectInfos = { isJSProject: false, packageManager: undefined } | ||
const result = askPackageManager(projectInfos).when(projectInfos) | ||
|
||
expect(result).toBe(false) | ||
}) | ||
|
||
it('should not show question when package manager has already been detected', () => { | ||
const projectInfos = { isJSProject: true, packageManager: 'yarn' } | ||
const result = askPackageManager(projectInfos).when(projectInfos) | ||
|
||
expect(result).toBe(false) | ||
}) | ||
|
||
it('should show question when package manager is undefined and if project is JS', () => { | ||
const projectInfos = { isJSProject: true, packageManager: undefined } | ||
const result = askPackageManager(projectInfos).when(projectInfos) | ||
|
||
expect(result).toBe(true) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
const isNil = require('lodash/isNil') | ||
|
||
module.exports = projectInfos => ({ | ||
type: 'input', | ||
message: '✅ Test command (use empty value to skip)', | ||
name: 'testCommand', | ||
default: projectInfos.testCommand | ||
default: answers => { | ||
const packageManager = answers.packageManager || projectInfos.packageManager | ||
return projectInfos.hasTestCommand && !isNil(packageManager) | ||
? `${packageManager} run test` | ||
: undefined | ||
} | ||
}) |
Oops, something went wrong.