Skip to content

Commit

Permalink
chore(gatsby-cli): Convert util/configstore to typescript (#22180)
Browse files Browse the repository at this point in the history
* chore(gatsby-cli): Convert util/configstore to typescript

* Use configstore of gatsby-core-utils

* Rename configstore to package-manager
  • Loading branch information
mottox2 authored Mar 11, 2020
1 parent b8862be commit d90dad0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 46 deletions.
2 changes: 1 addition & 1 deletion packages/gatsby-cli/src/init-starter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import prompts from "prompts"
import url from "url"

import report from "./reporter"
import { getPackageManager, promptPackageManager } from "./util/configstore"
import { getPackageManager, promptPackageManager } from "./util/package-manager"
import isTTY from "./util/is-tty"

const spawnWithArgs = (
Expand Down
45 changes: 0 additions & 45 deletions packages/gatsby-cli/src/util/configstore.js

This file was deleted.

35 changes: 35 additions & 0 deletions packages/gatsby-cli/src/util/package-manager.ts
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
}

0 comments on commit d90dad0

Please sign in to comment.