Skip to content

Commit

Permalink
feat: prettier plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfiorette committed Feb 4, 2023
1 parent 65afff7 commit f5ed63d
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 184 deletions.
100 changes: 50 additions & 50 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
name: Publish to NPM

on:
push:
paths:
- 'index.js'
branches:
- main
workflow_dispatch:

jobs:
publish:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
persist-credentials: false
fetch-depth: 0

- name: Setup node and restore cached dependencies
uses: actions/setup-node@v2
with:
registry-url: 'https://registry.npmjs.org/'
node-version: '16'
cache: 'npm'

- name: Install dependencies
run: npm install

- name: Prepare git and update version
run: |
git config --local user.name "github-actions[bot]"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
npm run auto-version
git commit -m "tags: updated tags" -a
- name: Publish to NPM
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
tags: true
name: Publish to NPM

on:
push:
paths:
- 'index.js'
branches:
- main
workflow_dispatch:

jobs:
publish:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
persist-credentials: false
fetch-depth: 0

- name: Setup node and restore cached dependencies
uses: actions/setup-node@v2
with:
registry-url: 'https://registry.npmjs.org/'
node-version: '16'
cache: 'npm'

- name: Install dependencies
run: npm install

- name: Prepare git and update version
run: |
git config --local user.name "github-actions[bot]"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
npm run auto-version
git commit -m "tags: updated tags" -a
- name: Publish to NPM
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
tags: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/node_modules
package-lock.json
yarn.lock
1 change: 1 addition & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./index')();
23 changes: 4 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
## @arthurfiorette/prettier-config
# @arthurfiorette/prettier-config

### Usage

First, install
## Usage

```sh
# Npm
npm i -D @arthurfiorette/prettier-config

# Yarn
yarn add -D @arthurfiorette/prettier-config
setup-aff-prettier # creates the .prettierrc.js file.
```

You can just copy what is below in a `.prettierrc.js` file:

```js
// https://github.com/ArthurFiorette/prettier-config

module.exports = require('@arthurfiorette/prettier-config')({
// Any options here will override @arthurfiorette/prettier-config defaults
});
```

### See more
## See more

- [Prettier - extending configurations](https://prettier.io/docs/en/configuration.html#sharing-configurations)
18 changes: 18 additions & 0 deletions bin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env node

const path = require('path');
const fs = require('fs');

const code = `
// https://github.com/arthurfiorette/prettier-config
module.exports = require('@arthurfiorette/prettier-config')({
// Any options here will override @arthurfiorette/prettier-config defaults
});
`.trim();

fs.writeFileSync(path.resolve(process.cwd(), '.prettierrc.js'), code);

console.log(
'\x1b[7mCreated .prettierrc.js file with @arthurfiorette/prettier-config\x1b[0m'
);
71 changes: 38 additions & 33 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
/** @type {import('prettier').Options} */
const defaultConfig = {
arrowParens: 'always',
bracketSpacing: true,
endOfLine: 'lf',
insertPragma: false,
bracketSameLine: false,
jsxSingleQuote: false,
printWidth: 90,
proseWrap: 'always',
quoteProps: 'as-needed',
requirePragma: false,
semi: true,
singleQuote: true,
tabWidth: 2,
trailingComma: 'none',
useTabs: false
};

/**
* Returns the prettier config with the given overridden options.
*
* @param {Partial<import('prettier').Options>} override
* @returns {import('prettier').Options}
*
* @see {defaultConfig}
*/
module.exports = function (override = {}) {
return { ...defaultConfig, ...override };
};

module.exports.defaultConfig = defaultConfig;

/** @satisfies {import('prettier').Options} */
const defaultConfig = {
arrowParens: 'always',
bracketSpacing: true,
endOfLine: 'lf',
insertPragma: false,
bracketSameLine: false,
jsxSingleQuote: false,
printWidth: 90,
proseWrap: 'always',
quoteProps: 'as-needed',
requirePragma: false,
semi: true,
singleQuote: true,
tabWidth: 2,
trailingComma: 'none',
useTabs: false,
vueIndentScriptAndStyle: false,
plugins: [
require.resolve('prettier-plugin-packagejson'),
require.resolve('prettier-plugin-jsdoc'),
require.resolve('prettier-plugin-organize-imports')
]
};

/**
* Returns the prettier config with the given overridden options.
*
* @param {Partial<import('prettier').Options>} override
* @returns {import('prettier').Options}
*
* @see {defaultConfig}
*/
module.exports = function config(override = {}) {
return { ...defaultConfig, ...override };
};

module.exports.defaultConfig = defaultConfig;
70 changes: 0 additions & 70 deletions package-lock.json

This file was deleted.

27 changes: 15 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@
"name": "@arthurfiorette/prettier-config",
"version": "1.0.7",
"description": "My personal prettier config",
"main": "index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/ArthurFiorette/prettier-config.git"
},
"author": "Hazork",
"homepage": "https://github.com/arthurfiorette/prettier-config#readme",
"bugs": "https://github.com/arthurfiorette/prettier-config/issues",
"repository": "https://github.com/arthurfiorette/prettier-config.git",
"license": "MIT",
"bugs": {
"url": "https://github.com/ArthurFiorette/prettier-config/issues"
"author": "Hazork",
"main": "index.js",
"bin": {
"setup-aff-prettier": "./bin.js"
},
"homepage": "https://github.com/ArthurFiorette/prettier-config#readme",
"scripts": {
"auto-version": "npm-auto-version"
},
"dependencies": {
"@types/prettier": "*"
"@types/prettier": "*",
"prettier-plugin-jsdoc": "*",
"prettier-plugin-organize-imports": "*",
"prettier-plugin-packagejson": "*",
"typescript": "*"
},
"devDependencies": {
"npm-auto-version": "^1.0.0"
"npm-auto-version": "^1.0.0",
"prettier": "^2.8.3"
}
}
}

0 comments on commit f5ed63d

Please sign in to comment.