@ast-grep/nursery 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +33 -0
  2. package/package.json +13 -0
package/index.js ADDED
@@ -0,0 +1,33 @@
1
+ const { cp } = require('fs').promises
2
+ const { parse, registerDynamicLanguage } = require('@ast-grep/napi')
3
+
4
+ const path = require('path')
5
+
6
+ async function copySrc(packageName) {
7
+ const src = path.join(process.cwd(), 'node_modules', packageName, 'src')
8
+ await cp(src, 'src', { recursive: true })
9
+ }
10
+
11
+ function test(setupConfig) {
12
+ const { name, languageRegistration, testRunner } = setupConfig
13
+ registerDynamicLanguage({ [name]: languageRegistration })
14
+ testRunner((code) => parse(name, code))
15
+ }
16
+
17
+ /** Setup ast-grep/lang package's pre-release and
18
+ * @param {Object} setupConfig
19
+ * @param {string} setupConfig.name
20
+ * @param {string} setupConfig.packageName
21
+ * @param {Function} setupConfig.testRunner
22
+ * @returns {void}
23
+ */
24
+ function setup(setupConfig){
25
+ const arg = process.argv[2]
26
+ if (arg === 'copy') {
27
+ copySrc(setupConfig.packageName)
28
+ } else if (arg === 'test') {
29
+ test(setupConfig)
30
+ }
31
+ }
32
+
33
+ exports.setup = setup
package/package.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "@ast-grep/nursery",
3
+ "version": "0.0.1",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "keywords": [],
7
+ "author": "",
8
+ "license": "ISC",
9
+ "dependencies": {
10
+ "tree-sitter-cli": "0.24.6",
11
+ "@ast-grep/napi": "0.33.0"
12
+ }
13
+ }