virmator 2.0.7 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/.github/workflows/virmator-build-for-gh-pages.yml +24 -0
  2. package/.github/workflows/virmator-tagged-release.yml +8 -4
  3. package/.github/workflows/virmator-tests.yml +4 -3
  4. package/.mocharc.js +9 -0
  5. package/.prettierignore +2 -3
  6. package/README.md +67 -82
  7. package/configs/.cspell.json +4 -0
  8. package/configs/.gitattributes +1 -0
  9. package/configs/.mocharc.js +8 -0
  10. package/configs/.prettierignore +6 -0
  11. package/configs/.prettierrc.js +13 -0
  12. package/{.cspell.json → configs/.virmator/.cspell-base.json} +5 -0
  13. package/configs/.virmator/mocharc-base.js +15 -0
  14. package/configs/.virmator/prettierrc-base.js +62 -0
  15. package/{tsconfig.json → configs/.virmator/tsconfig-base.json} +12 -8
  16. package/configs/.virmator/vite-always-reload-plugin.ts +90 -0
  17. package/configs/.virmator/vite-base.ts +11 -0
  18. package/configs/.virmator/vite.config.ts +8 -0
  19. package/configs/.virmator/web-test-runner-base.mjs +29 -0
  20. package/configs/.virmator/web-test-runner.config.mjs +8 -0
  21. package/{.vscode → configs/.vscode}/settings.json +12 -0
  22. package/configs/gitignore.txt +6 -0
  23. package/configs/npmignore.txt +13 -0
  24. package/configs/package.json +16 -0
  25. package/configs/src/global.d.ts +5 -0
  26. package/configs/tsconfig.json +3 -0
  27. package/dist/api/virmator-wrapper.d.ts +5 -0
  28. package/dist/api/virmator-wrapper.js +9 -0
  29. package/dist/augments/array.d.ts +1 -0
  30. package/dist/augments/array.js +7 -0
  31. package/dist/augments/fs.d.ts +5 -0
  32. package/dist/augments/fs.js +30 -0
  33. package/dist/augments/json.d.ts +1 -0
  34. package/dist/augments/json.js +12 -0
  35. package/dist/augments/object.d.ts +1 -0
  36. package/dist/augments/object.js +14 -0
  37. package/dist/augments/regexp.d.ts +1 -0
  38. package/dist/augments/regexp.js +7 -0
  39. package/dist/augments/test.d.ts +2 -0
  40. package/dist/augments/test.js +8 -0
  41. package/dist/augments/type.d.ts +1 -0
  42. package/dist/augments/type.js +2 -0
  43. package/dist/cli/all-cli-command-definitions.d.ts +54 -0
  44. package/dist/cli/all-cli-command-definitions.js +76 -0
  45. package/dist/cli/cli-color.d.ts +8 -0
  46. package/dist/cli/cli-color.js +12 -0
  47. package/dist/cli/cli-command/cli-command-help.d.ts +8 -0
  48. package/dist/cli/cli-command/cli-command-help.js +2 -0
  49. package/dist/cli/{commands/description-printing.d.ts → cli-command/cli-command-to-help-message.d.ts} +3 -2
  50. package/dist/cli/{commands/description-printing.js → cli-command/cli-command-to-help-message.js} +55 -21
  51. package/dist/cli/cli-command/define-cli-command.d.ts +41 -0
  52. package/dist/cli/cli-command/define-cli-command.js +29 -0
  53. package/dist/cli/cli-command/run-shell-command.d.ts +8 -0
  54. package/dist/cli/cli-command/run-shell-command.js +23 -0
  55. package/dist/cli/cli-command-implementations/code-in-markdown.command.d.ts +6 -0
  56. package/dist/cli/cli-command-implementations/code-in-markdown.command.js +67 -0
  57. package/dist/cli/cli-command-implementations/compile.command.d.ts +6 -0
  58. package/dist/cli/cli-command-implementations/compile.command.js +44 -0
  59. package/dist/cli/cli-command-implementations/format.command.d.ts +6 -0
  60. package/dist/cli/cli-command-implementations/format.command.js +116 -0
  61. package/dist/cli/cli-command-implementations/frontend.command.d.ts +7 -0
  62. package/dist/cli/cli-command-implementations/frontend.command.js +45 -0
  63. package/dist/cli/cli-command-implementations/init.command.d.ts +4 -0
  64. package/dist/cli/cli-command-implementations/init.command.js +31 -0
  65. package/dist/cli/cli-command-implementations/spellcheck.command.d.ts +4 -0
  66. package/dist/cli/cli-command-implementations/spellcheck.command.js +40 -0
  67. package/dist/cli/cli-command-implementations/test-web.command.d.ts +4 -0
  68. package/dist/cli/cli-command-implementations/test-web.command.js +50 -0
  69. package/dist/cli/cli-command-implementations/test.command.d.ts +4 -0
  70. package/dist/cli/cli-command-implementations/test.command.js +53 -0
  71. package/dist/cli/cli-command-implementations/update-configs.command.d.ts +4 -0
  72. package/dist/cli/cli-command-implementations/update-configs.command.js +31 -0
  73. package/dist/cli/cli-flags/cli-flag-name.d.ts +4 -0
  74. package/dist/cli/cli-flags/cli-flag-name.js +8 -0
  75. package/dist/cli/cli-flags/cli-flag-values.d.ts +4 -0
  76. package/dist/cli/cli-flags/cli-flag-values.js +19 -0
  77. package/dist/cli/cli-messages.d.ts +6 -0
  78. package/dist/cli/cli-messages.js +19 -0
  79. package/dist/cli/cli.js +27 -20
  80. package/dist/cli/config/combine-text-config.d.ts +2 -0
  81. package/dist/cli/config/combine-text-config.js +27 -0
  82. package/dist/cli/config/config-files.d.ts +133 -0
  83. package/dist/cli/config/config-files.js +138 -0
  84. package/dist/cli/config/copy-config.d.ts +25 -13
  85. package/dist/cli/config/copy-config.js +86 -86
  86. package/dist/cli/config/create-default-package-json.d.ts +1 -16
  87. package/dist/cli/config/create-default-package-json.js +37 -12
  88. package/dist/cli/is-global.d.ts +1 -0
  89. package/dist/cli/is-global.js +10 -0
  90. package/dist/cli/parse-arguments.d.ts +8 -0
  91. package/dist/cli/parse-arguments.js +42 -0
  92. package/dist/cli/run-cli-command.d.ts +13 -0
  93. package/dist/cli/run-cli-command.js +52 -0
  94. package/dist/cli/run-command.test-helper.d.ts +28 -0
  95. package/dist/cli/run-command.test-helper.js +87 -0
  96. package/dist/errors/virmator-cli.error.d.ts +3 -0
  97. package/dist/errors/virmator-cli.error.js +10 -0
  98. package/dist/errors/virmator-config-file.error.d.ts +4 -0
  99. package/dist/errors/virmator-config-file.error.js +11 -0
  100. package/dist/errors/virmator-invalid-command.error.d.ts +5 -0
  101. package/dist/errors/virmator-invalid-command.error.js +11 -0
  102. package/dist/errors/virmator-invalid-flags.error.d.ts +5 -0
  103. package/dist/errors/virmator-invalid-flags.error.js +13 -0
  104. package/dist/file-paths/virmator-package-paths.d.ts +11 -0
  105. package/dist/file-paths/virmator-package-paths.js +31 -0
  106. package/dist/file-paths/virmator-test-file-paths.d.ts +17 -7
  107. package/dist/index.d.ts +1 -2
  108. package/dist/index.js +0 -4
  109. package/dist/logging.d.ts +10 -0
  110. package/dist/logging.js +9 -0
  111. package/package.json +26 -20
  112. package/.prettierrc.js +0 -40
  113. package/dist/augments/ansi-regex.d.ts +0 -1
  114. package/dist/augments/ansi-regex.js +0 -27
  115. package/dist/augments/string.d.ts +0 -1
  116. package/dist/augments/string.js +0 -8
  117. package/dist/cli/cli-util/cli-color.d.ts +0 -8
  118. package/dist/cli/cli-util/cli-color.js +0 -35
  119. package/dist/cli/cli-util/cli-command-name.d.ts +0 -11
  120. package/dist/cli/cli-util/cli-command-name.js +0 -15
  121. package/dist/cli/cli-util/cli-flags.d.ts +0 -18
  122. package/dist/cli/cli-util/cli-flags.js +0 -63
  123. package/dist/cli/cli-util/cli-messages.d.ts +0 -7
  124. package/dist/cli/cli-util/cli-messages.js +0 -19
  125. package/dist/cli/cli-util/get-all-command-output.d.ts +0 -7
  126. package/dist/cli/cli-util/get-all-command-output.js +0 -21
  127. package/dist/cli/cli-util/shell-command-wrapper.d.ts +0 -8
  128. package/dist/cli/cli-util/shell-command-wrapper.js +0 -25
  129. package/dist/cli/cli-util/update-configs.d.ts +0 -3
  130. package/dist/cli/cli-util/update-configs.js +0 -54
  131. package/dist/cli/commands/all-cli-commands.d.ts +0 -13
  132. package/dist/cli/commands/all-cli-commands.js +0 -99
  133. package/dist/cli/commands/cli-command.d.ts +0 -35
  134. package/dist/cli/commands/cli-command.js +0 -40
  135. package/dist/cli/commands/implementations/code-in-markdown.command.d.ts +0 -3
  136. package/dist/cli/commands/implementations/code-in-markdown.command.js +0 -54
  137. package/dist/cli/commands/implementations/compile.command.d.ts +0 -3
  138. package/dist/cli/commands/implementations/compile.command.js +0 -49
  139. package/dist/cli/commands/implementations/format.command.d.ts +0 -16
  140. package/dist/cli/commands/implementations/format.command.js +0 -143
  141. package/dist/cli/commands/implementations/init.command.d.ts +0 -3
  142. package/dist/cli/commands/implementations/init.command.js +0 -55
  143. package/dist/cli/commands/implementations/spellcheck.command.d.ts +0 -3
  144. package/dist/cli/commands/implementations/spellcheck.command.js +0 -35
  145. package/dist/cli/commands/implementations/test.command.d.ts +0 -3
  146. package/dist/cli/commands/implementations/test.command.js +0 -49
  147. package/dist/cli/commands/implementations/update-all-configs.command.d.ts +0 -3
  148. package/dist/cli/commands/implementations/update-all-configs.command.js +0 -46
  149. package/dist/cli/commands/implementations/update-bare-configs.command.d.ts +0 -3
  150. package/dist/cli/commands/implementations/update-bare-configs.command.js +0 -46
  151. package/dist/cli/commands/run-command.d.ts +0 -3
  152. package/dist/cli/commands/run-command.js +0 -65
  153. package/dist/cli/config/config-key.d.ts +0 -35
  154. package/dist/cli/config/config-key.js +0 -25
  155. package/dist/cli/config/config-paths.d.ts +0 -3
  156. package/dist/cli/config/config-paths.js +0 -69
  157. package/dist/cli/config/config-read.d.ts +0 -7
  158. package/dist/cli/config/config-read.js +0 -91
  159. package/dist/cli/config/extendable-config.d.ts +0 -12
  160. package/dist/cli/config/extendable-config.js +0 -45
  161. package/dist/errors/cli-command-error.d.ts +0 -4
  162. package/dist/errors/cli-command-error.js +0 -12
  163. package/dist/errors/cli-flag-error.d.ts +0 -4
  164. package/dist/errors/cli-flag-error.js +0 -12
  165. package/dist/errors/config-file-error.d.ts +0 -3
  166. package/dist/errors/config-file-error.js +0 -7
  167. package/dist/exportable-jest-config/jest-config.d.ts +0 -3
  168. package/dist/exportable-jest-config/jest-config.js +0 -23
  169. package/dist/exportable-jest-config/jest-setup.d.ts +0 -1
  170. package/dist/exportable-jest-config/jest-setup.js +0 -11
  171. package/dist/file-paths/virmator-repo-paths.d.ts +0 -5
  172. package/dist/file-paths/virmator-repo-paths.js +0 -19
  173. package/dist/jest/jest-config.d.ts +0 -3
  174. package/dist/jest/jest-config.js +0 -13
  175. package/extender-configs/.cspell.json +0 -3
  176. package/extender-configs/.prettierrc.js +0 -3
  177. package/extender-configs/tsconfig.json +0 -3
  178. package/separate-configs/.prettierignore +0 -3
  179. package/separate-configs/gitignore.txt +0 -4
  180. package/separate-configs/jest/jest-config.ts +0 -24
  181. package/separate-configs/jest/jest-setup.ts +0 -12
  182. package/separate-configs/npmignore.txt +0 -20
  183. package/separate-configs/package.json +0 -9
