create-juisy 2.0.0-beta.9 → 2.1.0

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 (47) hide show
  1. package/LICENSE +661 -0
  2. package/index.js +45 -17
  3. package/package.json +57 -59
  4. package/template/.env.example +1 -1
  5. package/template/COMMIT_CONVENTION.md +116 -0
  6. package/template/CONTRIBUTING.md +61 -0
  7. package/template/bin/cli/cli.js +11 -14
  8. package/template/bin/cli/cmds/index.js +4 -6
  9. package/template/bin/cli/cmds/private/docs/{generate-api.js → GenerateAPI.js} +28 -7
  10. package/template/bin/cli/cmds/private/docs/index.js +30 -11
  11. package/template/bin/cli/cmds/private/test.js +40 -25
  12. package/template/bin/cli/index.js +4 -2
  13. package/template/bin/scripts/commit-msg.js +13 -18
  14. package/template/bin/scripts/pre-commit.js +13 -11
  15. package/template/dev.config.js +37 -5
  16. package/template/dev.config.json +19 -1
  17. package/template/dev.config.ts +40 -1
  18. package/template/docs/.markdownlint-cli2.mjs +21 -0
  19. package/template/docs/cli/private/config.js +37 -0
  20. package/template/docs/cli/private/data.js +14 -0
  21. package/template/docs/cli/private/partials/child-command.md +26 -0
  22. package/template/docs/cli/private/template.md +26 -0
  23. package/template/docs/cli/public/config.js +21 -0
  24. package/template/docs/cli/public/template.md +19 -0
  25. package/template/docs/readme/config.js +24 -13
  26. package/template/docs/readme/data.js +45 -0
  27. package/template/docs/readme/template.md +37 -9
  28. package/template/eslint.config.js +47 -0
  29. package/template/package.json +9 -6
  30. package/template/project.globals.js +20 -29
  31. package/template/tests/unit/example.spec.ts +13 -0
  32. package/template/tests/unit/setup.unit.ts +14 -0
  33. package/template/tests/vitest.d.ts +16 -0
  34. package/template/tsconfig.json +18 -0
  35. package/template/vite.config.ts +22 -0
  36. package/template/bin/cli/cmds/private/changelog.js +0 -44
  37. package/template/bin/cli/cmds/private/docs/generate-cli.js +0 -11
  38. package/template/bin/cli/cmds/private/docs/generate-readme.js +0 -11
  39. package/template/bin/cli/cmds/private/docs/lint.js +0 -42
  40. package/template/bin/cli/cmds/private/git-hooks/index.js +0 -20
  41. package/template/bin/cli/cmds/private/git-hooks/reset.js +0 -48
  42. package/template/bin/cli/cmds/private/git-hooks/sync.js +0 -19
  43. package/template/bin/cli/cmds/private/release.js +0 -223
  44. package/template/bin/cli/lib/docs/generate-api-doc.js +0 -33
  45. package/template/bin/cli/lib/release/generate-release-note.js +0 -3
  46. package/template/bin/cli/lib/version/update-version.js +0 -51
  47. package/template/docs/readme/readme.js +0 -70
package/index.js CHANGED
@@ -17,6 +17,7 @@ const __filename = fileURLToPath(import.meta.url)
17
17
  const __dirname = dirname(__filename)
18
18
 
19
19
  const {
20
+ abort,
20
21
  run,
21
22
  prompts
22
23
  } = InterfaceUtils
@@ -39,7 +40,10 @@ const argv = mri(process.argv.slice(2), {
39
40
  const cwd = process.cwd()
40
41
 
41
42
  // Get juisy version from this package.json file
42
- const { version: JUISY_VERSION } = JSON.parse(
43
+ const {
44
+ version: JUISY_VERSION,
45
+ homepage: JUISY_DOCS_HOMEPAGE
46
+ } = JSON.parse(
43
47
  fs.readFileSync(path.resolve(__dirname, './package.json'), 'utf-8')
44
48
  )
45
49
 
@@ -64,7 +68,11 @@ async function main () {
64
68
  initial: defaultTargetDir,
65
69
  name: 'projectName'
66
70
  }
67
- ])
71
+ ], {
72
+ onCancel: () => {
73
+ abort(1)
74
+ }
75
+ })
68
76
  targetDir = rmTrailingSlashes(promptsResult.projectName)
