Skip to content

Commit a626d24

Browse files
authored
Add run command (#373)
1 parent 0a4514b commit a626d24

File tree

17 files changed

+1326
-130
lines changed

17 files changed

+1326
-130
lines changed

.changeset/flat-gorillas-grab.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@quilted/craft': patch
3+
'@quilted/create': patch
4+
'@quilted/sewing-kit': patch
5+
---
6+
7+
Add quilt run command

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ node_modules/
55
packages/*/bin/
66
*.log
77
tests/e2e/output/
8+
coverage

.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@
2727
"**/build": true
2828
},
2929
"typescript.tsdk": "node_modules/typescript/lib",
30-
"jest.jestCommandLine": "./node_modules/@quilted/craft/node_modules/.bin/jest --config ./.quilt/temp/jest/config.mjs"
30+
"jest.jestCommandLine": "node ./scripts/quilt-from-source.js run jest"
3131
}

documentation/cli/run.md

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# `quilt run`
2+
3+
The `quilt run` command allows you to run some tools that are packaged with [Craft](../craft.md), Quilt’s optional development tool. Using `quilt run` is an alternative to using the `quilt` `test`, `type-check`, and `lint` commands, which automatically run theQuilt’s preferred set of [tools](TODO) that are relevant for a given development task. `quilt run` allows you to use the underlying tools more directly, while still benefitting from Craft’s smart defaults (and its [plugin-based configuration system](../craft.md#configuring-hooks)).
4+
5+
To use `quilt run`, you must provide an additional argument: the name of the tool to run. The following tools can be run directly using `quilt run`:
6+
7+
- [TypeScript](TODO), using [`quilt run typescript` or `quilt run tsc`](#quilt-run-typescript)
8+
- [Jest](TODO), using [`quilt run jest`](#quilt-run-jest)
9+
- [ESLint](TODO), using [`quilt run eslint`](#quilt-run-eslint)
10+
- [Prettier](TODO), using [`quilt run prettier`](#quilt-run-prettier)
11+
12+
## `quilt run typescript`
13+
14+
`quilt run typescript` (aliased as `quilt run tsc`) allows you to run the TypeScript compiler, `tsc`. You can pass this command any of the [flags accepted by the `tsc` executable](https://www.typescriptlang.org/docs/handbook/compiler-options.html):
15+
16+
```sh
17+
# Run TypeScript in watch mode
18+
pnpm exec quilt run typescript --watch
19+
```
20+
21+
By default, this command will run `tsc` with the [`--build` flag, which enables Project References](https://www.typescriptlang.org/docs/handbook/project-references.html). This matches the default way Quilt runs `tsc` when you use the [`quilt type-check` command](TODO). To disable this behavior, pass a `--no-build` flag to this command:
22+
23+
```sh
24+
pnpm exec quilt run typescript --no-build
25+
```
26+
27+
## `quilt run jest`
28+
29+
`quilt run jest` allows you to run the Jest test runner. You can pass this command any of the [flags accepted by the `jest` executable](https://jestjs.io/docs/cli):
30+
31+
```sh
32+
# Run Jest on test files matching /app/, with test coverage enabled,
33+
# and without tests being able to print to the console
34+
pnpm exec quilt run jest app --silent --coverage
35+
```
36+
37+
Unlike when running the [`quilt test` command](TODO), Using `quilt run jest` does not automatically run Jest in watch mode. To enable watch mode, you must run this command with the [`--watch`](https://jestjs.io/docs/cli#--watch) or [`--watchAll`](https://jestjs.io/docs/cli#--watchall) Jest flags:
38+
39+
```sh
40+
pnpm exec quilt run jest --watch
41+
```
42+
43+
## `quilt run eslint`
44+
45+
`quilt run eslint` allows you to run the ESLint linter. You can pass this command any of the [flags accepted by the `eslint` executable](https://eslint.org/docs/latest/user-guide/command-line-interface):
46+
47+
```sh
48+
# Run `eslint` with a dry run of fixable errors
49+
pnpm exec quilt run eslint --fix-dry-run
50+
```
51+
52+
By default, this command runs on the entire contents of the directory you run this command from, just like when running [`quilt lint`](TODO). You can run ESLint on only a subset of your project by passing additional positional arguments:
53+
54+
```sh
55+
# Run `eslint` on the ./app directory, relative to where you are running this command
56+
pnpm exec quilt run eslint ./app
57+
```
58+
59+
This command runs on JavaScript and TypeScript files, using the same configurable hooks as `quilt lint`. You can run ESLint on a different set of extensions by explicitly passing the [ESLint `--ext` flag](https://eslint.org/docs/latest/user-guide/command-line-interface#--ext):
60+
61+
```sh
62+
# Run `eslint` only on JavaScript files
63+
pnpm exec quilt run eslint --ext .js
64+
```
65+
66+
Like `quilt lint`, this command defaults to running with ESLint’s [cache enabled](https://eslint.org/docs/latest/user-guide/command-line-interface#--cache). To disable this behavior, pass a `--no-cache` flag:
67+
68+
```sh
69+
# Run `eslint` without cache
70+
pnpm exec quilt run eslint --no-cache
71+
```
72+
73+
## `quilt run prettier`
74+
75+
`quilt run prettier` allows you to run the Prettier linter. You can pass this command any of the [flags accepted by the `prettier` executable](https://prettier.io/docs/en/cli.html):
76+
77+
```sh
78+
# Run `prettier`, preferring single quotes over double quotes
79+
pnpm exec quilt run prettier --single-quote
80+
```
81+
82+
By default, this command runs on a set of extensions that includes all the file types [Prettier is able to format](https://prettier.io/docs/en/index.html), except for JavaScript and TypeScript files, which are assumed to be run Prettier through ESLint. You can customize the files that will be checked with prettier by passing an explicit glob pattern to this command:
83+
84+
```sh
85+
# Run `prettier` on GraphQL files in the app directory.
86+
pnpm exec quilt run prettier "./app/**/*.graphql"
87+
```

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"node": ">=14.0.0"
99
},
1010
"scripts": {
11+
"quilt-from-source": "node ./scripts/quilt-from-source.js",
1112
"create": "node --no-warnings --experimental-specifier-resolution=node --loader ./scripts/esbuild-module-loader.js ./packages/create/source/index.ts",
1213
"test": "node ./scripts/quilt-from-source.js test",
1314
"test:unit": "node ./scripts/quilt-from-source.js test --exclude-pattern tests/e2e",

packages/craft/source/cli/cli.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
import arg from 'arg';
12
import {Task} from '../kit';
23

34
run();
45

56
async function run() {
67
const [, , ...args] = process.argv;
7-
const [task, ...argv] = args;
8+
const {
9+
_: [command, ...argv],
10+
} = arg({}, {argv: args, stopAtPositional: true});
811

9-
if (!task) {
12+
if (!command) {
1013
// eslint-disable-next-line no-console
1114
console.log(
1215
`You must run quilt with one of the following commands: build, develop, lint, test, or type-check.`,
@@ -15,7 +18,7 @@ async function run() {
1518
return;
1619
}
1720

18-
switch (task.toLowerCase()) {
21+
switch (command.toLowerCase()) {
1922
case Task.Build: {
2023
const {build} = await import('./tasks/build');
2124
await build(argv);
@@ -41,9 +44,14 @@ async function run() {
4144
await typeCheck(argv);
4245
break;
4346
}
47+
case 'run': {
48+
const {run} = await import('./tasks/run');
49+
await run(argv);
50+
break;
51+
}
4452
default: {
4553
// eslint-disable-next-line no-console
46-
console.log(`Task not found: ${task} (${argv.join(' ')})`);
54+
console.log(`Command not found: ${command} (${argv.join(' ')})`);
4755
process.exitCode = 1;
4856
}
4957
}

0 commit comments

Comments
 (0)