From 25415aa46336cf3ee307ddeffe6067f140cf2b5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Tammerg=C3=A5rd?= Date: Sun, 26 Dec 2021 18:03:01 +0100 Subject: [PATCH] fix: use @einride/prettier-config when formattign markdown --- CODE_OF_CONDUCT.md | 32 ++++++++++++++++---------------- README.md | 31 +++++++++++++++++++++++-------- targets/mgprettier/targets.go | 19 ++++++++++++++----- 3 files changed, 53 insertions(+), 29 deletions(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index a899c5ea..d8985981 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -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. @@ -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 @@ -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 @@ -110,8 +110,8 @@ 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 @@ -119,8 +119,8 @@ 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 diff --git a/README.md b/README.md index f946adf3..507e1cc5 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 @@ -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 @@ -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() { @@ -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 ( @@ -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 @@ -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( diff --git a/targets/mgprettier/targets.go b/targets/mgprettier/targets.go index 08b81a83..210354b7 100644 --- a/targets/mgprettier/targets.go +++ b/targets/mgprettier/targets.go @@ -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", @@ -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 @@ -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 }