Skip to content

Commit

Permalink
prettier --write .
Browse files Browse the repository at this point in the history
  • Loading branch information
leoortizz committed May 21, 2024
1 parent 234dafc commit 5796757
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 75 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ Can also be extended like this:
```js
// .prettierrc.js
module.exports = {
...require('@monogram/prettier-config'),
tabWidth: 2,
useTabs: false,
overrides: [
{
files: '*.scss',
options: {
singleQuote: true,
tabWidth: 2,
useTabs: false,
printWidth: 160,
},
},
],
...require('@monogram/prettier-config'),
tabWidth: 2,
useTabs: false,
overrides: [
{
files: '*.scss',
options: {
singleQuote: true,
tabWidth: 2,
useTabs: false,
printWidth: 160,
},
},
],
}
```

Expand Down
14 changes: 7 additions & 7 deletions prettierrc.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/** @type {import('prettier').Config} */
module.exports = {
tabWidth: 2,
useTabs: true,
printWidth: 100,
singleQuote: true,
trailingComma: 'es5',
bracketSameLine: false,
semi: false,
tabWidth: 2,
useTabs: true,
printWidth: 100,
singleQuote: true,
trailingComma: 'es5',
bracketSameLine: false,
semi: false,
}
12 changes: 6 additions & 6 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ export const AVAILABLE_CONFIGS = ['next', 'node'] as const
export const PACKAGE_MANAGERS = ['yarn', 'pnpm', 'npm'] as const

export const LOCK_FILES: PackageManagerRecord = {
yarn: `${process.cwd()}/yarn.lock`,
pnpm: `${process.cwd()}/pnpm-lock.yaml`,
npm: `${process.cwd()}/package-lock.json`,
yarn: `${process.cwd()}/yarn.lock`,
pnpm: `${process.cwd()}/pnpm-lock.yaml`,
npm: `${process.cwd()}/package-lock.json`,
} as const

export const INSTALL_PREFIXES: PackageManagerRecord = {
yarn: 'yarn add -D',
pnpm: 'pnpm add -D',
npm: 'npm i -D',
yarn: 'yarn add -D',
pnpm: 'pnpm add -D',
npm: 'npm i -D',
} as const
38 changes: 19 additions & 19 deletions src/package-managers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,33 @@ import { LOCK_FILES, PACKAGE_MANAGERS } from './constants'
import type { PackageManager } from './types'

export async function choosePackageManager(): Promise<PackageManager> {
const packageManager = findPackageManager()
const packageManager = findPackageManager()

if (packageManager === undefined) {
return selectPackageManager()
}
if (packageManager === undefined) {
return selectPackageManager()
}

const useAutoDetected = await confirm({
message: `Auto-detected package manager. Use ${packageManager} for installation?`,
default: true,
})
const useAutoDetected = await confirm({
message: `Auto-detected package manager. Use ${packageManager} for installation?`,
default: true,
})

if (useAutoDetected === false) {
return selectPackageManager()
}
if (useAutoDetected === false) {
return selectPackageManager()
}

return packageManager
return packageManager
}

function findPackageManager(): PackageManager | undefined {
return PACKAGE_MANAGERS.find((packageManager) => existsSync(LOCK_FILES[packageManager]))
return PACKAGE_MANAGERS.find((packageManager) => existsSync(LOCK_FILES[packageManager]))
}

function selectPackageManager() {
return select({
message: 'Which package manager should be used for installation?',
choices: PACKAGE_MANAGERS.map((packageManager) => ({
value: packageManager,
})),
})
return select({
message: 'Which package manager should be used for installation?',
choices: PACKAGE_MANAGERS.map((packageManager) => ({
value: packageManager,
})),
})
}
44 changes: 22 additions & 22 deletions src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,38 @@ import { confirm } from '@inquirer/prompts'
init().catch(console.error)

async function init() {
const projectDir = process.cwd()
const packagePath = `${projectDir}/package.json`
const projectDir = process.cwd()
const packagePath = `${projectDir}/package.json`

if (!existsSync(packagePath)) {
throw Error(`Can't find package.json in ${projectDir}`)
}
if (!existsSync(packagePath)) {
throw Error(`Can't find package.json in ${projectDir}`)
}

const packageJson = require(packagePath)
const packageJson = require(packagePath)

if (packageJson.prettier) {
const yes = await confirm({
message: `'prettier' key (${packageJson.prettier}) found in package.json. Do you want to replace it?`,
})
if (packageJson.prettier) {
const yes = await confirm({
message: `'prettier' key (${packageJson.prettier}) found in package.json. Do you want to replace it?`,
})

if (yes === false) throw Error('Aborted')
}
if (yes === false) throw Error('Aborted')
}

packageJson.prettier = PACKAGE_NAME
packageJson.prettier = PACKAGE_NAME

const packageJsonString = JSON.stringify(packageJson, null, 2)
const packageJsonString = JSON.stringify(packageJson, null, 2)

const packageManager = await choosePackageManager()
await installDependencies(packageManager)
const packageManager = await choosePackageManager()
await installDependencies(packageManager)

await writeFile(packagePath, packageJsonString)
await writeFile(packagePath, packageJsonString)
}

async function installDependencies(packageManager: PackageManager) {
const installPrefix = INSTALL_PREFIXES[packageManager]
const installCommand = `${installPrefix} prettier ${PACKAGE_NAME}`
const installPrefix = INSTALL_PREFIXES[packageManager]
const installCommand = `${installPrefix} prettier ${PACKAGE_NAME}`

console.log(`📦 Installing dependencies...`)
console.log(`👉 ${installCommand}`)
execSync(installCommand, { stdio: 'inherit' })
console.log(`📦 Installing dependencies...`)
console.log(`👉 ${installCommand}`)
execSync(installCommand, { stdio: 'inherit' })
}
14 changes: 7 additions & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"compilerOptions": {
"esModuleInterop": true,
"outDir": "./dist",
"rootDir": "./src",
"module": "commonjs",
"compilerOptions": {
"esModuleInterop": true,
"outDir": "./dist",
"rootDir": "./src",
"module": "commonjs",
"baseUrl": ".",
"moduleResolution": "node"
}
"moduleResolution": "node"
}
}

0 comments on commit 5796757

Please sign in to comment.