Skip to content

Commit bd0ef7b

Browse files
committed
Documentation, use interfaces and rewrite bin scripts
1 parent 88dfcac commit bd0ef7b

29 files changed

+383
-306
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"typescript.tsdk": "node_modules\\typescript\\lib"
3+
}

bin/analyze.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
@REM Usage:
2-
@REM ./bin/analyze.bat two_fer ~/test/
2+
@REM ./bin/analyze.bat two-fer ~/test/
33

44
node -r esm ./dist/analyze.js %*

bin/analyze.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env sh
22

33
# Usage:
4-
# ./bin/analyze.sh two_fer ~/test/
4+
# ./bin/analyze.sh two-fer ~/folder/to/solution
55

66
node -r esm ./dist/analyze.js "$@"

bin/batch-runner

Lines changed: 0 additions & 166 deletions
This file was deleted.

bin/batch.bat

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@REM Usage:
2+
@REM ./bin/batch.bat two-fer
3+
4+
node -r esm ./dist/batch.js %*

bin/batch.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env sh
2+
3+
# Usage:
4+
# ./bin/batch.sh two-fer
5+
6+
node -r esm ./dist/batch.js "$@"

bin/statistics

Lines changed: 0 additions & 85 deletions
This file was deleted.

bin/stats.bat

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@REM Usage:
2+
@REM ./bin/stats.bat two-fer
3+
4+
node -r esm ./dist/stats.js %*

bin/stats.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env sh
2+
3+
# Usage:
4+
# ./bin/stats.sh two-fer
5+
6+
node -r esm ./dist/stats.js "$@"

src/exercise.ts renamed to src/ExerciseImpl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export class Exercise {
1+
export class ExerciseImpl implements Exercise {
22
constructor(public readonly slug: string) {
33
if (!slug) {
44
throw new Error(`Expected valid exercise slug, got '${slug}'`)

src/analyze.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,36 @@
11
import { Bootstrap } from './utils/bootstrap'
22
import { find } from './analyzers/Autoload'
3-
import { run } from './runner'
3+
import { run } from './utils/runner'
44

5+
// The bootstrap call uses the arguments passed to the process to figure out
6+
// which exercise to target, where the input lives (directory input) and what
7+
// execution options to set.
8+
//
9+
// analyze -dc two-fer ~/test/
10+
//
11+
// For example, if arguments are passed directly, the above will run the two-fer
12+
// exercise analyzer with the ~/test/ input directory and turning on debug and
13+
// console logging.
14+
//
515
const { exercise, options, input, logger } = Bootstrap.call()
616

717
logger.log('=> DEBUG mode is on')
818
logger.log(`=> exercise: ${exercise.slug}`)
919

20+
// The autoloader knows where an analyzer should live and tries to require it
21+
// so it can be instantiated here. This allows us to add new analyzers without
22+
// needing to update a bookkeeping construct
23+
//
1024
const AnalyzerClass = find(exercise)
1125
const analyzer = new AnalyzerClass()
1226

27+
// The runner uses the execution options to determine what should happen with
28+
// the output. For example the --dry flag will make sure there is nothing
29+
// written to a file.
30+
//
31+
// The basis for the runner is calling analyzer.run(input) -- the output is then
32+
// logged and/or written to a file.
33+
//
1334
run(analyzer, input, options)
1435
.then(() => process.exit(0))
1536
.catch((err: any) => logger.fatal(err.toString()))

src/analyzers/AnalyzerImpl.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { getProcessLogger as getLogger, Logger } from '../utils/logger'
22

3-
import { Comment } from '../comments/comment'
43
import { AnalyzerOutput } from '../output/AnalyzerOutput';
54
import { ParsedSource, AstParser } from '../parsers/AstParser';
65

@@ -35,6 +34,15 @@ export abstract class AnalyzerImpl implements Analyzer {
3534
*/
3635
public async run(input: Input): Promise<Output> {
3736
// Ensure each run has a fresh output
37+
//
38+
// Note: still need to wait for a run to complete before the next one can be
39+
// started. We could work around this by providing an execution
40+
// context that is fresh on each run.
41+
//
42+
// The reason output is not passed to execute, is that it doesn't _actually_
43+
// enforce the implementing analyzer to not use local state, so we don't
44+
// gain anything by it.
45+
//
3846
this.output = new AnalyzerOutput()
3947

4048
await this.execute(input)

src/analyzers/Autoload.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { Exercise } from '../exercise'
2-
31
import path from 'path'
42

53
import { getProcessLogger } from '../utils/logger'

src/analyzers/two-fer/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
BinaryExpression,
32
ConditionalExpression,
43
IfStatement,
54
LogicalExpression,
@@ -246,7 +245,7 @@ export class TwoFerAnalyzer extends AnalyzerImpl {
246245
}
247246

248247
private checkForSolutionWithoutStringTemplate() {
249-
const [expression] = extractAll<BinaryExpression>(this.mainMethod!, AST_NODE_TYPES.BinaryExpression)
248+
const [expression] = extractAll(this.mainMethod!, AST_NODE_TYPES.BinaryExpression)
250249

251250

252251
//

0 commit comments

Comments
 (0)