From 5796757d5cb559ab257b2d17c40506bc95410538 Mon Sep 17 00:00:00 2001 From: Leonardo Ortiz Date: Tue, 21 May 2024 13:04:48 -0300 Subject: [PATCH] prettier --write . --- README.md | 28 +++++++++++++------------- prettierrc.config.js | 14 ++++++------- src/constants.ts | 12 +++++------ src/package-managers.ts | 38 +++++++++++++++++------------------ src/setup.ts | 44 ++++++++++++++++++++--------------------- tsconfig.json | 14 ++++++------- 6 files changed, 75 insertions(+), 75 deletions(-) diff --git a/README.md b/README.md index 5ab98d8..b4186f2 100644 --- a/README.md +++ b/README.md @@ -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, + }, + }, + ], } ``` diff --git a/prettierrc.config.js b/prettierrc.config.js index 580ab85..a331821 100644 --- a/prettierrc.config.js +++ b/prettierrc.config.js @@ -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, } diff --git a/src/constants.ts b/src/constants.ts index 7cab8c2..f84fd4d 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -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 diff --git a/src/package-managers.ts b/src/package-managers.ts index a135931..cfae235 100644 --- a/src/package-managers.ts +++ b/src/package-managers.ts @@ -4,33 +4,33 @@ import { LOCK_FILES, PACKAGE_MANAGERS } from './constants' import type { PackageManager } from './types' export async function choosePackageManager(): Promise { - 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, + })), + }) } diff --git a/src/setup.ts b/src/setup.ts index 3565e33..4e4ca67 100755 --- a/src/setup.ts +++ b/src/setup.ts @@ -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' }) } diff --git a/tsconfig.json b/tsconfig.json index fb73ce6..b2e115d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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" + } }