Skip to content

Commit 1b9544e

Browse files
feat: add prompts
1 parent ff2acb2 commit 1b9544e

File tree

3 files changed

+86
-4
lines changed

3 files changed

+86
-4
lines changed

pnpm-lock.yaml

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/create-lang/index.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,43 @@
1-
console.log('Hello, world!')
1+
import prompts from 'prompts'
2+
3+
function required(s: string): string | true {
4+
if (s.length === 0) {
5+
return 'This value is required'
6+
}
7+
return true
8+
}
9+
10+
function askConfiguration() {
11+
return prompts([
12+
{
13+
type: 'text',
14+
name: 'name',
15+
message: 'Language name',
16+
validate: required,
17+
},
18+
{
19+
type: 'text',
20+
name: 'treeSitterPackage',
21+
message: 'Tree-sitter package to use',
22+
validate: required,
23+
},
24+
{
25+
type: 'list',
26+
name: 'extension',
27+
message: 'File extensions used by the language, comma separated',
28+
separator: ',',
29+
validate: required,
30+
},
31+
{
32+
type: 'text',
33+
name: 'expandoChar',
34+
message: 'Expando char used in pattern',
35+
initial: '$',
36+
validate: (value) => {
37+
return value.length === 1 ? true : 'Expando char must be a single character'
38+
}
39+
}
40+
])
41+
}
42+
43+
askConfiguration().then(console.log)

scripts/create-lang/package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
{
22
"name": "@ast-grep/create-lang",
3-
"version": "0.0.1",
3+
"version": "0.0.0-prerelease",
44
"private": false,
55
"description": "",
66
"main": "index.js",
77
"keywords": [],
88
"author": "",
99
"license": "ISC",
10+
"bin": {
11+
"create-lang": "index.js"
12+
},
1013
"scripts": {
1114
"compile-ts": "tsc",
1215
"prepublishOnly": "tsc"
1316
},
1417
"dependencies": {
18+
"prompts": "2.4.2"
1519
},
1620
"publishConfig": {
1721
"access": "public",
1822
"registry": "https://registry.npmjs.org/"
1923
},
2024
"devDependencies": {
21-
"typescript": "^5.7.3",
22-
"@types/node": "22.10.5"
25+
"@types/node": "22.10.5",
26+
"@types/prompts": "^2.4.9",
27+
"typescript": "^5.7.3"
2328
}
2429
}

0 commit comments

Comments
 (0)