-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat.task.ts
More file actions
44 lines (40 loc) · 1.16 KB
/
format.task.ts
File metadata and controls
44 lines (40 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import {print_spawn_result} from '@fuzdev/fuz_util/process.js';
import {z} from 'zod';
import {to_implicit_forwarded_args} from './args.ts';
import {PRETTIER_CLI_DEFAULT} from './constants.ts';
import {format_directory} from './format_directory.ts';
import {paths} from './paths.ts';
import {TaskError, type Task} from './task.ts';
/** @nodocs */
export const Args = z.strictObject({
_: z.array(z.string()).meta({description: 'files or directories to format'}).optional(),
check: z
.boolean()
.meta({description: 'exit with a nonzero code if any files are unformatted'})
.default(false),
});
export type Args = z.infer<typeof Args>;
/** @nodocs */
export const task: Task<Args> = {
summary: 'format source files',
Args,
run: async ({args, log, config}) => {
const {_: patterns, check} = args;
const format_result = await format_directory(
log,
paths.source,
check,
undefined,
undefined,
undefined,
config.pm_cli,
to_implicit_forwarded_args(PRETTIER_CLI_DEFAULT),
patterns,
);
if (!format_result.ok) {
throw new TaskError(
`Failed ${check ? 'formatting check' : 'to format'}. ${print_spawn_result(format_result)}`,
);
}
},
};