69
77
  }
70
78
 
@@ -81,7 +89,11 @@ async function main () {
81
89
  initial: 0,
82
90
  name: 'devConfigFormat'
83
91
  }
84
- ])
92
+ ], {
93
+ onCancel: () => {
94
+ abort(1)
95
+ }
96
+ })
85
97
  devConfigFormat = promptsResult.devConfigFormat
86
98
 
87
99
  /**
@@ -98,13 +110,21 @@ async function main () {
98
110
  'dev.config.json'
99
111
  ].filter(identifier => !identifier.endsWith(devConfigFormat)), // don't ignore dev config file of chosen format
100
112
  logLevel: 'warn',
101
- processor: (content, identifier) => {
102
- if (identifier === 'package.json') {
103
- return content.replace(/__JUISY_VERSION__/g, JUISY_VERSION)
104
- } else {
105
- return content
113
+ templateData: (identifier) => {
114
+ return {
115
+ __PROJECT_NAME__: targetDir,
116
+ __JUISY_VERSION__: JUISY_VERSION,
117
+ __JUISY_DOCS_HOMEPAGE__: JUISY_DOCS_HOMEPAGE
106
118
  }
107
119
  }
120
+ // processor: (content, identifier) => {
121
+ // if (identifier === 'package.json') {
122
+ // let newContent = content.replace(/__PROJECT_NAME__/g, targetDir)
123
+ // return newContent
124
+ // } else {
125
+ // return content
126
+ // }
127
+ // }
108
128
  })
109
129
 
110
130
  substep($style.green(`✔ Successfuly copied`), { last: true })
@@ -116,25 +136,30 @@ async function main () {
116
136
  * Update package.json file
117
137
  */
118
138
  const scripts = {
119
- 'docs:api': `${targetCliCommand} docs generate -c ./docs/docs.config.js`,
139
+ 'docs:api': `${targetCliCommand} docs generate:api`,
120
140
  'docs:readme': `${targetCliCommand} docs generate:readme`,
121
- 'docs:lint': `${targetCliCommand} docs lint`,
122
- 'docs:lint:fix': 'npm run docs:lint -- --fix',
123
- 'docs': 'npm run docs:readme && npm run docs:api && npm run docs:lint',
141
+ 'docs:cli': 'npm run docs:cli:private && npm run docs:cli:public',
142
+ 'docs:cli:private': `${targetCliCommand} docs generate:cli -c ./docs/cli/private/config.js`,
143
+ 'docs:cli:public': `${targetCliCommand} docs generate:cli -c ./docs/cli/public/config.js`,
144
+ 'docs': 'npm run docs:readme && npm run docs:cli && npm run docs:api && npm run lint:markdown:fix',
124
145
  'lint': `${targetCliCommand} lint`,
125
146
  'lint:fix': 'npm run lint -- --fix',
126
- 'lint:markdown': 'npm run docs:lint',
127
- 'lint:markdown:fix': 'npm run docs:lint:fix',
147
+ 'lint:markdown': 'node ./bin/cli lint:markdown',
148
+ 'lint:markdown:fix': 'npm run lint:markdown -- --fix',
128
149
  'release': `${targetCliCommand} release`,
129
150
  'changelog': `${targetCliCommand} changelog`,
130
151
  'git-hooks:reset': `${targetCliCommand} git-hooks reset`,
131
152
  'git-hooks:sync': `${targetCliCommand} git-hooks sync`,
132
- 'test': `${targetCliCommand} test`
153
+ 'test': `${targetCliCommand} test run`,
154
+ 'test:watch': `${targetCliCommand} test`,
155
+ 'test:ui': 'npm run test:watch -- --ui --coverage.enabled=true',
156
+ 'test:coverage': 'npm run test -- --coverage.enabled=true'
133
157
  }
