Skip to content
Source
Sign inSign up
TanStack/cli
Open History to see the last commit

test-utilities.ts

44 lines1.0 KB

1import { dirname, join, basename, extname } from 'node:path'
2​
3import { formatCommand, Options } from '@tanstack/cta-engine'
4​
5const IGNORE_EXTENSIONS = ['.png', '.ico', '.svg']
6​
7export function cleanupOutput(
8 options: Options,
9 output: {
10 files: Record<string, string>
11 commands: Array<{
12 command: string
13 args: Array<string>
14 }>
15 },
16) {
17 const trimProjectRelativePath = (path: string) =>
18 join(dirname(path).replace(options.targetDir, ''), basename(path))
19​
20 const filteredFiles = Object.keys(output.files)
21 .filter((key) => !IGNORE_EXTENSIONS.includes(extname(key)))
22 .reduce(
23 (acc, key) => {
24 acc[trimProjectRelativePath(key)] = output.files[key]
25 return acc
26 },
27 {} as Record<string, string>,
28 )
29​
30 const files = Object.keys(filteredFiles)
31 .sort()
32 .reduce(
33 (acc, key) => {
34 acc[key] = filteredFiles[key]
35 return acc
36 },
37 {} as Record<string, string>,
38 )
39​
40 return {
41 files,
42 commands: output.commands.map((c) => formatCommand(c)),
43 }