Coverage for src/su6_plugin_svelte_check/cli.py: 100%
27 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-17 18:23 +0200
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-17 18:23 +0200
1"""
2This module contains an example of both methods of adding commands to su6.
3"""
4from pathlib import Path
6from su6.plugins import PluginConfig, register, run_tool
8from .helpers import chdir, find_project_root
11@register
12class SvelteCheckPluginConfig(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"
20 strict: bool = False
21 tsconfig: str = "./tsconfig.json"
24config = SvelteCheckPluginConfig()
27@register
28def install_svelte_check(target_dir: str = None) -> int:
29 """
30 Install the svelte-check tool using npm.
31 """
32 config.update(target=target_dir)
34 with chdir(config.target):
35 return run_tool("npm", "install", "svelte-check")
38@register(add_to_all=True)
39def svelte_check(target: str = None, strict: bool = None, tsconfig: str = None, node_modules: str = None) -> int:
40 """
41 Run the svelte-check tool.
42 """
43 config.update(strict=strict, tsconfig=tsconfig, target=target, node_modules=node_modules)
44 # svelte-check --tsconfig ./tsconfig.json --threshold error
46 root, _ = find_project_root((config.node_modules,))
47 executable = str(root / "node_modules/svelte-check/bin/svelte-check")
49 args = ["--workspace", config.target]
50 if config.strict:
51 args.append("--fail-on-warnings")
52 else:
53 args.extend(["--threshold", "error"])
55 if Path(config.tsconfig).exists():
56 args.extend(["--tsconfig", config.tsconfig])
58 return run_tool(executable, *args)