1.0.18 • Published 6 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
6 years ago
1.0.17
6 years ago
1.0.16
6 years ago
1.0.15
7 years ago
1.0.14
7 years ago
1.0.13
7 years ago
1.0.12
7 years ago
1.0.11
7 years ago
1.0.10
7 years ago
1.0.9
7 years ago
1.0.8
7 years ago
1.0.7
7 years ago
1.0.6
7 years ago
1.0.5
7 years ago
1.0.4
7 years ago
1.0.3
7 years ago
1.0.2
7 years ago
1.0.1
7 years ago
1.0.0
7 years ago