@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.
- package/index.js +33 -0
- 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