134
158
 
135
159
  step('Adding scripts to package.json')
160
+ const packageJsonPath = path.join(path.resolve(cwd, targetDir), 'package.json')
136
161
  const pkg = JSON.parse(
137
- fs.readFileSync(path.join(path.resolve(cwd, targetDir), 'package.json'), 'utf-8')
162
+ fs.readFileSync(packageJsonPath, 'utf-8')
138
163
  )
139
164
  pkg.scripts = pkg.scripts || {}
140
165
 
@@ -145,13 +170,16 @@ async function main () {
145
170
  : true
146
171
  const isLastStep = scriptName === Object.keys(scripts)[Object.keys(scripts).length - 1]
147
172
  if (setScript) {
148
- await run('npm', [ 'set-script', scriptName, scripts[scriptName] ], { stdio: 'pipe', cwd: path.resolve(cwd, targetDir) })
173
+ pkg.scripts[scriptName] = scripts[scriptName]
149
174
  substep($style.green(`✔ Script "${scriptName}" successfuly added`), { last: isLastStep })
150
175
  } else {
151
176
  substep($style.yellow(`Script "${scriptName}" already set. Use --force option to overwrite`), { last: isLastStep })
152
177
  }
153
178
  }
154
179
 
180
+ // Replace package.json content
181
+ fs.writeFileSync(packageJsonPath, JSON.stringify(pkg, null, 2) + '\n')
182
+
155
183
  log() // Blank line
156
184
  log('You should now move into the created folder and run the following command:\n - npm install')
157
185
  log() // Blank line
