diff options
author | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2024-01-24 18:59:13 -0700 |
---|---|---|
committer | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2024-01-24 18:59:13 -0700 |
commit | 203925d9a48d34537bdf6cd25502134df5e91ae7 (patch) | |
tree | afe8a12679568ba00bfa019b0a5b6f13a3778c00 /src/index.ts | |
download | tabloid-compiler-203925d9a48d34537bdf6cd25502134df5e91ae7.tar.gz tabloid-compiler-203925d9a48d34537bdf6cd25502134df5e91ae7.zip |
Diffstat (limited to 'src/index.ts')
-rw-r--r-- | src/index.ts | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..09d952b --- /dev/null +++ b/src/index.ts @@ -0,0 +1,34 @@ +import { args, type Args } from '@/args'; +import { join } from 'path'; +import { watch } from 'fs/promises'; +import { generateParser, GRAMMAR_FILE, GENERATED_PARSER } from '@/parser'; +import { ConsoleTracingLogger } from '@/utils'; + +const devMode = async (logger: ConsoleTracingLogger) => { + logger.info('Watching for changes in parser...'); + const watcher = watch(import.meta.dir, { recursive: true }); + for await (const event of watcher) { + if (event.filename?.endsWith(GRAMMAR_FILE)) { + const grammarFile = join(import.meta.dir, event.filename); + const outputFile = join( + import.meta.dir, + event.filename.replace(GRAMMAR_FILE, GENERATED_PARSER), + ); + logger.info( + `Generating parser at Location=(${grammarFile}) to Source=(${outputFile})...`, + ); + generateParser(grammarFile, outputFile); + } + } +}; + +export const main = async (args: Args) => { + const logger = new ConsoleTracingLogger('main'); + + if (args.devMode) { + logger.info('Starting in dev mode...'); + await devMode(logger.createChild('devMode')); + } +}; + +main(args); |