@@ -0,0 +1,24 @@
1
+ name: build-for-gh-pages
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ jobs:
9
+ build-for-gh-pages:
10
+ runs-on: 'ubuntu-latest'
11
+
12
+ steps:
13
+ - uses: actions/checkout@v3
14
+ - uses: actions/setup-node@v3
15
+ with:
16
+ node-version: 16.x
17
+ - name: build
18
+ run: |
19
+ npm ci
20
+ npm run build
21
+ - uses: 'JamesIves/github-pages-deploy-action@4'
22
+ with:
23
+ branch: 'gh-pages'
24
+ folder: 'dist'
@@ -8,24 +8,28 @@ on:
8
8
  jobs:
9
9
  tagged-release:
10
10
  name: 'Tagged Release'
11
+ if: github.event.base_ref == 'refs/heads/main' || github.event.base_ref == 'refs/heads/master'
11
12
  runs-on: 'ubuntu-latest'
12
13
 
13
14
  steps:
14
- - uses: actions/checkout@v1
15
- - name: Use Node.js 16.x
16
- uses: actions/setup-node@v1
15
+ - uses: actions/checkout@v3
16
+ - name: Use Node.js
17
+ uses: actions/setup-node@v3
17
18
  with:
18
19
  node-version: 16.x
19
20
  - name: run test
