Skip to content

Commit 3afa686

Browse files
committed
thank fuck I finally seem to have a repl working
https://nodejs.org/api/repl.html#repl TypeStrong/ts-node#1007 some real jank around ESM vs CommonJS - we seem to have to use .js file extensions in src/repl.ts ;; let's check if we CAN use .js everywhere in our .ts files at least that would be consistent.
1 parent 52f16d4 commit 3afa686

File tree

3 files changed

+59
-30
lines changed

3 files changed

+59
-30
lines changed

Diff for: package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
"prettier-check": "pnpm exec prettier --config .prettierrc -c 'src/**/*.ts' 'test/**/*.ts'",
1919
"prettier-watch": "pnpm exec onchange 'src/**/*.ts' 'test/**/*.ts' -- pnpm exec prettier --config .prettierrc -w {{changed}}",
2020
"prep": "pnpm run prettier & pnpm run lint && pnpm test",
21-
"deps": "pnpm exec depcruise -c .dependency-cruiser.cjs -I src -T dot . | dot -T svg > graph.svg && open -a Arc graph.svg"
21+
"deps": "pnpm exec depcruise -c .dependency-cruiser.cjs -I src -T dot . | dot -T svg > graph.svg && open -a Arc graph.svg",
22+
"ex": "node --loader ts-node/esm src/*.ts",
23+
"repl": "node --loader ts-node/esm src/repl.ts"
2224
},
2325
"husky": {
2426
"hooks": {

Diff for: src/parser.ts

+28-29
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
1-
// import * as R from 'ramda'
2-
// import { parseISO } from 'date-fns'
3-
// import { parseJSON } from 'date-fns/fp'
4-
5-
export function argsFromArgv(argv: string[]): string[] {
6-
return argv.slice(2) // .filter((arg) => !(arg === '--'))
7-
}
81

92
enum TokenKind {
10-
Command = 'commands',
11-
Filter = 'filters',
3+
Command = 'commands',
4+
Filter = 'filters',
125
Modifier = 'modifiers',
13-
Ids = 'filters.ids',
6+
Ids = 'filters.ids',
147
}
158

169
export type CommandConfig = {
17-
name: string
18-
aliases: string[]
19-
expect: TokenKind[]
20-
subcommands: CommandConfig[]
10+
name: string
11+
aliases: string[]
12+
expect: TokenKind[]
13+
subcommands: CommandConfig[]
2114
confirmation?: boolean
2215
}
2316

@@ -73,7 +66,6 @@ const CommandConfigs: CommandConfig[] = [
7366
]
7467
// no reason it should change
7568
Object.freeze(CommandConfigs)
76-
const defaultCommandName = 'list'
7769

7870
export type CommandConfigList = {
7971
[key: string]: CommandConfig
@@ -84,15 +76,15 @@ export type TagSet = {
8476
[key: string]: string[]
8577
}
8678

87-
// schema?
79+
// should use a typebox schema?
8880
export type ParsedCommandArgs = {
8981
filters: {
90-
ids: number[]
91-
tags: TagSet
82+
ids: number[]
83+
tags: TagSet
9284
words: string[]
9385
}
9486
modifiers: {
95-
tags: TagSet
87+
tags: TagSet
9688
words: string[]
9789
}
9890
}
@@ -116,12 +108,12 @@ function buildState(tokens: string[]): State {
116108
command: [],
117109
processedIndices: [],
118110
filters: {
119-
ids: [],
120-
tags: {},
111+
ids: [],
112+
tags: {},
121113
words: [],
122114
},
123115
modifiers: {
124-
tags: {},
116+
tags: {},
125117
words: [],
126118
},
127119
} as State
@@ -134,19 +126,20 @@ function extractCommand(state: State): ParsedCommand {
134126
return parsed
135127
}
136128

129+
const DefaultCommandName = 'list'
130+
137131
// https://taskwarrior.org/docs/syntax/
138132
// task <filter> <command> <modifications> <miscellaneous>
139-
133+
//
140134
// first, find the first thing that looks like a command
141135
// everything before it is a filter (ids, etc)
142136
// everything after it is a modification
143-
144137
export function parse(tokens: string[]): ParsedCommand {
145138
let state = buildState(tokens)
146139
state = parseCommands(state)
147140

148141
if (state.command.length === 0)
149-
state.command.push(defaultCommandName)
142+
state.command.push(DefaultCommandName)
150143

151144
// how we interpret remaining tokens depends on whether they're
152145
// before or after a command
@@ -187,16 +180,14 @@ function parseCommands(state: State): State {
187180
// we've previously found a command, but matched no valid subcommand
188181
break
189182
}
190-
return state // TODO rather than mutate the state, return an immutable update
183+
return state // FIXME rather than mutate the state, return an immutable update
191184
}
192185

193186
export function parseArgs(argv: string[]): ParsedCommand {
194187
return parse(argsFromArgv(argv))
195188
}
196189

197-
function commandAliases(
198-
cmds: CommandConfig[] = CommandConfigs,
199-
): CommandConfigList {
190+
function commandAliases(cmds: CommandConfig[]=CommandConfigs): CommandConfigList {
200191
const o: CommandConfigList = {}
201192
cmds.map((c) =>
202193
c.aliases.forEach((alias) => {
@@ -247,3 +238,11 @@ function recogniseIds(word: string): number[] | null {
247238
}
248239

249240
// function recogniseTags()
241+
// function recognisePriority()
242+
// function recogniseParent()
243+
244+
// utility functions
245+
246+
export function argsFromArgv(argv: string[]): string[] {
247+
return argv.slice(2) // .filter((arg) => !(arg === '--'))
248+
}

Diff for: src/repl.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import * as repl from 'node:repl'
2+
import * as E from './entry.js'
3+
import { Value } from '@sinclair/typebox/value'
4+
5+
const replServer = repl.start('> ')
6+
replServer.context.E = E
7+
replServer.context.Value = Value
8+
9+
10+
// import repl from "repl";
11+
// import ts from "typescript";
12+
// import * as tsnode from "ts-node";
13+
14+
// // Create a ts-node replService
15+
// const replService: tsnode.ReplService = tsnode.createRepl()
16+
// const service = tsnode.create({ ...replService.evalAwarePartialHost })
17+
// service.ts = ts;
18+
// replService.setService(service)
19+
20+
// // create a node-repl server
21+
// const replServer = repl.start({
22+
// prompt: "→º ",
23+
// ignoreUndefined: true,
24+
// eval: replService.nodeEval,
25+
// });
26+
27+
// // setup environment
28+
// replServer.setupHistory(".log", () => {})

0 commit comments

Comments
 (0)