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

Function debug

packages/node/src/debug.ts:11–71  ·  view source on GitHub ↗
(ctx: PandaContext, options: DebugOptions)

Source from the content-addressed store, hash-verified

9}
10
11export async function debug(ctx: PandaContext, options: DebugOptions) {
12 const files = ctx.getFiles()
13 const measureTotal = logger.time.debug(`Done parsing ${files.length} files`)
14
15 // easier to debug
16 ctx.config.minify = false
17
18 const { fs, path } = ctx.runtime
19 const outdir = options.outdir
20
21 if (!options.dry && outdir) {
22 fs.ensureDirSync(outdir)
23 logger.info('cli', `Writing ${colors.bold(`${outdir}/config.json`)}`)
24 await fs.writeFile(`${outdir}/config.json`, JSON.stringify(ctx.config, null, 2))
25 }
26
27 if (options.onlyConfig) {
28 measureTotal()
29 return
30 }
31
32 const filesWithCss = []
33
34 files.map((file) => {
35 const measure = logger.time.debug(`Parsed ${file}`)
36 const encoder = ctx.encoder.clone()
37 const result = ctx.project.parseSourceFile(file, encoder)
38
39 measure()
40 if (!result || result.isEmpty() || encoder.isEmpty()) return
41
42 const styles = ctx.decoder.clone().collect(encoder)
43 const css = ctx.getParserCss(styles)
44 if (!css) return
45
46 if (options.dry) {
47 console.log({ path: file, ast: result, code: css })
48 return
49 }
50
51 if (outdir) {
52 filesWithCss.push(file)
53 const parsedPath = parse(file)
54 const relative = path.relative(ctx.config.cwd, parsedPath.dir)
55
56 const astJsonPath = `${relative}${path.sep}${parsedPath.name}.ast.json`.replaceAll(path.sep, '__')
57 const cssPath = `${relative}${path.sep}${parsedPath.name}.css`.replaceAll(path.sep, '__')
58
59 logger.info('cli', `Writing ${colors.bold(`${outdir}/${astJsonPath}`)}`)
60 logger.info('cli', `Writing ${colors.bold(`${outdir}/${cssPath}`)}`)
61
62 return Promise.allSettled([
63 fs.writeFile(`${outdir}${path.sep}${astJsonPath}`, JSON.stringify(result.toJSON(), null, 2)),
64 fs.writeFile(`${outdir}${path.sep}${cssPath}`, css),
65 ])
66 }
67 })
68

Callers 1

mainFunction · 0.90

Calls 8

toJSONMethod · 0.80
getFilesMethod · 0.65
ensureDirSyncMethod · 0.65
writeFileMethod · 0.65
relativeMethod · 0.65
parseFunction · 0.50
cloneMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected