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

file-helpers.ts

29 lines818 Bytes

1import { basename } from 'node:path'
2​
3import { CONFIG_FILE } from '@tanstack/create'
4​
5export function cleanUpFiles(
6 files: Record<string, string>,
7 targetDir?: string,
8 preserveBase64 = false,
9) {
10 return Object.keys(files).reduce<Record<string, string>>((acc, file) => {
11 const content =
12 files[file].startsWith('base64::') && !preserveBase64
13 ? '<binary file>'
14 : files[file]
15 if (basename(file) !== CONFIG_FILE) {
16 acc[targetDir ? file.replace(targetDir, '.') : file] = content
17 }
18 return acc
19 }, {})
21​
22export function cleanUpFileArray(files: Array<string>, targetDir?: string) {
23 return files.reduce<Array<string>>((acc, file) => {
24 if (basename(file) !== CONFIG_FILE) {
25 acc.push(targetDir ? file.replace(targetDir, '.') : file)
26 }
27 return acc
28 }, [])