MCPcopy Create free account
hub / github.com/chakra-ui/panda / OutputEngine

Class OutputEngine

packages/node/src/output-engine.ts:10–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8}
9
10export class OutputEngine {
11 private paths: Generator['paths']
12 private fs: Runtime['fs']
13 private path: Runtime['path']
14
15 constructor(options: OutputEngineOptions) {
16 const { paths, runtime } = options
17
18 this.paths = paths
19 this.fs = runtime.fs
20 this.path = runtime.path
21 }
22
23 empty = () => {
24 this.fs.rmDirSync(this.path.join(...this.paths.root))
25 }
26
27 ensure = (file: string, cwd: string) => {
28 const outPath = this.path.resolve(cwd, file)
29 const dirname = this.path.dirname(outPath)
30 this.fs.ensureDirSync(dirname)
31 return outPath
32 }
33
34 writeFile = (filePath: string, code: string) => {
35 this.fs.ensureDirSync(this.path.dirname(filePath))
36
37 if (this.fs.existsSync(filePath) && this.fs.readFileSync(filePath) === code) {
38 return
39 }
40
41 logger.debug('write:file', filePath)
42 return this.fs.writeFile(filePath, code)
43 }
44
45 write = (output: Artifact | undefined) => {
46 if (!output) return
47
48 const { dir = this.paths.root, files } = output
49 this.fs.ensureDirSync(this.path.join(...dir))
50
51 return Promise.allSettled(
52 files.map(async (artifact) => {
53 if (!artifact?.code) return
54
55 const { file, code } = artifact
56 const absPath = this.path.join(...dir, file)
57 return this.writeFile(absPath, code)
58 }),
59 )
60 }
61}

Callers

nothing calls this directly

Calls 8

rmDirSyncMethod · 0.65
joinMethod · 0.65
resolveMethod · 0.65
dirnameMethod · 0.65
ensureDirSyncMethod · 0.65
existsSyncMethod · 0.65
readFileSyncMethod · 0.65
writeFileMethod · 0.65

Tested by

no test coverage detected