-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eaed0ac
commit c0c26ed
Showing
6 changed files
with
58 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
export const PACKAGE_NAME = "@monogram/eslint-config" | ||
export const PACKAGE_NAME = '@monogram/eslint-config' | ||
|
||
export const ESLINT_FILENAME = '.eslintrc.js' | ||
export const ESLINT_FILENAME = '.eslintrc.js' | ||
|
||
export const availableConfigs = ["next", "node"] as const | ||
export type AvailableConfig = typeof availableConfigs[number] | ||
export const AVAILABLE_CONFIGS = ['next', 'node'] as const | ||
export type AvailableConfig = (typeof AVAILABLE_CONFIGS)[number] | ||
|
||
export const packageManagers = ['yarn', 'pnpm', 'npm'] as const | ||
export type PackageManager = typeof packageManagers[number] | ||
export const PACKAGE_MANAGERS = ['yarn', 'pnpm', 'npm'] as const | ||
export type PackageManager = (typeof PACKAGE_MANAGERS)[number] | ||
|
||
type PackageManagerMap = Record<PackageManager, string> | ||
type PackageManagerRecord = Record<PackageManager, string> | ||
|
||
export const lockFiles: PackageManagerMap = { | ||
export const LOCK_FILES: PackageManagerRecord = { | ||
yarn: `${process.cwd()}/yarn.lock`, | ||
pnpm: `${process.cwd()}/pnpm-lock.yaml`, | ||
npm: `${process.cwd()}/package-lock.json` | ||
} as const | ||
|
||
export const installPrefixes: PackageManagerMap = { | ||
export const INSTALL_PREFIXES: PackageManagerRecord = { | ||
yarn: 'yarn add -D', | ||
pnpm: 'pnpm add -D', | ||
npm: 'npm i -D' | ||
} as const | ||
} as const |
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,32 +1,35 @@ | ||
import { existsSync } from "node:fs" | ||
import { select, confirm } from "@inquirer/prompts" | ||
import { PackageManager, lockFiles, packageManagers } from "./constants" | ||
import { existsSync } from 'node:fs' | ||
import { select, confirm } from '@inquirer/prompts' | ||
import { PackageManager, LOCK_FILES, PACKAGE_MANAGERS } from './constants' | ||
|
||
export default async function choosePackageManager(): Promise<PackageManager> { | ||
const pm = findPackageManager() | ||
const packageManager = findPackageManager() | ||
|
||
if (pm === undefined) { | ||
if (packageManager === undefined) { | ||
return selectPackageManager() | ||
} | ||
|
||
const usePm = await confirm({ message: `Auto-detected package manager. Use ${pm} for installation?`, default: true }) | ||
const useAutoDetected = await confirm({ | ||
message: `Auto-detected package manager. Use ${packageManager} for installation?`, | ||
default: true | ||
}) | ||
|
||
if (usePm === false) { | ||
if (useAutoDetected === false) { | ||
return selectPackageManager() | ||
} | ||
|
||
return pm | ||
return packageManager | ||
} | ||
|
||
function findPackageManager(): PackageManager | undefined { | ||
return packageManagers.find((pm) => existsSync(lockFiles[pm])) | ||
return PACKAGE_MANAGERS.find((packageManager) => existsSync(LOCK_FILES[packageManager])) | ||
} | ||
|
||
function selectPackageManager() { | ||
return select({ | ||
message: 'Select a package manager you would like to use for the install', | ||
choices: packageManagers.map((pm) => ({ | ||
value: pm | ||
})), | ||
}); | ||
} | ||
choices: PACKAGE_MANAGERS.map((packageManager) => ({ | ||
value: packageManager | ||
})) | ||
}) | ||
} |