| 11 | import { OutputEngine } from './output-engine' |
| 12 | |
| 13 | export class PandaContext extends Generator { |
| 14 | runtime: Runtime |
| 15 | project: Project |
| 16 | output: OutputEngine |
| 17 | diff: DiffEngine |
| 18 | explicitDeps: string[] = [] |
| 19 | |
| 20 | constructor(conf: LoadConfigResult) { |
| 21 | super(conf) |
| 22 | |
| 23 | const config = conf.config |
| 24 | this.runtime = nodeRuntime |
| 25 | |
| 26 | config.cwd ||= this.runtime.cwd() |
| 27 | |
| 28 | if (config.logLevel) { |
| 29 | logger.level = config.logLevel |
| 30 | } |
| 31 | |
| 32 | this.project = new Project({ |
| 33 | ...conf.tsconfig, |
| 34 | getFiles: this.getFiles.bind(this), |
| 35 | readFile: this.runtime.fs.readFileSync.bind(this), |
| 36 | hooks: conf.hooks, |
| 37 | parserOptions: { |
| 38 | ...this.parserOptions, |
| 39 | join: this.runtime.path.join || this.parserOptions.join, |
| 40 | }, |
| 41 | }) |
| 42 | |
| 43 | this.output = new OutputEngine(this) |
| 44 | this.diff = new DiffEngine(this) |
| 45 | this.explicitDeps = this.getExplicitDependencies() |
| 46 | } |
| 47 | |
| 48 | private getExplicitDependencies = () => { |
| 49 | const { cwd, dependencies } = this.config |
| 50 | if (!dependencies) return [] |
| 51 | return this.runtime.fs.glob({ include: dependencies, cwd }) |
| 52 | } |
| 53 | |
| 54 | initMessage = () => { |
| 55 | return createBox({ |
| 56 | content: this.messages.codegenComplete(), |
| 57 | title: this.messages.exclamation(), |
| 58 | }) |
| 59 | } |
| 60 | |
| 61 | getFiles = () => { |
| 62 | const { include, exclude, cwd } = this.config |
| 63 | return this.runtime.fs.glob({ include, exclude, cwd }) |
| 64 | } |
| 65 | |
| 66 | parseFile = (filePath: string, styleEncoder?: StyleEncoder) => { |
| 67 | const file = this.runtime.path.abs(this.config.cwd, filePath) |
| 68 | logger.debug('file:extract', file) |
| 69 | |
| 70 | const measure = logger.time.debug(`Parsed ${file}`) |
nothing calls this directly
no test coverage detected