Coverage for src/su6_plugin_prettier/cli.py: 100%
23 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-17 19:00 +0200
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-17 19:00 +0200
1"""
2This module contains an example of both methods of adding commands to su6.
3"""
4import typing
6from su6.plugins import PluginConfig, register, run_tool
8from .helpers import chdir, find_project_root
11@register
12class PrettierPluginConfig(PluginConfig):
13 """
14 Config without state, loads [tool.su6.demo] from pyproject.toml into self.
15 """
17 target: str = "."
18 node_modules: str = "./node_modules"
21config = PrettierPluginConfig()
24@register
25def install_prettier(target_dir: str = None) -> int:
26 """
27 Install the svelte-check tool using npm.
28 """
29 config.update(target=target_dir)
31 with chdir(config.target):
32 return run_tool("npm", "install", "prettier")
35@register(add_to_all=True, add_to_fix=True)
36def prettier(target: typing.Optional[str] = None, fix: bool = False, node_modules: str = None) -> int:
37 """
38 Run the svelte-check tool.
39 """
40 config.update(target=target, node_modules=node_modules)
42 root, _ = find_project_root((config.node_modules,))
43 executable = str(root / "node_modules/prettier/bin/prettier.cjs")
45 args = [config.target]
47 if fix:
48 args.append("--write")
49 else:
50 args.append("--check")
52 return run_tool(executable, *args)