20
21
  run: |
21
22
  npm ci
23
+ npx playwright install
22
24
  npm run test:full
23
25
  - name: pack and set vars
24
26
  id: vars
25
27
  run: |
26
28
  tagName="${GITHUB_REF#refs/*/}"
27
29
  originalTarName="$(npm pack)"
28
- packageName="$(npm -s run env echo '$npm_package_name')"
30
+ packageNameWithoutFileExtension="${originalTarName%.tgz}"
31
+ tagNameWithoutV="${tagName##v}"
32
+ packageName="${packageNameWithoutFileExtension%-$tagNameWithoutV}"
29
33
  newTarName="$packageName-$tagName.tgz"
30
34
  mv "$originalTarName" "$newTarName"
31
35
  echo ::set-output name=tarName::"$newTarName"
@@ -12,14 +12,15 @@ jobs:
12
12
  fail-fast: false
13
13
  matrix:
14
14
  os: [ubuntu-latest, windows-latest, macos-latest]
15
- node-version: [14.x, 16.x]
15
+ node-version: [16.x, 18.x]
16
16
  steps:
17
- - uses: actions/checkout@v1
17
+ - uses: actions/checkout@v3
18
18
  - name: Use Node.js ${{ matrix.node-version }}
19
- uses: actions/setup-node@v1
19
+ uses: actions/setup-node@v3
20
20
  with:
