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

1""" 

2This module contains an example of both methods of adding commands to su6. 

3""" 

4from pathlib import Path 

5 

6from su6.plugins import PluginConfig, register, run_tool 

7 

8from .helpers import chdir, find_project_root 

9 

10 

11@register 

12class SvelteCheckPluginConfig(PluginConfig): 

13 """ 

14 Config without state, loads [tool.su6.demo] from pyproject.toml into self. 

15 """ 

16 

17 target: str = "." 

18 node_modules: str = "./node_modules" 

19 

20 strict: bool = False 

21 tsconfig: str = "./tsconfig.json" 

22 

23 

24config = SvelteCheckPluginConfig() 

25 

26 

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) 

33 

34 with chdir(config.target): 

35 return run_tool("npm", "install", "svelte-check") 

36 

37 

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 

45 

46 root, _ = find_project_root((config.node_modules,)) 

47 executable = str(root / "node_modules/svelte-check/bin/svelte-check") 

48 

49 args = ["--workspace", config.target] 

50 if config.strict: 

51 args.append("--fail-on-warnings") 

52 else: 

53 args.extend(["--threshold", "error"]) 

54 

55 if Path(config.tsconfig).exists(): 

56 args.extend(["--tsconfig", config.tsconfig]) 

57 

58 return run_tool(executable, *args)