-
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathanalyze.ts
More file actions
43 lines (38 loc) · 1.55 KB
/
analyze.ts
File metadata and controls
43 lines (38 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// The bootstrap call uses the arguments passed to the process to figure out
// which exercise to target, where the input lives (directory input) and what
// execution options to set.
//
// analyze -dc two-fer ~/test/
//
// For example, if arguments are passed directly, the above will run the two-fer
// exercise analyzer with the ~/test/ input directory and turning on debug and
// console logging.
import { find } from './analyzers/Autoload'
import { Bootstrap } from './utils/bootstrap'
import { run } from './utils/runner'
//
const { exercise, options, input, logger } = Bootstrap.call()
logger.log('=> DEBUG mode is on')
logger.log(`=> exercise: ${exercise.slug}`)
logger.log(
`=> options: ${options.pretty ? 'pretty ' : ''}${
options.noTemplates ? 'no-templates' : 'templates'
} ${options.dry ? 'dry ' : ''}`
)
// The autoloader knows where an analyzer should live and tries to require it
// so it can be instantiated here. This allows us to add new analyzers without
// needing to update a bookkeeping construct
//
// eslint-disable-next-line @typescript-eslint/naming-convention
const AnalyzerClass = find(exercise)
const analyzer = new AnalyzerClass()
// The runner uses the execution options to determine what should happen with
// the output. For example the --dry flag will make sure there is nothing
// written to a file.
//
// The basis for the runner is calling analyzer.run(input) -- the output is then
// logged and/or written to a file.
//
run(analyzer, input, options)
.then(() => process.exit(0))
.catch((err: unknown) => logger.fatal(`${err}`))