21
21
  node-version: ${{ matrix.node-version }}
22
22
  - name: run test
23
23
  run: |
24
24
  npm ci
25
+ npx playwright install --with-deps
25
26
  npm run test:full
package/.mocharc.js ADDED
@@ -0,0 +1,9 @@
1
+ const baseOptions = require('./.virmator/mocharc-base');
2
+
3
+ /** @type {import('mocha').MochaOptions} */
4
+ const mochaConfig = {
5
+ ...baseOptions,
6
+ parallel: false,
7
+ };
8
+
9
+ module.exports = mochaConfig;
package/.prettierignore CHANGED
@@ -1,6 +1,5 @@
1
+ /Icon?
1
2
  dist/
2
3
  node_modules/
3
4
  package-lock.json
4
- test-files/format/
5
- extender-configs/
6
- dist/vite/
5
+ test-files/format/
package/README.md CHANGED
@@ -1,5 +1,3 @@
1
- [![tests](https://github.com/electrovir/virmator/actions/workflows/virmator-tests.yml/badge.svg?branch=main)](https://github.com/electrovir/virmator/actions/workflows/virmator-tests.yml)
2
-
3
1
  # virmator
4
2
 
5
3
  Centralize and automate all the things! So I don't have to copy pasta configs in every single project.
@@ -10,17 +8,17 @@ Centralize and automate all the things! So I don't have to copy pasta configs in
10
8
  npm -i D virmator
11
9
  ```
12
10
 
13
- # Usage
11
+ # Help
14
12
 
15
13
  ```bash
16
14
  npx virmator --help
17
15
  ```
18
16
 
19
- Output from the help command:
17
+ Below is full documentation for the cli, which is generated via the cli's `help` message:
20
18
 
21
19
  <!-- usage below -->
22
20
 
23
- ## virmator usage
21
+ # virmator usage
24
22
 
25
23
  ```
26
24
  [npx] virmator [--flags] command subCommand
@@ -28,148 +26,135 @@ Output from the help command:
28
26
 
29
27
  `npx` is needed when the command is run directly from the terminal (not scoped within an npm script) unless the package has been globally installed (which will work just fine but I wouldn't recommend, simply because I prefer explicit dependencies).
30
28
 
31
- ## available flags
32
-
33
- ### `--extendable-config`
29
+ # Available flags
34
30
 
35
- Not supported by all commands. Rather than updating the current command's relevant config file directly, commands will write an extendable config file so that the user can extend and override config values.
36
-
37
- ### `--help`
31
+ ## `--help`
38
32
 
39
33
  Prints this help message.
40
34
 
41
- ### `--no-write-config`
42
-
43
- Prevents a command from overwriting its relevant config file (if one exists, which they usually do).
44
-
45
- ### `--silent`
35
+ ## `--silent`
46
36
 
47
37
  Turns off most logging.
48
38
 
49
- ## available commands
39
+ # Available commands
50
40
 
51
- ### code-in-markdown
41
+ ## code-in-markdown
52
42
 
53
43
  Insert code snippets into markdown files. This uses the markdown-code-example-inserter package to expand code link comments inside of markdown files to actual markdown code blocks. See that package's README for more details but the basics are that you need a comment that looks like the following in your markdown file for this to do anything: `<!-- example-link: path/to/file.ts -->`
54
44
 
55
45
  By default this command parses all markdown files in the repo (ignoring node_modules). Specific markdown files can be parsed by giving virmator extra parameters.
56
46
 
57
- #### Examples
47
+ To check if files are up-to-date (rather than actually updating them), use the "check" sub-command.
48
+
49
+ ### Examples
58
50
 
59
51
  - default experience (usually all you need): `virmator code-in-markdown`
52
+ - checking if files are up-to-date: `virmator code-in-markdown check`
60
53
  - override files to check to a single file: `virmator code-in-markdown only/this/one/file.md`
61
54
  - override files to check to a group of files: `virmator code-in-markdown "only/this/dir/*.md"`
62
55
 
63
- ### compile
56
+ ### check
57
+
58
+ Check that markdown files have their examples inserted and are up-to-date.
59
+
60
+ ## compile
64
61
 
65
62
  compile typescript files
66
63
  Pass any extra tsc flags to this command.
67
64
 
68
- #### Examples
65
+ ### Examples
69
66
 
70
67
  - no extra flags: `virmator compile`
71
68
  - one extra flag: `virmator compile --noEmit`
72
69
 
73
- ### format
70
+ ### check
74
71
 
75
- Formats source files with Prettier.
72
+ Run type checking without emitting compiled files.
76
73
 
77
- #### operation commands:
74
+ ## format
78
75
 
79
- This is optional but if provided it must come first. write is the default.
80
- write: overwrites files to fix formatting.
81
- check: checks the formatting, does not write to files
76
+ Formats source files with Prettier.
82
77
 
83
- #### file extensions:
78
+ ### file extensions:
84
79
 
85
- If only specific file extensions should be formatted, add the "--format-files" argument to this command. All following arguments will be treated as file extensions to be formatted. For example, the following command will overwrite files (because write is the default operation) only if they have the extension ".md" or ".json": virmator format --format-files md json
80
+ If only specific file extensions should be formatted, add the "--file-types" argument to this command. All following arguments will be treated as file extensions to be formatted. For example, the following command will format files only if they have the extension ".md" or ".json": virmator format --file-types md json
86
81
 
87
- #### Prettier flags:
82
+ ### Prettier flags:
88
83
 
89
- Any other arguments encountered between the operation command (if provided) and the "--format-files" marker are treated as extra arguments to Prettier and will be passed along.
84
+ Any other arguments encountered between the operation command (if provided) and the "--file-types" marker are treated as extra arguments to Prettier and will be passed along.
90
85
 
91
- #### Examples
86
+ ### Examples
92
87
 
93
88
  - checks formatting for files: `virmator format check`
94
- - checks formatting only for .md files: `virmator format check --format-files md`
95
- - checks formatting only for .md and .json files: `virmator format check --format-files md json`
89
+ - checks formatting only for .md files: `virmator format check --file-types md`
90
+ - checks formatting only for .md and .json files: `virmator format check --file-types md json`
96
91
  - fixes formatting for files:
97
92
 
98
93
  ```
99
94
  virmator format
100
- virmator format write
95
+ virmator format
101
96
  ```
102
97
 
103
98
  - examples with extra Prettier flags:
104
99
  ```
105
100
  virmator format --ignore-path .prettierignore
106
- virmator format write --ignore-path .prettierignore
107
- virmator format write --ignore-path .prettierignore --format-files md json
101
+ virmator format --ignore-path .prettierignore
102
+ virmator format --ignore-path .prettierignore --file-types md json
108
103
  ```
109
104
 
110
- ### help
105
+ ### check
111
106
 
112
- Prints this help message.
107
+ check formatting without overwriting files.
108
+
109
+ ## frontend
110
+
111
+ Runs a frontend. Currently uses vite.
112
+
113
+ ### build
114
+
115
+ Builds and bundles the frontend for deployment.
116
+
117
+ ### preview
113
118
 
114
- ### test
119
+ Builds and previews the built output.
115
120
 
116
- Init everything, including package.json scripts.
117
- If no package.json file is found, one is created and initialized.
118
- Pass --force to this command to overwrite current package.json scripts.
121
+ ## help
119
122
 
120
- ### spellcheck
123
+ Prints this help output.
121
124
 
122
- Spellcheck code with cspell. Any extra arguments are passed directly to cspell.
125
+ ## init
123
126
 
124
- ### test
127
+ Initialize a repo with all virmator config files.
125
128
 
126
- Test all .test.ts files with jest. By default this command tests all .test.ts files in the current directory that are not .type.test.ts files. To override this behavior, pass in a custom config file with Jest's --config argument. The default Jest config file can be extended by importing it with "import {virmatorJestConfig} from 'virmator'". All other Jest inputs are also valid.
129
+ ## spellcheck
127
130
 
128
- #### Examples
131
+ Spellcheck code with cspell. By default this spellchecks every file in the entire repo (except for those ignored in the config file), including .dot files. If any arguments are passed to this command, the default cspell args that this command applies are ignored, you'll have to supply them via your args.
129
132
 
130
- - `virmator test ./path/to/single/file.js`
131
- - `virmator test "./**/single-file.js"`
132
- - `virmator test "./dist/**/!(*.type).test.js"`
133
+ ## test
133
134
 
134
- ### update-all-configs
135
+ Test all .test.ts files with Mocha and Chai. By default this command tests all ".test.ts" files in the current directory (recursively) that are not ".type.test.ts" files. To override this behavior, override the "spec" property in .mocharc.js.
135
136
 
136
- Update all config files. This command accepts a list of config file keys as arguments. If no arguments are given, this command copies all config files.
137
+ This command is meant to run Node.js tests. For running web-based testing, see the test-web command.
137
138
 
138
- #### list of possible arguments:
139
+ Note that the below single file examples only work because the base Mocha config from virmator is setup to handle them. (So if you don't use that config, the examples may not work properly.)
139
140
 
140
- Cspell
141
- JestConfig
142
- JestSetup
143
- PackageJson
144
- Prettier
145
- PrettierIgnore
146
- TsConfig
147
- GitAttributes
148
- GitHubActionsTaggedRelease
149
- GitHubActionsTest
150
- GitIgnore
151
- NpmIgnore
152
- VsCodeSettings
141
+ ### Examples
153
142
 
154
- #### Examples
143
+ - Test all .test.ts and .test.tsx files: `virmator test`
144
+ - Test a single file: `virmator test ./path/to/single/file.js`
145
+ - Test multiple files: `virmator test "./**/single-file.js"`
155
146
 
156
- - update all config files: `virmator update-all-configs`
157
- - update only Cspell and GitIgnore files: `virmator update-all-configs Cspell GitIgnore`
147
+ ## test-web
158
148
 
159
- ### update-bare-configs
149
+ Runs tests within browsers rather than inside of Node.js. Test files fed into this command cannot be mixed with test files run by the "virmator test" command, as the run-time environment is quite different (Node.js vs browser). However, just like the test command, this command will all ".test.ts" files in the current directory (recursively) that are not ".type.test.ts" files. To override this behavior, override the "files" property in web-test-runner.config.mjs.
160
150
 
161
- Update config files that aren't used in any virmator commands, like GitHub actions tests or VS Code Settings. This command accepts a list of bare config file keys as arguments. If no arguments are given, this command copies all the bare config files.
151
+ By default this command runs all tests three times: in Chromium (Chrome), Firefox, and Webkit (Safari) using playwright.
162
152
 
163
- #### list of possible arguments:
153
+ ### Examples
164
154
 
165
- GitAttributes
166
- GitHubActionsTaggedRelease
167
- GitHubActionsTest
168
- GitIgnore
169
- NpmIgnore
170
- VsCodeSettings
155
+ - Test all .test.ts and .test.tsx files: `virmator test-web`
156
+ - Test a specific file: `virmator test-web path/to/file.test.ts`
171
157
 
172
- #### Examples
158
+ ## update-configs
173
159
 
174
- - update all bare config files: `virmator update-bare-configs`
175
- - update only GitIgnore and NpmIgnore files: `virmator update-bare-configs GitIgnore NpmIgnore,`
160
+ Update all existing configuration files that virmator is able to update. (Like base config files.)
@@ -0,0 +1,4 @@
1
+ {
2
+ "import": ".virmator/.cspell-base.json",
3
+ "words": []
4
+ }
@@ -0,0 +1 @@
1
+ * text=auto eol=lf
@@ -0,0 +1,8 @@
1
+ const baseOptions = require('./.virmator/mocharc-base');
2
+
3
+ /** @type {import('mocha').MochaOptions} */
4
+ const mochaConfig = {
5
+ ...baseOptions,
6
+ };
7
+
8
+ module.exports = mochaConfig;
@@ -0,0 +1,6 @@
1
+ /Icon?
2
+ coverage/
3
+ dist/
4
+ graphics/
5
+ node_modules/
6
+ package-lock.json
@@ -0,0 +1,13 @@
1
+ const baseConfig = require('./.virmator/prettierrc-base.js');
2
+
3
+ /**
4
+ * @typedef {import('prettier-plugin-multiline-arrays').MultilineArrayOptions} MultilineOptions
5
+ *
6
+ * @typedef {import('prettier').Options} PrettierOptions
7
+ * @type {PrettierOptions & MultilineOptions}
8
+ */
9
+ const prettierConfig = {
10
+ ...baseConfig,
11
+ };
12
+
13
+ module.exports = prettierConfig;
@@ -1,8 +1,10 @@
1
1
  {
2
+ "globRoot": "..",
2
3
  "ignorePaths": [
3
4
  ".DS_Store",
4
5
  ".git/",
5
6
  "dist/",
7
+ "coverage/",
6
8
  "node_modules/",
7
9
  "package-lock.json",
8
10
  ".cspell-base.json",
@@ -26,6 +28,8 @@
26
28
  "entrypoint",
27
29
  "entrypoints",
28
30
  "esbenp",
31
+ "esbuild",
32
+ "esbuild",
29
33
  "estree",
30
34
  "fleek",
31
35
  "gitattributes",
@@ -37,6 +41,7 @@
37
41
  "locationchange",
38
42
  "marvinpinto",
39
43
  "mmultiline",
44
+ "mocharc",
40
45
  "monospace",
41
46
  "msapplication",
42
47
  "mstile",
@@ -0,0 +1,15 @@
1
+ const allTestFiles = 'src/**/!(*.type).test.ts?(x)';
2
+ const isTestingOtherFiles = process.argv.some((arg) => arg.match(/\.tsx?$/));
3
+
4
+ /** @type {import('mocha').MochaOptions} */
5
+ const mochaConfig = {
6
+ checkLeaks: true,
7
+ color: true,
8
+ parallel: true,
9
+ require: 'ts-node/register',
10
+ slow: '1500', // ms
11
+ timeout: '60000', // ms
12
+ ...(isTestingOtherFiles ? {} : {spec: allTestFiles}),
13
+ };
14
+
15
+ module.exports = mochaConfig;
@@ -0,0 +1,62 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ function toPosixPath(input) {
5
+ return input.replace(/\\/g, '/').replace(/^\w+:/, '');
6
+ }
7
+
8
+ const posixDirname = path.posix.dirname(toPosixPath(__dirname));
9
+
10
+ function findClosestNodeModulesPath(dirPath = __dirname) {
11
+ const currentAttempt = path.join(dirPath, 'node_modules');
12
+ if (fs.existsSync(currentAttempt)) {
13
+ return currentAttempt;
14
+ } else if (dirPath === '/') {
15
+ throw new Error(`Could not find node_modules directory.`);
16
+ } else {
17
+ return findClosestNodeModulesPath(path.dirname(dirPath));
18
+ }
19
+ }
20
+
21
+ const nodeModules = toPosixPath(findClosestNodeModulesPath());
22
+
23
+ const plugins = [
24
+ 'prettier-plugin-toml',
25
+ 'prettier-plugin-sort-json',
26
+ 'prettier-plugin-packagejson',
27
+ 'prettier-plugin-multiline-arrays',
28
+ 'prettier-plugin-organize-imports',
29
+ 'prettier-plugin-jsdoc',
30
+ ].map((pluginName) => {
31
+ // account for installations where node_modules is flattened and installations where it's nested
32
+ const flattenedPath = path.posix.join(nodeModules, pluginName);
33
+ const nestedPath = path.posix.join(nodeModules, 'virmator', 'node_modules', pluginName);
34
+
35
+ if (fs.existsSync(flattenedPath)) {
36
+ return path.posix.resolve(posixDirname, flattenedPath);
37
+ } else {
38
+ return path.posix.resolve(posixDirname, nestedPath);
39
+ }
40
+ });
41
+
42
+ /**
43
+ * @typedef {import('prettier-plugin-multiline-arrays').MultilineArrayOptions} MultilineOptions
44
+ *
45
+ * @typedef {import('prettier').Options} PrettierOptions
46
+ * @type {PrettierOptions & MultilineOptions}
47
+ */
48
+ const prettierConfig = {
49
+ arrowParens: 'always',
50
+ bracketSpacing: false,
51
+ endOfLine: 'lf',
52
+ htmlWhitespaceSensitivity: 'ignore',
53
+ jsonRecursiveSort: true,
54
+ bracketSameLine: false,
55
+ plugins,
56
+ printWidth: 100,
57
+ singleQuote: true,
58
+ tabWidth: 4,
59
+ trailingComma: 'all',
60
+ };
61
+
62
+ module.exports = prettierConfig;
@@ -1,31 +1,35 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "alwaysStrict": true,
4
- "baseUrl": ".",
5
4
  "declaration": true,
6
5
  "esModuleInterop": true,
7
6
  "exactOptionalPropertyTypes": true,
8
7
  "forceConsistentCasingInFileNames": true,
8
+ "isolatedModules": true,
9
9
  "module": "CommonJS",
10
10
  "moduleResolution": "Node",
11
+ "noEmitOnError": true,
12
+ "noErrorTruncation": true,
11
13
  "noImplicitAny": true,
12
14
  "noImplicitOverride": true,
13
15
  "noImplicitReturns": true,
14
16
  "noImplicitThis": true,
15
17
  "noUncheckedIndexedAccess": true,
16
- "outDir": "dist",
17
- "rootDir": "src",
18
+ "outDir": "../dist",
19
+ "pretty": true,
20
+ "resolveJsonModule": true,
21
+ "rootDir": "../src",
18
22
  "skipDefaultLibCheck": true,
19
23
  "skipLibCheck": true,
20
24
  "strict": true,
21
- "target": "ESNext",
25
+ "target": "ES2019",
22
26
  "useUnknownInCatchVariables": true
23
27
  },
24
28
  "exclude": [
25
- "dist",
26
- "node_modules",
27
- "separate-configs",
28
- "test-files"
29
+ "../dist",
30
+ "../node_modules",
31
+ "../test-files",
32
+ "../.virmator"
29
33
  ],
30
34
  "ts-node": {
31
35
  "compilerOptions": {
@@ -0,0 +1,90 @@
1
+ import chalk from 'chalk';
2
+ import {existsSync, lstatSync, readlinkSync} from 'fs';
3
+ import {relative} from 'path';
4
+ import {PluginOption} from 'vite';
5
+
6
+ /**
7
+ * Include actual paths and symlinked target paths if they exist.
8
+ *
9
+ * This is needed because when removing files from the watcher, sym links have be removed with the
10
+ * path to the symlink itself AND the path to the symlink target or the path will still be watched.
11
+ */
12
+ function mapToActualPaths(paths: Readonly<string[]>): Readonly<string[]> {
13
+ return paths.reduce((accum, path) => {
14
+ if (existsSync(path)) {
15
+ if (lstatSync(path).isSymbolicLink()) {
16
+ console.info('reading symlink from', path);
17
+ // sym links AND the original path both need to be included
18
+ return accum.concat(readlinkSync(path), path);
19
+ } else {
20
+ return accum.concat(path);
21
+ }
22
+ } else {
23
+ return accum;
24
+ }
25
+ }, [] as string[]);
26
+ }
27
+
28
+ /**
29
+ * There are similar plugins out there that try to do this but they aren't aggressive enough. This
30
+ * plugin literally always reloads on save, no questions asked.
31
+ */
32
+ export function alwaysReloadPlugin(
33
+ config: Partial<{
34
+ exclusions: string[];
35
+ /** Inclusions apply after exclusions so they will override exclusions. */
36
+ inclusions: string[];
37
+ root: string;
38
+ }> = {},
39
+ ): PluginOption {
40
+ return {
41
+ name: 'alwaysReloadPlugin',
42
+ apply: 'serve',
43
+ config: () => ({server: {watch: {disableGlobbing: false}}}),
44
+ configureServer({watcher, ws, config: {logger}}) {
45
+ const {root = process.cwd(), inclusions = [], exclusions = []} = config;
46
+ let callingAlready = false;
47
+ let loggedAlready = false;
48
+
49
+ const reloadCallback = (path: string) => {
50
+ if (!loggedAlready) {
51
+ loggedAlready = true;
52
+ // log watched stuff so that we can make sure it's not watching too much
53
+ // console.info({watched: watcher.getWatched()});
54
+ }
55
+ // prevent duplicate calls cause the watcher is very eager to call callbacks multiple times in a row
56
+ if (!callingAlready) {
57
+ callingAlready = true;
58
+ ws.send({
59
+ type: 'full-reload',
60
+ path: '*',
61
+ });
62
+ logger.info(
63
+ `${chalk.green('page reload')} ${chalk.dim(relative(root, path))}`,
64
+ {clear: true, timestamp: true},
65
+ );
66
+ /**
67
+ * Debounce reloads calls so that they don't get spammed. If you're saving
68
+ * faster than this, then what the heck are you doing anyway?
69
+ */
70
+ setTimeout(() => {
71
+ callingAlready = false;
72
+ }, 100);
73
+ }
74
+ };
75
+
76
+ if (exclusions.length) {
77
+ watcher.unwatch(mapToActualPaths(exclusions));
78
+ // ignore macOS file system metadata stuff
79
+ watcher.unwatch('./**/.DS_Store');
80
+ }
81
+ if (inclusions.length) {
82
+ watcher.add(inclusions);
83
+ }
84
+ if (!watcher.listeners('change').includes(reloadCallback)) {
85
+ watcher.on('change', reloadCallback);
86
+ watcher.on('add', reloadCallback);
87
+ }
88
+ },
89
+ };
90
+ }
@@ -0,0 +1,11 @@
1
+ import {dirname} from 'path';
2
+ import {UserConfig} from 'vite';
3
+ import {alwaysReloadPlugin} from './vite-always-reload-plugin';
4
+
5
+ const viteConfig: UserConfig = {
6
+ clearScreen: false,
7
+ plugins: [alwaysReloadPlugin()],
8
+ root: dirname(__dirname),
9
+ };
10
+
11
+ export default viteConfig;
@@ -0,0 +1,8 @@
1
+ import {UserConfig} from 'vite';
2
+ import baseConfig from './vite-base';
3
+
4
+ const viteConfig: UserConfig = {
5
+ ...baseConfig,
6
+ };
7
+
8
+ export default viteConfig;