MCPcopy Create free account
hub / github.com/TanStack/cli / createDefaultEnvironment

Function createDefaultEnvironment

packages/create/src/environment.ts:30–115  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

28}
29
30export function createDefaultEnvironment(): Environment {
31 let errors: Array<string> = []
32 return {
33 startRun: () => {
34 errors = []
35 },
36 finishRun: () => {},
37 getErrors: () => errors,
38
39 appendFile: async (path: string, contents: string) => {
40 await mkdir(dirname(path), { recursive: true })
41 return appendFile(path, contents)
42 },
43 copyFile: async (from: string, to: string) => {
44 await mkdir(dirname(to), { recursive: true })
45 return copyFile(from, to)
46 },
47 writeFile: async (path: string, contents: string) => {
48 await mkdir(dirname(path), { recursive: true })
49 return writeFile(path, contents)
50 },
51 writeFileBase64: async (path: string, base64Contents: string) => {
52 await mkdir(dirname(path), { recursive: true })
53 return writeFile(path, getBinaryFile(base64Contents) as string)
54 },
55 execute: async (
56 command: string,
57 args: Array<string>,
58 cwd: string,
59 options?: { inherit?: boolean },
60 ) => {
61 try {
62 if (options?.inherit) {
63 // For commands that should show output directly to the user
64 await execa(command, args, {
65 cwd,
66 stdio: 'inherit',
67 })
68 return { stdout: '' }
69 } else {
70 // For commands where we need to capture output
71 const result = await execa(command, args, {
72 cwd,
73 })
74 return { stdout: result.stdout }
75 }
76 } catch {
77 errors.push(
78 `Command "${command} ${args.join(' ')}" did not run successfully. Please run this manually in your project.`,
79 )
80 return { stdout: '' }
81 }
82 },
83 deleteFile: async (path: string) => {
84 if (existsSync(path)) {
85 await unlink(path)
86 }
87 },

Callers 4

createUIEnvironmentFunction · 0.90
createMemoryEnvironmentFunction · 0.85
readConfigFileFunction · 0.85

Calls 2

getBinaryFileFunction · 0.85
toStringMethod · 0.80

Tested by

no test coverage detected