Skip to content

Add a new endpoint to fully install prettier, husky and lint-staged, with a "curl pipe bash" idiom #60

@marcelocra

Description

@marcelocra

Context

The prettier.io website provides a step by step on how to install and automate formatting.

Task

Create an endpoint, e.g. https://devmagic.run/install/prettier , that does everything necessary to install and make it work automatically:

# 1. Install
# Below is the default command, but it MUST detect if in a workspace and add the `-w` flag correctly.
pnpm add --save-dev --save-exact prettier 

# 2. Create files
node --eval "fs.writeFileSync('.prettierrc','{}\n')"
node --eval "fs.writeFileSync('.prettierignore','# Ignore artifacts:\nbuild\ncoverage\n')"
node --eval "fs.writeFileSync('root = true

[*]
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
end_of_line = lf
charset = utf-8
spelling_languages = en-US,en,pt-BR,pt
max_line_length = 120

[*.{lua,toml,yaml,yml,json,jsonc,json5}]
max_line_length = 80

[*.{fs,fsi,fsx}]
indent_size = 4
# Simplifies reordering and adding new items. Details:
# https://learn.microsoft.com/en-us/dotnet/fsharp/style-guide/formatting#multiline-bracket-formatting-style
fsharp_multiline_bracket_style = stroustrup

[*.{py,sh,zsh,bash,gitconfig,tmux.conf}]
indent_size = 4
max_line_length = 80

[*.{md,markdown,mdx}]
indent_size = 4
max_line_length = unset           # Not wrapping lines reduces diffs.
trim_trailing_whitespace = false  # Double trailing spaces can be used to break lines.')"

# 3. Install husky, lint-staged and prepare stuff.
pnpm add --save-dev husky lint-staged
pnpm exec husky init
node --eval "fs.writeFileSync('.husky/pre-commit','pnpm exec lint-staged\n')"
// 4. Add the following to the `package.json` at the end of it. MUST check if the file already
// has something like it before doing so.
{
  // ... rest of the file, unchanged ...

  "lint-staged": {
    "**/*": "prettier --write --ignore-unknown"
  }
}
# 5. Create a github ci workflow to check and fail the build.
# It should not change anything, just check. The name does
# NOT need to be CI if there's too much risk of colision.
name: CI
on: [push, pull_request]

jobs:
  check-format:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: pnpm/action-setup@v4
        with:
          version: 9
      - uses: actions/setup-node@v4
        with:
          node-version: "20"
          cache: "pnpm"
      - run: pnpm install --frozen-lockfile
      - run: pnpm exec prettier --check .

IMPORTANT: notice that everything here considers pnpm. It would be nice if there was a simple way to change to other package managers, perhaps directly through the url, like ?pm=npm. Prettier's site has commands for npm, yarn, pnpm and bun, so we would have those too, with pnpm being the default.

Example Usage

List all available installs: https://devmagic.run/install.

Clicking on one of the listed installs should show their step by step.

Run any of the listed installs using the "curl pipe bash" idiom. Prettier example:

curl -fsSL https://devmagic.run/install/prettier | bash

Change the package manager before running:

curl -fsSL https://devmagic.run/install/prettier?pm=npm | bash

Requirements

  1. Most likely there will be more installations like this to be added later, so the code should be generic enough that it is simple to add more step-by-steps like this one.
  2. While the curl-pipe-bash expects bash, if this would be better in a different language, e.g. go, we could write it in that language, create releases directly in the repo, download and use them through the curl-pipe-bash.

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions