-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(gatsby-cli): Convert util/configstore to typescript (#22180)
* chore(gatsby-cli): Convert util/configstore to typescript * Use configstore of gatsby-core-utils * Rename configstore to package-manager
- Loading branch information
Showing
3 changed files
with
36 additions
and
46 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 was deleted.
Oops, something went wrong.
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,35 @@ | ||
import { getConfigStore } from "gatsby-core-utils" | ||
import prompts from "prompts" | ||
import report from "../reporter" | ||
|
||
type PackageManager = "yarn" | "npm" | ||
|
||
const packageMangerConfigKey = `cli.packageManager` | ||
export const getPackageManager = (): PackageManager => | ||
getConfigStore().get(packageMangerConfigKey) | ||
export const setPackageManager = (packageManager: PackageManager): void => { | ||
getConfigStore().set(packageMangerConfigKey, packageManager) | ||
report.info(`Preferred package manager set to "${packageManager}"`) | ||
} | ||
|
||
export const promptPackageManager = async (): Promise<PackageManager> => { | ||
const promptsAnswer: { | ||
package_manager: PackageManager | ||
} = await prompts([ | ||
{ | ||
type: `select`, | ||
name: `package_manager`, | ||
message: `Which package manager would you like to use ?`, | ||
choices: [ | ||
{ title: `yarn`, value: `yarn` }, | ||
{ title: `npm`, value: `npm` }, | ||
], | ||
initial: 0, | ||
}, | ||
]) | ||
const response = promptsAnswer.package_manager | ||
if (response) { | ||
setPackageManager(response) | ||
} | ||
return response | ||
} |