Skip to content

Commit 22980b3

Browse files
fix: various fix for @ast-grep/create-lang
1 parent 017e69e commit 22980b3

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

scripts/create-lang/index.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,26 @@ function askConfiguration() {
5454
validate: (value) => {
5555
return value.length === 1 ? true : 'Expando char must be a single character'
5656
}
57+
},
58+
{
59+
type: 'confirm',
60+
name: 'includeDotFiles',
61+
message: 'Include gitignore and npm publish files?',
62+
initial: true,
5763
}
5864
])
5965
}
6066

6167
type Answers = Awaited<ReturnType<typeof askConfiguration>>
6268

63-
function copyTemplate(targetDir: string, skipDotFiles = false) {
69+
function copyTemplate(targetDir: string, includeDotFiles: boolean) {
6470
const templateDir = path.join(__dirname, 'template')
6571
return fs.cp(templateDir, targetDir, {
6672
recursive: true, // Copy all files and folders
67-
// includes hidden files if `skipDotFiles` is false
73+
// includes hidden files if `includeDotFiles` is true
6874
filter: (src) => {
6975
const basename = path.basename(src)
70-
return !skipDotFiles || !basename.startsWith('.')
76+
return includeDotFiles || !basename.startsWith('.')
7177
}
7278
})
7379
}
@@ -78,7 +84,7 @@ async function renameFiles(dir: string, answer: Answers) {
7884
$$NAME$$: answer.name,
7985
$$TREE_SITTER_PACKAGE$$: answer.treeSitterPackage,
8086
$$EXTENSIONS$$: JSON.stringify(answer.extensions),
81-
$$EXPANDO_CHAR$$: JSON.stringify(answer.expandoChar),
87+
$$EXPANDO_CHAR$$: answer.expandoChar,
8288
}
8389
for (const file of await fs.readdir(dir)) {
8490
const filePath = path.join(dir, file)
@@ -106,8 +112,7 @@ function installTreeSitterPackage(answer: Answers) {
106112
async function main() {
107113
const cwd = process.cwd()
108114
const config = await askConfiguration()
109-
const skipDotFiles = process.argv.slice(2).includes('--skip-dot-files')
110-
await copyTemplate(cwd, skipDotFiles)
115+
await copyTemplate(cwd, config.includeDotFiles)
111116
await renameFiles(cwd, config)
112117
installTreeSitterPackage(config)
113118
}

0 commit comments

Comments
 (0)