1.0.18 • Published 5 years ago
underhill v1.0.18
underhill
An opinionated wrapper of tsquery and some other things. Very early in prototyping so everything is likely to change! :surfer:
https://astexplorer.net/ is a very useful tool for building selectors.
Examples
import * as path from 'path'
import { SourceCode } from 'underhill'
let example = SourceCode.fromFile(path.join(__dirname, 'example.ts'))
example.modifyParent({
selector: 'InterfaceDeclaration > Identifier[name!=/[I][A-Z].*/]',
action: o =>
o.members.push(
SourceCode.extractFirst(
'PropertySignature',
`
interface __ {
readonly testProperty: boolean
}
`
)
),
})
example.modifyParent({
selector: 'Identifier[name=defaultState]',
action: o =>
o.initializer.properties.push(
SourceCode.extractFirst(
'PropertyAssignment',
`
const __ = {
testProperty: false
}
`
)
),
})
example.logDiff()
example.writeToFile(path.join(__dirname, 'output.ts'))
let files = await SourceCode.searchFiles(path.join(__dirname, 'my-project'), {
selector: 'CallExpression[expression.text=getDefault]',
})
files.forEach(f => {
console.log('\n' + f.path)
console.log(f.summary.join('\n---\n'))
})
1.0.18
5 years ago
1.0.17
5 years ago
1.0.16
5 years ago
1.0.15
6 years ago
1.0.14
6 years ago
1.0.13
6 years ago
1.0.12
6 years ago
1.0.11
6 years ago
1.0.10
6 years ago
1.0.9
6 years ago
1.0.8
6 years ago
1.0.7
6 years ago
1.0.6
6 years ago
1.0.5
6 years ago
1.0.4
6 years ago
1.0.3
6 years ago
1.0.2
6 years ago
1.0.1
6 years ago
1.0.0
6 years ago