Skip to content

Commit

Permalink
feat: add nursery package
Browse files Browse the repository at this point in the history
  • Loading branch information
HerringtonDarkholme committed Jan 11, 2025
1 parent 4e430cf commit a69fff8
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 33 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "@ast-grep/langs",
"private": true,
"workspaces": [
"packages/*"
"packages/*",
"scripts/*"
],
"version": "0.0.1",
"description": "Monorepo for `@ast-grep/lang-*` packages",
Expand Down
10 changes: 0 additions & 10 deletions packages/toml/build.js

This file was deleted.

13 changes: 13 additions & 0 deletions packages/toml/nursery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { setup } = require('@ast-grep/nursery')
const toml = require('./index')

setup({
name: 'toml',
packageName: '@tree-sitter-grammars/tree-sitter-toml',
testConfig: {
languageRegistration: toml,
code: `
$NAME = "toml"
`
}
})
14 changes: 8 additions & 6 deletions packages/toml/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
"description": "",
"main": "index.js",
"scripts": {
"build": "node build.js && tree-sitter build -o parser.so",
"test": "node test.js"
"copy-src": "node nursery.js copy",
"build": "tree-sitter build -o parser.so",
"postinstall": "npm run build",
"test": "node nursery.js test"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"tree-sitter-cli": "0.24.6",
"@tree-sitter-grammars/tree-sitter-toml": "0.7.0"
"peerDependencies": {
"tree-sitter-cli": "0.24.6"
},
"devDependencies": {
"@ast-grep/napi": "0.33.0"
"@tree-sitter-grammars/tree-sitter-toml": "0.7.0",
"@ast-grep/nursery": "workspace:*"
}
}
13 changes: 0 additions & 13 deletions packages/toml/test.js

This file was deleted.

15 changes: 12 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
packages:
- 'packages/*'
- 'scripts/*'

36 changes: 36 additions & 0 deletions scripts/nursery/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const { cp } = require('fs').promises
const { parse, registerDynamicLanguage } = require('@ast-grep/napi')

const path = require('path')

async function copySrc(packageName) {
const src = path.join(process.cwd(), 'node_modules', packageName, 'src')
await cp(src, 'src', { recursive: true })
}

function test(name, lang, code) {
registerDynamicLanguage({ [name]: lang })
const tree = parse(name, code)
const root = tree.root()
const node = root.find('$NAME = "toml"')
console.log(node.kind())
}

// jsdoc for setupConfig
// @param {Object} setupConfig
// @param {string} setupConfig.packageName
// @param {string} setupConfig.name
// @param {Object} setupConfig.testConfig
// @param {Object} setupConfig.testConfig.languageRegistration
// @param {string} setupConfig.testConfig.code
//
//
exports.setup = function setup(setupConfig){
const arg = process.argv[2]
if (arg === 'copy') {
copySrc(setupConfig.packageName)
} else if (arg === 'test') {
const testConfig = setupConfig.testConfig
test(setupConfig.name, testConfig.languageRegistration, testConfig.code)
}
}
13 changes: 13 additions & 0 deletions scripts/nursery/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "@ast-grep/nursery",
"version": "0.0.1",
"description": "",
"main": "index.js",
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"tree-sitter-cli": "0.24.6",
"@ast-grep/napi": "0.33.0"
}
}

0 comments on commit a69fff8

Please sign in to comment.