Skip to content

Commit

Permalink
feat: adds function for generating prettier ignore files and formats …
Browse files Browse the repository at this point in the history
…code
  • Loading branch information
jmgilman committed May 28, 2022
1 parent 298a2a1 commit 027e0d2
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 53 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ name: CI
on:
pull_request:
paths-ignore:
- 'README.md'
- "README.md"
push:
branches:
- master
paths-ignore:
- 'README.md'
- "README.md"
workflow_dispatch:

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: cachix/install-nix-action@v17
- uses: cachix/cachix-action@v10
with:
name: jmgilman
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- run: nix develop -c just check
- uses: actions/checkout@v2
- uses: cachix/install-nix-action@v17
- uses: cachix/cachix-action@v10
with:
name: jmgilman
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
- run: nix develop -c just check
20 changes: 10 additions & 10 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ on:
branches:
- master
paths:
- 'docs/**'
- "docs/**"
workflow_dispatch:

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: cachix/install-nix-action@v17
- uses: cachix/cachix-action@v10
with:
name: jmgilman
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- run: nix develop -c just check
- uses: actions/checkout@v2
- uses: cachix/install-nix-action@v17
- uses: cachix/cachix-action@v10
with:
name: jmgilman
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
- run: nix develop -c just check
docs:
runs-on: ubuntu-latest
needs: [check]
Expand All @@ -27,5 +27,5 @@ jobs:
- uses: cachix/cachix-action@v10
with:
name: jmgilman
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- run: nix develop -c just deploy
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
- run: nix develop -c just deploy
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.direnv/
.justfile
.pre-commit-config.yaml
.prettierignore
site/
2 changes: 1 addition & 1 deletion docs/contributing/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ the format needed for the configuration file.
## Plugins

The main interface that Nixago provides is through its [plugin][4]
infrastructure. A plugin is simply a small wrapper which generates a
infrastructure. A plugin is simply a small wrapper which generates a
configuration file for a specific tool. The structure of plugins is consistent
in that they ingest data from the user and produce an instance of the
[template module](#templates). This module provides a derivation which will
Expand Down
6 changes: 3 additions & 3 deletions docs/contributing/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ advanced cases may require multiple files. The file should be called
When creating the CUE file, keep the following in mind:

- The schema defined in the file should be sufficient enough to prevent most
configuration mistakes.
configuration mistakes.

- If the tool being supported has rich documentation around valid values for
each configuration field, use constraints to improve the accuracy of the schema.
each configuration field, use constraints to improve the accuracy of the schema.

- Don't be overly strict with the schema definition. The goal is to be helpful
and not generate a large number of false negatives.
and not generate a large number of false negatives.

Here is the `template.nix` file for our pre-commit plugin:

Expand Down
28 changes: 14 additions & 14 deletions docs/plugins/prettier.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ Produces the following `.prettierrc.json`:

```json
{
"arrowParens": "always",
"bracketSpacing": true,
"tabWidth": 80
"arrowParens": "always",
"bracketSpacing": true,
"tabWidth": 80
}
```

Expand Down Expand Up @@ -52,17 +52,17 @@ Produces:

```json
{
"arrowParens": "always",
"bracketSpacing": true,
"overrides": [
{
"files": "*.js",
"options": {
"semi": true
}
}
],
"tabWidth": 80
"arrowParens": "always",
"bracketSpacing": true,
"overrides": [
{
"files": "*.js",
"options": {
"semi": true
}
}
],
"tabWidth": 80
}
```

Expand Down
24 changes: 16 additions & 8 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
pkgs.mkdocs
pkgs.nixpkgs-fmt
pkgs.pre-commit
pkgs.nodePackages.prettier
];

# Define development dependencies
Expand All @@ -58,19 +59,12 @@

# Define development tool configuration
configurations = {
# Pre-commit configuration
"pre-commit.mkLocalConfig" = {
nixpkgs-fmt = {
entry = tools.nixpkgs-fmt.exe;
language = "system";
files = "\\.nix";
};
};
# Just configuration
"just.mkConfig" = {
tasks = {
check = [
"@${tools.nixpkgs-fmt.exe} --check flake.nix $(git ls-files '**/*.nix')"
"@${tools.prettier.exe} -c ."
"@nix flake check"
"@mkdocs build --strict && rm -rf site"
];
Expand All @@ -79,9 +73,23 @@
];
fmt = [
"@${tools.nixpkgs-fmt.exe} flake.nix $(git ls-files '**/*.nix')"
"@${tools.prettier.exe} -w ."
];
};
};
# Pre-commit configuration
"pre-commit.mkLocalConfig" = {
nixpkgs-fmt = {
entry = tools.nixpkgs-fmt.exe;
language = "system";
files = "\\.nix";
};
};
# Prettier
"prettier.mkIgnoreConfig" = [
".direnv"
"tests"
];
};
in
{
Expand Down
16 changes: 8 additions & 8 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ theme:

nav:
- Home: index.md
- 'Quick Start': quick_start.md
- "Quick Start": quick_start.md
- Plugins:
- Overview: plugins/overview.md
- Just: plugins/just.md
- Pre-commit: plugins/pre-commit.md
- Prettier: plugins/prettier.md
- Overview: plugins/overview.md
- Just: plugins/just.md
- Pre-commit: plugins/pre-commit.md
- Prettier: plugins/prettier.md
- Contributing:
- Design: contributing/design.md
- Plugins: contributing/plugins.md
- Design: contributing/design.md
- Plugins: contributing/plugins.md

markdown_extensions:
- pymdownx.highlight:
Expand All @@ -26,4 +26,4 @@ markdown_extensions:
- pymdownx.inlinehilite
- pymdownx.snippets:
check_paths: true
- pymdownx.superfences
- pymdownx.superfences
1 change: 1 addition & 0 deletions plugins/prettier/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/* Creates a .prettierrc.json file for configuring prettier.
*/
mkConfig = import ./mkConfig.nix { inherit pkgs lib; };
mkIgnoreConfig = import ./mkIgnoreConfig.nix { inherit pkgs lib; };
}
20 changes: 20 additions & 0 deletions plugins/prettier/mkIgnoreConfig.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{ pkgs, lib }:
data:
with pkgs.lib;
let
files = [ ./template_ignore.cue ];
output = ".prettierignore";
flags = {
expression = "rendered";
out = "text";
};

# Generate the module
result = lib.mkTemplate {
inherit files output flags;
data = { inherit data; };
};
in
{
inherit (result) configFile shellHook;
}
5 changes: 5 additions & 0 deletions plugins/prettier/template_ignore.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import "strings"

data: [...string]

rendered: strings.Join(data, "\n")

0 comments on commit 027e0d2

Please sign in to comment.