Skip to content

Commit

Permalink
fix: use @einride/prettier-config when formattign markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptammergard committed Dec 27, 2021
1 parent 15f955d commit 25415aa
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 29 deletions.
32 changes: 16 additions & 16 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, religion, or sexual identity
and orientation.
nationality, personal appearance, race, religion, or sexual identity and
orientation.

We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.
Expand All @@ -22,17 +22,17 @@ community include:
- Giving and gracefully accepting constructive feedback
- Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
- Focusing on what is best not just for us as individuals, but for the
overall community
- Focusing on what is best not just for us as individuals, but for the overall
community

Examples of unacceptable behavior include:

- The use of sexualized language or imagery, and sexual attention or
advances of any kind
- The use of sexualized language or imagery, and sexual attention or advances of
any kind
- Trolling, insulting or derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or email
address, without their explicit permission
- Publishing others' private information, such as a physical or email address,
without their explicit permission
- Other conduct which could reasonably be considered inappropriate in a
professional setting

Expand Down Expand Up @@ -83,15 +83,15 @@ behavior was inappropriate. A public apology may be requested.

### 2. Warning

**Community Impact**: A violation through a single incident or series
of actions.
**Community Impact**: A violation through a single incident or series of
actions.

**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or
permanent ban.
like social media. Violating these terms may lead to a temporary or permanent
ban.

### 3. Temporary Ban

Expand All @@ -110,17 +110,17 @@ Violating these terms may lead to a permanent ban.
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within
the community.
**Consequence**: A permanent ban from any sort of public interaction within the
community.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.0, available at
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.

Community Impact Guidelines were inspired by [Mozilla's code of conduct
enforcement ladder](https://github.com/mozilla/diversity).
Community Impact Guidelines were inspired by
[Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).

[homepage]: https://www.contributor-covenant.org

Expand Down
31 changes: 23 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Mage-tools

Mage-tools is an opinionated set of [mage](https://github.com/magefile/mage) targets to help with build automation of different projects
Mage-tools is an opinionated set of [mage](https://github.com/magefile/mage)
targets to help with build automation of different projects

[![Release](https://github.com/einride/mage-tools/actions/workflows/release.yml/badge.svg)](https://github.com/einride/mage-tools/actions/workflows/release.yml)

Expand All @@ -21,11 +22,15 @@ Run `make`

## Usage

All mage imports, and targets within the magefiles, gets written to a default Makefile which is always imported. It can also generate specific makefiles to only be imported in certain places like in a Makefile that should only have terraform targets.
All mage imports, and targets within the magefiles, gets written to a default
Makefile which is always imported. It can also generate specific makefiles to
only be imported in certain places like in a Makefile that should only have
terraform targets.

### Magefiles

You can have as many magefiles as you want in the `.mage` folder, as long as you tag them and put them in the main package
You can have as many magefiles as you want in the `.mage` folder, as long as you
tag them and put them in the main package

```golang
// +build mage
Expand All @@ -35,7 +40,9 @@ package main

#### Imports

If you want to import targets from this repository, just import and add the `// mage:import` comment above the import and alias it with `_` if its only to be used as a mage target
If you want to import targets from this repository, just import and add the
`// mage:import` comment above the import and alias it with `_` if its only to
be used as a mage target

```golang
// mage:import
Expand All @@ -47,7 +54,10 @@ _ "go.einride.tech/mage-tools/targets/mgsemanticrelease"

#### Local targets

If you wish to utilize an import, or define your own target; like an `All` target, you can just write one yourself. Just create a public function in a magefile, and it will be included. The target can have no return value other then error.
If you wish to utilize an import, or define your own target; like an `All`
target, you can just write one yourself. Just create a public function in a
magefile, and it will be included. The target can have no return value other
then error.

```golang
func All() {
Expand All @@ -62,7 +72,9 @@ func All() {

#### Specific makefiles / Mage namespaces

We utilize mage namespaces to group targets and write them to unique Makefiles. This can be done via import or for local targets. The below would generate a `semantic-release.mk` and a `terraform.mk`
We utilize mage namespaces to group targets and write them to unique Makefiles.
This can be done via import or for local targets. The below would generate a
`semantic-release.mk` and a `terraform.mk`

```golang
import (
Expand All @@ -80,7 +92,8 @@ func (Terraform) TerraformInitDev() {
}
```

Which we can then import like below, where the `$(mage_terraform)` variable gets generated by the tooling
Which we can then import like below, where the `$(mage_terraform)` variable gets
generated by the tooling

```Makefile
include ./.mage/tools.mk
Expand All @@ -89,7 +102,9 @@ include $(mage_terraform)

#### Dependencies

Dependencies can be defined just by specificing the function, or with `mg.F` if the function takes arguments. `Deps` runs in parallel while `Serial` runs serially
Dependencies can be defined just by specificing the function, or with `mg.F` if
the function takes arguments. `Deps` runs in parallel while `Serial` runs
serially

```golang
mg.Deps(
Expand Down
19 changes: 14 additions & 5 deletions targets/mgprettier/targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,25 @@ import (

const packageJSONContent = `{
"devDependencies": {
"prettier": "^2.4.1",
"@einride/prettier-config": "^1.2.0"
"@einride/prettier-config": "1.2.0",
"prettier": "2.5.0"
}
}`

const prettierConfigContent = `module.exports = {
...require("@einride/prettier-config"),
}`

var executable string

func FormatMarkdown(ctx context.Context) error {
logger := mglog.Logger("prettier")
ctx = logr.NewContext(ctx, logger)
mg.CtxDeps(ctx, prepare)
prettierrc := filepath.Join(mgtool.GetPath(), "prettier", ".prettierrc.js")
mg.CtxDeps(ctx, mg.F(prepare, prettierrc))
args := []string{
"--config",
"./.tools/prettier/.prettierrc.js",
"--write",
"**/*.md",
"!.tools",
Expand All @@ -34,7 +41,7 @@ func FormatMarkdown(ctx context.Context) error {
return sh.RunV(executable, args...)
}

func prepare(ctx context.Context) error {
func prepare(ctx context.Context, prettierrc string) error {
// Check if npm is installed
if err := sh.Run("npm", "version"); err != nil {
return err
Expand All @@ -47,7 +54,9 @@ func prepare(ctx context.Context) error {
if err := os.MkdirAll(toolDir, 0o755); err != nil {
return err
}

if err := os.WriteFile(prettierrc, []byte(prettierConfigContent), 0o644); err != nil {
return err
}
if err := os.WriteFile(packageJSON, []byte(packageJSONContent), 0o644); err != nil {
return err
}
Expand Down

0 comments on commit 25415aa

Please sign in to comment.