package/package.json CHANGED
@@ -1,63 +1,61 @@
1
1
  {
2
- "name": "create-juisy",
3
- "version": "2.0.0-beta.9",
4
- "description": "Juisy boilerplate for npm init",
5
- "type": "module",
6
- "bin": {
7
- "create-juisy": "index.js"
8
- },
9
- "files": [
10
- "template",
11
- "index.js"
12
- ],
13
- "publishConfig": {
14
- "access": "public"
15
- },
16
- "scripts": {
17
- "release": "release-it",
18
- "test": "echo No test found..."
19
- },
20
- "repository": {
21
- "type": "git",
22
- "url": "git+https://gitlab.com/hperchec/juisy.git"
23
- },
24
- "keywords": [
25
- "js",
26
- "build",
27
- "release",
28
- "changelog",
29
- "bin",
30
- "cmd",
31
- "easy"
32
- ],
33
- "author": {
34
- "name": "Hervé Perchec",
35
- "email": "contact@herve-perchec.com",
36
- "url": "https://gitlab.com/herveperchec"
37
- },
38
- "license": "GPL-3.0-only",
39
- "bugs": {
40
- "url": "https://gitlab.com/hperchec/juisy/issues"
41
- },
42
- "homepage": "https://gitlab.com/hperchec/juisy#readme",
43
- "devDependencies": {
44
- "juisy": "2.0.0-beta.9"
45
- },
46
- "dependencies": {
47
- "execa": "^8",
48
- "mri": "^1.2.0"
49
- },
50
- "release-it": {
51
- "git": false,
52
- "plugins": {
53
- "@release-it/bumper": {
54
- "out": {
55
- "file": "package.json",
56
- "path": [
57
- "devDependencies.juisy"
58
- ]
59
- }
60
- }
2
+ "name": "create-juisy",
3
+ "version": "2.1.0",
4
+ "description": "Juisy boilerplate for npm init",
5
+ "type": "module",
6
+ "bin": {
7
+ "create-juisy": "index.js"
8
+ },
9
+ "files": [
10
+ "template",
11
+ "index.js"
12
+ ],
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "scripts": {
17
+ "release": "release-it --no-increment",
18
+ "test": "echo No test found..."
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://gitlab.com/hperchec/juisy.git"
23
+ },
24
+ "keywords": [
25
+ "js",
26
+ "build",
27
+ "release",
28
+ "changelog",
29
+ "bin",
30
+ "cmd",
31
+ "easy"
32
+ ],
33
+ "author": {
34
+ "name": "Hervé Perchec",
35
+ "email": "contact@herve-perchec.com",
36
+ "url": "https://gitlab.com/herveperchec"
37
+ },
38
+ "license": "GPL-3.0-only",
39
+ "bugs": {
40
+ "url": "https://gitlab.com/hperchec/juisy/issues"
41
+ },
42
+ "homepage": "https://hperchec.gitlab.io/juisy",
43
+ "dependencies": {
44
+ "execa": "^9.5.2",
45
+ "juisy": "2.1.0",
46
+ "mri": "^1.2.0"
47
+ },
48
+ "release-it": {
49
+ "git": false,
50
+ "plugins": {
51
+ "@release-it/bumper": {
52
+ "out": {
53
+ "file": "package.json",
54
+ "path": [
55
+ "dependencies.juisy"
56
+ ]
61
57
  }
58
+ }
62
59
  }
60
+ }
63
61
  }
@@ -1,4 +1,4 @@
1
1
  NODE_ENV=development
2
2
 
3
3
  # CLI specific environement variables
4
- __JUISY_CLI_ENV__=private
4
+ CLI_ENV=private
@@ -0,0 +1,116 @@
1
+ # Commit Message Format
2
+
3
+ > ❗ IMPORTANT
4
+ >
5
+ > This documentation is based on Angular [commit message guidelines](https://github.com/angular/angular/blob/main/contributing-docs/commit-message-guidelines.md)
6
+
7
+ We have very precise rules over how our Git commit messages must be formatted.
8
+ This format leads to **easier to read commit history** and makes it analyzable for changelog generation.
9
+
10
+ Each commit message consists of a **header**, a **body**, and a **footer**.
11
+
12
+ ```
13
+ <header>
14
+ <BLANK LINE>
15
+ <body>
16
+ <BLANK LINE>
17
+ <footer>
18
+ ```
19
+
20
+ The `header` is mandatory and must conform to the [Commit Message Header](#commit-header) format.
21
+
22
+ The `body` is mandatory for all commits except for those of type "docs".
23
+ When the body is present it must be at least 20 characters long and must conform to the [Commit Message Body](#commit-body) format.
24
+
25
+ The `footer` is optional. The [Commit Message Footer](#commit-footer) format describes what the footer is used for and the structure it must have.
26
+
27
+ ## Commit Message Header
28
+
29
+ ```
30
+ <type>(<scope>): <short summary>
31
+ │ │ │
32
+ │ │ └─⫸ Summary in present tense. Not capitalized. No period at the end.
33
+ │ │
34
+ │ └─⫸ Commit Scope: see below
35
+
36
+ └─⫸ Commit Type: build|ci|docs|feat|fix|perf|refactor|test
37
+ ```
38
+
39
+ The `<type>` and `<summary>` fields are mandatory, the `(<scope>)` field is optional.
40
+
41
+ ### Type
42
+
43
+ Must be one of the following:
44
+
45
+ | Type | Description |
46
+ |--------------|-----------------------------------------------------------------------------------------------------|
47
+ | **build** | Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm) |
48
+ | **ci** | Changes to our CI configuration files and scripts (examples: Github Actions, SauceLabs) |
49
+ | **docs** | Documentation only changes |
50
+ | **feat** | A new feature |
51
+ | **fix** | A bug fix |
52
+ | **perf** | A code change that improves performance |
53
+ | **refactor** | A code change that neither fixes a bug nor adds a feature |
54
+ | **test** | Adding missing tests or correcting existing tests |
55
+
56
+ ### Scope
57
+ The scope should be the name of the npm package affected (as perceived by the person reading the changelog generated from commit messages).
58
+
59
+ The following is the list of supported scopes:
60
+
61
+ * `scope-a`
62
+ * `scope-b`
63
+ * `scope-c`
64
+
65
+ ### Summary
66
+
67
+ Use the summary field to provide a succinct description of the change:
68
+
69
+ * use the imperative, present tense: "change" not "changed" nor "changes"
70
+ * don't capitalize the first letter
71
+ * no dot (.) at the end
72
+
73
+ ## Commit Message Body
74
+
75
+ Just as in the summary, use the imperative, present tense: "fix" not "fixed" nor "fixes".
76
+
77
+ Explain the motivation for the change in the commit message body. This commit message should explain _why_ you are making the change.
78
+ You can include a comparison of the previous behavior with the new behavior in order to illustrate the impact of the change.
79
+
80
+ ## Commit Message Footer
81
+
82
+ The footer can contain information about breaking changes and deprecations and is also the place to reference GitHub issues and other PRs that this commit closes or is related to.
83
+ For example:
84
+
85
+ ```
86
+ BREAKING CHANGE: <breaking change summary>
87
+ <BLANK LINE>
88
+ <breaking change description + migration instructions>
89
+ <BLANK LINE>
90
+ <BLANK LINE>
91
+ Fixes #<issue number>
92
+ ```
93
+
94
+ or
95
+
96
+ ```
97
+ DEPRECATED: <what is deprecated>
98
+ <BLANK LINE>
99
+ <deprecation description + recommended update path>
100
+ <BLANK LINE>
101
+ <BLANK LINE>
102
+ Closes #<pr number>
103
+ ```
104
+
105
+ Breaking Change section should start with the phrase `BREAKING CHANGE: ` followed by a *brief* summary of the breaking change, a blank line, and a detailed description of the breaking change that also includes migration instructions.
106
+
107
+ Similarly, a Deprecation section should start with `DEPRECATED: ` followed by a short description of what is deprecated, a blank line, and a detailed description of the deprecation that also mentions the recommended update path.
108
+
109
+ ## Revert commits
110
+
111
+ If the commit reverts a previous commit, it should begin with `revert: `, followed by the header of the reverted commit.
112
+
113
+ The content of the commit message body should contain:
114
+
115
+ - information about the SHA of the commit being reverted in the following format: `This reverts commit <SHA>`,
116
+ - a clear description of the reason for reverting the commit message.
@@ -0,0 +1,61 @@
1
+ # Contribution guide
2
+
3
+ ## Commits
4
+
5
+ Commit messages are linted with `commitlint` in the `commit-msg` git hook, following the **angular** convention. Please check the [commit convention](./COMMIT_CONVENTION.md).
6
+
7
+ ## Build
8
+
9
+ Write here the instructions to build your code, if needed.
10
+
11
+ To build, run the following command:
12
+
13
+ ```sh
14
+ npm run build
15
+ ```
16
+
17
+ ## Tests
18
+
19
+ ### Units
20
+
21
+ To run unit tests, run the following command:
22
+
23
+ ```sh
24
+ npm run test
25
+ # With coverage enabled
26
+ npm run test:coverage
27
+ # Watch mode
28
+ npm run test:watch
29
+ # With @vitest/ui
30
+ npm run test:ui
31
+ ```
32
+
33
+ ## Releases
34
+
35
+ Run the following command to make a release:
36
+
37
+ ```sh
38
+ # Show help
39
+ npm run release -- --help
40
+ # Release a patch
41
+ npm run release -- --increment patch
42
+ # Release a specific version
43
+ npm run release -- -i 2.0.0
44
+ # To increment the current prerelease. For example:
45
+ # from 1.0.0-beta.1
46
+ # to 1.0.0-beta.2
47
+ npm run release -- -i pre
48
+ ```
49
+
50
+ > 💡 See also:
51
+ >
52
+ > - the **juisy** [release tool documentation](<%= __JUISY_DOCS_HOMEPAGE__ %>)
53
+ > - the **release-it** [package documentation](https://github.com/release-it/release-it)
54
+
55
+ ## Documentation
56
+
57
+ Run the following command to generate project documentation:
58
+
59
+ ```sh
60
+ npm run docs
61
+ ```
@@ -1,27 +1,24 @@
1
- const { createCli, utils } = require('@hperchec/juisy')
2
- const path = require('path')
3
- const {
4
- rootDir,
5
- $style
6
- } = utils
7
- // Get package.json content
8
- const packageJson = require(path.resolve(rootDir, './package.json'))
1
+ import { CLIFactory } from 'juisy/cli'
2
+
3
+ import { commands } from './cmds/index.js'
4
+
5
+ const { $style } = CLI.OutputUtils
9
6
 
10
7
  function getBanner () {
11
8
  let str = ''
12
- const title = $style.bold('CLI: ') + packageJson.name
13
- const length = title.length - 9 // removes characters generated by $style.bold from length
9
+ const title = 'Built with Juisy'
10
+ const length = title.length
14
11
  str += $style.cyan('-'.repeat(length) + '\n')
15
12
  str += $style.cyan(title + '\n')
16
13
  str += $style.cyan('-'.repeat(length) + '\n')
17
- str += $style.italic('Made with') + ' ' + $style.red('❤') + ' ' + $style.italic('by ') + $style.bold('Hervé Perchec <contact@herve-perchec.com') + '\n'
14
+ str += $style.italic('Made with') + ' ' + $style.red('❤') + ' ' + $style.italic('by ') + $style.bold('Hervé Perchec') + '\n'
18
15
  return str
19
16
  }
20
17
 
21
- // CLI
22
- module.exports = createCli(cli => cli
18
+ export default await CLIFactory(cli => cli
23
19
  .scriptName('./bin/cli')
24
20
  .usage(`${getBanner()}\nUsage: $0 <command> [<options>]`)
25
- .commandDir('cmds')
21
+ .disableDefaultCommand('docs generate:api')
22
+ .command(commands)
26
23
  .demandCommand(1, ('Command is missing. See help to learn more.').red)
27
24
  )
@@ -1,13 +1,11 @@
1
1
  // Private commands
2
- import docs from './private/docs/index.js'
3
- import release from './private/release.js'
4
- import test from './private/test.js'
2
+ import Docs from './private/docs/index.js'
3
+ import Test from './private/test.js'
5
4
 
6
5
  export const commands = [
7
6
  // Private commands
8
- docs,
9
- release,
10
- test
7
+ Docs,
8
+ Test
11
9
  // Public commands
12
10
  // ...
13
11
  ]
@@ -1,10 +1,31 @@
1
- /** @type {import('juisy/cli').Command} */
2
- export default new CLI.Command({
3
- command: 'generate:api',
4
- describe: 'Generate API docs from source code',
1
+ export default class GenerateAPI extends CLI.Command {
2
+ /**
3
+ * The command signature
4
+ */
5
+ command = 'generate:api'
6
+
7
+ /**
8
+ * The command description
9
+ */
10
+ describe = 'Generate API docs from source code'
11
+
12
+ /**
13
+ * The command meta
14
+ */
15
+ meta = {
16
+ private: true
17
+ }
18
+
19
+ /**
20
+ * Command builder
21
+ */
5
22
  builder (cli) {
6
- cli
7
- },
23
+ return cli
24
+ }
25
+
26
+ /**
27
+ * Command handler
28
+ */
8
29
  async handler (argv) {
9
30
  // Utils
10
31
  const { $style, step, substep } = CLI.OutputUtils
@@ -19,4 +40,4 @@ export default new CLI.Command({
19
40
  this.log($style.yellow('You can use JSDoc or TypeDoc for example. See documentation'))
20
41
  this.log() // blank line
21
42
  }
22
- })
43
+ }
@@ -1,20 +1,39 @@
1
- import generateAPI from './generate-api.js'
1
+ import GenerateAPI from './GenerateAPI.js'
2
2
 
3
- /** @type {import('juisy/cli').Command} */
4
- export default new CLI.Command({
5
- command: 'docs <command>',
6
- describe: 'Manage project documentation',
7
- meta: {
3
+ export default class Docs extends CLI.Command {
4
+ /**
5
+ * The command signature
6
+ */
7
+ command = 'docs <command>'
8
+
9
+ /**
10
+ * The command description
11
+ */
12
+ describe = 'Manage project documentation'
13
+
14
+ /**
15
+ * The command meta
16
+ */
17
+ meta = {
8
18
  private: true
9
- },
19
+ }
20
+
21
+ /**
22
+ * Command builder
23
+ */
10
24
  builder (cli) {
11
25
  return cli
12
26
  .command([
13
27
  /**
14
28
  * Default command are automatically injected here...
15
29
  */
16
- generateAPI
30
+ GenerateAPI
17
31
  ])
18
- },
19
- handler (argv) {}
20
- })
32
+ .demandCommand(1, 'Command is missing. See help to learn more.')
33
+ }
34
+
35
+ /**
36
+ * Command handler
37
+ */
38
+ async handler (argv) {}
39
+ }
@@ -1,33 +1,48 @@
1
- /** @type {import('juisy/cli').Command} */
2
- export default new CLI.Command({
3
- command: 'test',
4
- describe: 'Run project tests',
5
- meta: {
1
+ export default class Test extends CLI.Command {
2
+ /**
3
+ * The command signature
4
+ */
5
+ command = 'test'
6
+
7
+ /**
8
+ * The command description
9
+ */
10
+ describe = 'Run project tests with vitest. Accepts all arguments of vitest command.'
11
+
12
+ /**
13
+ * The command meta
14
+ */
15
+ meta = {
6
16
  private: true
7
- },
17
+ }
18
+
19
+ /**
20
+ * Command builder
21
+ */
8
22
  builder (cli) {
9
- cli.option('watch', {
10
- alias: 'w',
11
- type: 'boolean',
12
- default: false,
13
- describe: 'Run vitest in watch mode'
14
- })
15
- cli.option('ui', {
16
- type: 'boolean',
17
- default: false,
18
- describe: 'Launch vitest UI'
19
- })
23
+ cli.strict(false) // to forward all arguments
20
24
  return cli
21
- },
22
- async handler (args) {
23
- const watchMode = args.watch || args.ui
25
+ }
26
+
27
+ /**
28
+ * Command handler
29
+ */
30
+ async handler (argv) {
24
31
  const { run } = CLI.InterfaceUtils
32
+
33
+ // Forward arguments to vitest command
34
+ const testCommandArgs = this.getProcessArgv().slice(1)
35
+
25
36
  /**
26
37
  * Run tests
27
38
  */
28
- await run('vitest', [
29
- ...(watchMode ? [] : [ 'run' ]),
30
- ...(args.ui ? [ '--ui' ] : [])
31
- ], { stdio: 'inherit' })
39
+ await run('npx', [
40
+ 'vitest',
41
+ ...testCommandArgs
42
+ ])
43
+ // Prevent an error be thrown when Ctrl+C is pressed in watch mode
44
+ .catch((err) => {
45
+ if (err.exitCode !== 130) throw err
46
+ })
32
47
  }
33
- })
48
+ }
@@ -2,6 +2,8 @@
2
2
 
3
3
  'use strict'
4
4
 
5
- const cli = require('./cli')
5
+ import cli from './cli.js'
6
6
 
7
- cli().parse(process.argv.slice(2))
7
+ const argv = CLI.helpers.hideBin(process.argv)
8
+
9
+ cli().parse(argv)