Skip to content

Commit

Permalink
feat(prj): add justfile with maintenance helpers
Browse files Browse the repository at this point in the history
Copied and pasted from another project.

Mainly because I don't remember how to do a proper GitHub release!  So when I
figure it out again, I can save it.
  • Loading branch information
montchr committed Jun 20, 2024
1 parent c18dfa8 commit 0105804
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ fi
# Disable the automatic menu displaying on every environment reload.
# export DEVSHELL_NO_MOTD=1

export KWG_PROJECT_SLUG='php-coding-standards'
export KWG_PROJECT_TITLE='Kleinweb PHP Coding Standards'

# Reload the environment when any of these files change.
watch_file flake.nix flake.lock shell.nix
watch_file .env
Expand Down
95 changes: 95 additions & 0 deletions .justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# SPDX-FileCopyrightText: 2022-2024 Temple University <[email protected]>
# SPDX-License-Identifier: GPL-3.0-or-later

###: <https://just.systems/man/en/>

## Global constants
prj-root := justfile_directory()
# FIXME: not yet released -- probably will be v1.30.0
# today := datetime('%F')

## OS commands
open := if os_family() == "linux" { "xdg-open" } else { "open" }

## Project owner metadata
owner-name := 'Temple University'
owner-email := '[email protected]'
owner-attr := owner-name + ' <' + owner-email + '>'

## Project metadata
prj-slug := env('KWG_PROJECT_SLUG')
prj-title := env('KWG_PROJECT_TITLE')

# Display a list of available tasks as the default command
default:
@just --choose

[group: "qa"]
[doc: "Check for (non-stylistic) linting issues on project files"]
lint:
-biome lint {{prj-root}}
-composer lint

[group: "qa"]
[doc: "Write *all* formatter+fixer changes to project files"]
fix:
biome check --apply {{prj-root}}
composer fix

[group: "qa"]
[doc: "Write _safe_ formatter changes to project files"]
fmt:
biome format --write {{prj-root}}
composer ecs -- --fix

[group: "php"]
[doc: "Rebuild the Phpactor project index"]
reindex:
phpactor index:build --reset

_stub-add path base target:
jq --arg stub {{join(base, path)}} \
'."indexer.stub_paths" += [$stub]' \
{{target}} \
| sponge {{target}}

[group: "php"]
[doc: "Generate PHP stubs for files in the given directory"]
stubify src:
nix run .\#php-stubs-generator -- \
--out={{ join(prj-root, "packages", file_stem(src) + "-stubs", file_stem(src) + ".stubs.php") }} \
{{src}}

[group: "php"]
[doc: "Add the specified PHP stub paths to config files"]
stub-add path: (_stub-add path prj-root ".phpactor.json") (_stub-add path "/path/to/project" ".phpactor.json.example")

###: LICENSING =====================================================================================

alias l-default := l-gpl

[group: "licensing"]
[doc: "Annotate all plaintext note files with the documentation license"]
l-docs:
fd --glob '**/*.{md,mdx,markdown,org}' -X \
just l-cc {}

[group: "licensing"]
_annotate license +FILES:
reuse annotate -l '{{license}}' -c '{{owner-attr}}' --template=compact --skip-existing {{FILES}}

[group: "licensing"]
[doc: "License the specified files as GPL-3.0-or-later"]
l-gpl +FILES: (_annotate 'GPL-3.0-or-later' FILES)

[group: "licensing"]
[doc: "Dual-license the specified files as GPL/MIT"]
l-dual colicensor +FILES: (_annotate 'GPL-3.0-or-later AND MIT' ('-c ' + quote(colicensor) + ' ' + FILES))

[group: "licensing"]
[doc: "License the specified files as non-commercial docs"]
l-cc +FILES: (_annotate 'CC-BY-NC-SA-4.0' FILES)

[group: "licensing"]
[doc: "Release the specified files into the public domain"]
l-public-domain +FILES: (_annotate 'CC0-1.0' FILES)
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"scripts": {
"ecs": "ecs check --config=$PRJ_ROOT/ecs.php",
"fix": ["@ecs --fix --ansi", "@phpcbf"],
"lint": ["@ecs --ansi", "@phpcs"],
"check": ["@phpcs"],
"lint": ["@ecs --ansi", "@check"],
"phpcbf": "phpcbf --extensions=php --standard=$PRJ_ROOT/phpcs.xml.dist",
"phpcs": "phpcs --extensions=php --standard=$PRJ_ROOT/phpcs.xml.dist"
}
Expand Down
4 changes: 1 addition & 3 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
use Symplify\EasyCodingStandard\Config\ECSConfig;

return ECSConfig::configure()
->withPaths([
'ecs.php',
])
->withPaths(['ecs.php'])
->withPreparedSets(strict: true, common: true, psr12: true, symplify: true, cleanCode: true)
->withPhpCsFixerSets(symfony: true)
->withRules([PhpCsFixer\Fixer\Basic\SingleLineEmptyBodyFixer::class])
Expand Down
6 changes: 6 additions & 0 deletions nix/devshells.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
let
commonPkgs = [
inputs'.nixpkgs-trunk.legacyPackages.biome
inputs'.nixpkgs-trunk.legacyPackages.just
inputs'.phps.packages.env-php82

# standard utils
pkgs.jq
pkgs.fd
pkgs.ripgrep
];
in
{
Expand Down

0 comments on commit 0105804

Please sign in to comment.