Skip to content

farant/underhill

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

underhill

An opinionated wrapper of tsquery and some other things. Very early in prototyping so everything is likely to change! 🏄

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'))
})

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published